diff --git a/client/client_test.go b/client/client_test.go index 5bd2af1..db6109a 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -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{ diff --git a/client/lib/goldens/TestTui-LongQuery b/client/lib/goldens/TestTui-LongQuery index 6420e93..f899250 100644 --- a/client/lib/goldens/TestTui-LongQuery +++ b/client/lib/goldens/TestTui-LongQuery @@ -1,5 +1,4 @@ Search Query: > 1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip12345678 - ┌──────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Hostname CWD Timestamp Runtime Exit Code Command │ │──────────────────────────────────────────────────────────────────────────────────────────────────│ diff --git a/client/lib/goldens/TestTui-Resize b/client/lib/goldens/TestTui-Resize index 7c49395..74bb6e9 100644 --- a/client/lib/goldens/TestTui-Resize +++ b/client/lib/goldens/TestTui-Resize @@ -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 \ No newline at end of file diff --git a/client/lib/goldens/TestTui-SmallTerminal b/client/lib/goldens/TestTui-SmallTerminal index e19df5a..2d18f3c 100644 --- a/client/lib/goldens/TestTui-SmallTerminal +++ b/client/lib/goldens/TestTui-SmallTerminal @@ -1,5 +1,4 @@ Search Query: > ls - ┌────────────────────────────────────────────────────────────────────────────────────────────┐ │ Hostname CWD Timestamp Runtime Exit Code Command │ │────────────────────────────────────────────────────────────────────────────────────────────│ diff --git a/client/lib/goldens/TestTui-TiniestTerminal b/client/lib/goldens/TestTui-TiniestTerminal new file mode 100644 index 0000000..b7f641f --- /dev/null +++ b/client/lib/goldens/TestTui-TiniestTerminal @@ -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 ~/ │ +│ │ +│ │ +└────────────────────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/TestTui-TinyTerminal b/client/lib/goldens/TestTui-TinyTerminal index 03b061c..f09b140 100644 --- a/client/lib/goldens/TestTui-TinyTerminal +++ b/client/lib/goldens/TestTui-TinyTerminal @@ -1,5 +1,4 @@ Search Query: > ls - ┌────────────────────────────────────────────────────────────────────────────────────────────┐ │ Hostname CWD Timestamp Runtime Exit Code Command │ │────────────────────────────────────────────────────────────────────────────────────────────│ diff --git a/client/lib/goldens/TestTui-TinyTerminalHelp b/client/lib/goldens/TestTui-TinyTerminalHelp index eda61e2..b6de275 100644 --- a/client/lib/goldens/TestTui-TinyTerminalHelp +++ b/client/lib/goldens/TestTui-TinyTerminalHelp @@ -1,5 +1,4 @@ Search Query: > ls - ┌────────────────────────────────────────────────────────────────────────────────────────────┐ │ Hostname CWD Timestamp Runtime Exit Code Command │ │────────────────────────────────────────────────────────────────────────────────────────────│ diff --git a/client/tui/tui.go b/client/tui/tui.go index a498666..bd5d780 100644 --- a/client/tui/tui.go +++ b/client/tui/tui.go @@ -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),