Add handling for TUI queries with no results + more tests

This commit is contained in:
David Dworken 2022-11-11 15:57:13 -08:00
parent e520b23858
commit 029bf27117
No known key found for this signature in database
6 changed files with 141 additions and 3 deletions

View File

@ -1970,13 +1970,38 @@ func testControlR(t *testing.T, tester shellTester, shellName string, onlineStat
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"C-R", "-pipefail"})
out = strings.TrimSpace(out)
if tester.ShellName() == "bash" {
if !strings.Contains(out, "\n\n\n") {
t.Fatalf("failed to find separator in %#v", out)
}
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
}
compareGoldens(t, out, "testControlR-customColumn")
// Start with a search query, and then press control-r and it shows results for that query
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"ls", "C-R"})
if strings.Contains(out, "\n\n\n") {
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
}
compareGoldens(t, out, "testControlR-InitialSearch")
// Start with a search query, and then press control-r, then make the query more specific
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"e", "C-R", "cho"})
if strings.Contains(out, "\n\n\n") {
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
}
compareGoldens(t, out, "testControlR-InitialSearchExpanded")
// Start with a search query for which there are no results
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"asdf", "C-R"})
if strings.Contains(out, "\n\n\n") {
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
}
compareGoldens(t, out, "testControlR-InitialSearchNoResults")
// Start with a search query for which there are no results
out = captureTerminalOutputWithShellName(t, tester, shellName, []string{"asdf", "C-R", "BSpace BSpace BSpace BSpace echo"})
if strings.Contains(out, "\n\n\n") {
out = strings.TrimSpace(strings.Split(out, "\n\n\n")[1])
}
compareGoldens(t, out, "testControlR-InitialSearchNoResultsThenFoundResults")
// Disable control-r
_, _ = tester.RunInteractiveShellRelaxed(t, `hishtory config-set enable-control-r false`)
// And it shouldn't pop up

View File

@ -0,0 +1,26 @@
Search Query: > ls
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ ghaction-runner-hostname 0 ls / foo │
│ localhost 2 ls ~/bar/ │
│ localhost 2 ls ~/foo/ │
│ server 127 ls ~/ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,26 @@
Search Query: > echo
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ localhost 2 echo 'bar' & │
│ localhost 2 echo 'aaaaaa bbbb' │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,26 @@
Search Query: > asdf
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -0,0 +1,26 @@
Search Query: > echo
┌─────────────────────────────────────────────────────────────────────────────┐
│ Hostname Exit Code Command foo │
│─────────────────────────────────────────────────────────────────────────────│
│ localhost 2 echo 'bar' & │
│ localhost 2 echo 'aaaaaa bbbb' │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
│ │
└─────────────────────────────────────────────────────────────────────────────┘

View File

@ -257,6 +257,15 @@ func getTerminalSize() (int, int, error) {
var bigQueryResults []table.Row
func makeTableColumns(ctx *context.Context, columnNames []string, rows []table.Row) ([]table.Column, error) {
// Handle an initial query with no results
if len(rows) == 0 || len(rows[0]) == 0 {
allRows, _, err := getRows(ctx, columnNames, "", 25)
if err != nil {
return nil, err
}
return makeTableColumns(ctx, columnNames, allRows)
}
// Calculate the minimum amount of space that we need for each column for the current actual search
columnWidths := calculateColumnWidths(rows)
totalWidth := 20