Make the query input box in the TUI match the terminal dimensions

This commit is contained in:
David Dworken 2023-09-14 21:14:16 -07:00
parent 30ba0bd35c
commit 48e33d5034
No known key found for this signature in database
3 changed files with 32 additions and 3 deletions

View File

@ -1805,6 +1805,14 @@ func testTui_resize(t testing.TB) {
})
require.Contains(t, out, "\necho 'aaaaaa bbbb'\n")
// Check that it supports a very long search query
out = captureTerminalOutputWithShellNameAndDimensions(t, tester, tester.ShellName(), 100, 20, []TmuxCommand{
{Keys: "hishtory SPACE tquery ENTER"},
{Keys: "1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip"},
})
out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1])
testutils.CompareGoldens(t, out, "TestTui-LongQuery")
// Assert there are no leaked connections
assertNoLeakedConnections(t)
}

View File

@ -0,0 +1,15 @@
Search Query: > 1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip1234567890qwertyuip12345678
┌───────────────────────────────────────────────────────────────────────────────────────────┐
│ Hostname CWD Timestamp Runtime Exit Code Command │
│───────────────────────────────────────────────────────────────────────────────────────────│
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└───────────────────────────────────────────────────────────────────────────────────────────┘
hiSHtory: Search your shell history • ctrl+h help

View File

@ -195,9 +195,14 @@ func initialModel(ctx context.Context, t table.Model, tableEntries []*data.Histo
queryInput := textinput.New()
queryInput.Placeholder = "ls"
queryInput.Focus()
queryInput.CharLimit = 156
// TODO: Make the width of the query input match the width of the terminal
queryInput.Width = 50
queryInput.CharLimit = 200
width, _, err := getTerminalSize()
if err == nil {
queryInput.Width = width
} else {
hctx.GetLogger().Infof("getTerminalSize() return err=%#v, defaulting queryInput to a width of 50", err)
queryInput.Width = 50
}
if initialQuery != "" {
queryInput.SetValue(initialQuery)
}
@ -307,6 +312,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case tea.WindowSizeMsg:
m.help.Width = msg.Width
m.queryInput.Width = msg.Width
cmd := runQueryAndUpdateTable(m, true, true)
return m, cmd
case offlineMsg: