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:
David Dworken 2023-12-06 16:12:41 -08:00 committed by GitHub
parent 3d6578c7f6
commit a26fc5b360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 29 deletions

View File

@ -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{

View File

@ -1,5 +1,4 @@
Search Query: > 1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip12345678
┌──────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│──────────────────────────────────────────────────────────────────────────────────────────────────│

View File

@ -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

View File

@ -1,5 +1,4 @@
Search Query: > ls
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│────────────────────────────────────────────────────────────────────────────────────────────│

View 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 ~/ │
│ │
│ │
└────────────────────────────────────────────────────────────────────────────────────────────┘

View File

@ -1,5 +1,4 @@
Search Query: > ls
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│────────────────────────────────────────────────────────────────────────────────────────────│

View File

@ -1,5 +1,4 @@
Search Query: > ls
┌────────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│────────────────────────────────────────────────────────────────────────────────────────────│

View File

@ -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),