mirror of
https://github.com/ddworken/hishtory.git
synced 2025-04-13 03:58:42 +02:00
Add more special handling for extra tiny terminals (#140)
* Add more special handling for extra tiny terminals * Add tests for extra compact terminals
This commit is contained in:
parent
3d6578c7f6
commit
a26fc5b360
@ -1654,6 +1654,19 @@ func testTui_resize(t *testing.T) {
|
||||
out = stripTuiCommandPrefix(t, out)
|
||||
testutils.CompareGoldens(t, out, "TestTui-TinyTerminalHelp")
|
||||
|
||||
// Check the output when the size is extra tiny
|
||||
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 11, []TmuxCommand{
|
||||
{Keys: "hishtory SPACE tquery ENTER"},
|
||||
})
|
||||
testutils.CompareGoldens(t, out, "TestTui-TiniestTerminal")
|
||||
|
||||
// Check the output when the size is tiny and the user tries to open the help page, which doesn't work
|
||||
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 11, []TmuxCommand{
|
||||
{Keys: "hishtory SPACE tquery ENTER"},
|
||||
{Keys: "C-h"},
|
||||
})
|
||||
testutils.CompareGoldens(t, out, "TestTui-TiniestTerminal")
|
||||
|
||||
// Check that it resizes after the terminal size is adjusted
|
||||
manuallySubmitHistoryEntry(t, userSecret, testutils.MakeFakeHistoryEntry("echo 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc'"))
|
||||
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 20, []TmuxCommand{
|
||||
|
@ -1,5 +1,4 @@
|
||||
Search Query: > 1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip12345678
|
||||
|
||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
|
@ -1,27 +1,27 @@
|
||||
Search Query: > ls
|
||||
|
||||
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:26 PDT 3s 2 echo 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:26 PDT 3s 2 echo 'cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
hiSHtory: Search your shell history • ctrl+h help
|
@ -1,5 +1,4 @@
|
||||
Search Query: > ls
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
|
9
client/lib/goldens/TestTui-TiniestTerminal
Normal file
9
client/lib/goldens/TestTui-TiniestTerminal
Normal file
@ -0,0 +1,9 @@
|
||||
Search Query: > ls
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:21 PDT 3s 2 echo 'aaaaaa bbbb' │
|
||||
│ localhost /tmp/ Oct 17 2022 21:43:16 PDT 3s 2 ls ~/ │
|
||||
│ │
|
||||
│ │
|
||||
└────────────────────────────────────────────────────────────────────────────────────────────┘
|
@ -1,5 +1,4 @@
|
||||
Search Query: > ls
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
|
@ -1,5 +1,4 @@
|
||||
Search Query: > ls
|
||||
|
||||
┌────────────────────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname CWD Timestamp Runtime Exit Code Command │
|
||||
│────────────────────────────────────────────────────────────────────────────────────────────│
|
||||
|
@ -424,12 +424,27 @@ func (m model) View() string {
|
||||
additionalMessages = append(additionalMessages, fmt.Sprintf("%s Executing search query...", m.spinner.View()))
|
||||
}
|
||||
additionalMessagesStr := strings.Join(additionalMessages, "\n") + "\n"
|
||||
if isExtraCompactHeightMode() {
|
||||
additionalMessagesStr = "\n"
|
||||
}
|
||||
helpView := m.help.View(keys)
|
||||
if isExtraCompactHeightMode() {
|
||||
helpView = ""
|
||||
}
|
||||
additionalSpacing := "\n"
|
||||
if isCompactHeightMode() {
|
||||
additionalSpacing = ""
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s%sSearch Query: %s\n\n%s\n", additionalSpacing, additionalMessagesStr, m.banner, additionalSpacing, m.queryInput.View(), renderNullableTable(m, helpView)) + helpView
|
||||
return fmt.Sprintf("%s%s%s%sSearch Query: %s\n%s%s\n", additionalSpacing, additionalMessagesStr, m.banner, additionalSpacing, m.queryInput.View(), additionalSpacing, renderNullableTable(m, helpView)) + helpView
|
||||
}
|
||||
|
||||
func isExtraCompactHeightMode() bool {
|
||||
_, height, err := getTerminalSize()
|
||||
if err != nil {
|
||||
hctx.GetLogger().Infof("got err=%v when retrieving terminal dimensions, assuming the terminal is reasonably tall", err)
|
||||
return false
|
||||
}
|
||||
return height < 15
|
||||
}
|
||||
|
||||
func isCompactHeightMode() bool {
|
||||
@ -662,6 +677,9 @@ func makeTable(ctx context.Context, rows []table.Row) (table.Model, error) {
|
||||
if isCompactHeightMode() {
|
||||
tuiSize -= 2
|
||||
}
|
||||
if isExtraCompactHeightMode() {
|
||||
tuiSize -= 3
|
||||
}
|
||||
tableHeight := min(TABLE_HEIGHT, terminalHeight-tuiSize)
|
||||
t := table.New(
|
||||
table.WithColumns(columns),
|
||||
|
Loading…
Reference in New Issue
Block a user