mirror of
https://github.com/ddworken/hishtory.git
synced 2024-12-23 23:39:02 +01:00
Add handling for TUI queries with no results + more tests
This commit is contained in:
parent
e520b23858
commit
029bf27117
@ -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
|
||||
|
26
client/lib/goldens/testControlR-InitialSearch
Normal file
26
client/lib/goldens/testControlR-InitialSearch
Normal 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 ~/ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
26
client/lib/goldens/testControlR-InitialSearchExpanded
Normal file
26
client/lib/goldens/testControlR-InitialSearchExpanded
Normal file
@ -0,0 +1,26 @@
|
||||
Search Query: > echo
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname Exit Code Command foo │
|
||||
│─────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost 2 echo 'bar' & │
|
||||
│ localhost 2 echo 'aaaaaa bbbb' │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
26
client/lib/goldens/testControlR-InitialSearchNoResults
Normal file
26
client/lib/goldens/testControlR-InitialSearchNoResults
Normal file
@ -0,0 +1,26 @@
|
||||
Search Query: > asdf
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname Exit Code Command foo │
|
||||
│─────────────────────────────────────────────────────────────────────────────│
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
@ -0,0 +1,26 @@
|
||||
Search Query: > echo
|
||||
|
||||
┌─────────────────────────────────────────────────────────────────────────────┐
|
||||
│ Hostname Exit Code Command foo │
|
||||
│─────────────────────────────────────────────────────────────────────────────│
|
||||
│ localhost 2 echo 'bar' & │
|
||||
│ localhost 2 echo 'aaaaaa bbbb' │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────────────────┘
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user