From eb639b749657d27cd9044229ded9162b483cee7c Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 18 Dec 2022 15:39:03 -0800 Subject: [PATCH] Add code for header for #56 --- client/lib/goldens/TestFish-table | 11 ++--- client/lib/goldens/TestTimestampFormat-tquery | 1 + client/lib/goldens/TestTui-Exit | 1 - client/lib/goldens/TestTui-Initial | 3 ++ .../lib/goldens/TestTui-InitialInvalidSearch | 1 + client/lib/goldens/TestTui-InvalidSearch | 2 + client/lib/goldens/TestTui-LeftScroll | 3 ++ client/lib/goldens/TestTui-Resize | 3 ++ client/lib/goldens/TestTui-Search | 3 ++ client/lib/goldens/TestTui-SmallTerminal | 3 ++ .../testControlR-DisplayMultiline-fish | 48 +++++++++---------- client/lib/goldens/testControlR-Final | 48 +++++++++---------- client/lib/goldens/testControlR-InitialSearch | 48 +++++++++---------- .../testControlR-InitialSearchExpanded | 48 +++++++++---------- .../testControlR-InitialSearchNoResults | 48 +++++++++---------- ...olR-InitialSearchNoResultsThenFoundResults | 48 +++++++++---------- client/lib/goldens/testControlR-customColumn | 48 +++++++++---------- .../lib/goldens/testCustomColumns-tquery-zsh | 47 +++++++++--------- .../testRemoveDuplicateRows-enabled-tquery | 1 + .../goldens/testRemoveDuplicateRows-tquery | 1 + client/lib/tui.go | 9 +++- 21 files changed, 226 insertions(+), 199 deletions(-) diff --git a/client/lib/goldens/TestFish-table b/client/lib/goldens/TestFish-table index 3491deb..02fd3b7 100644 --- a/client/lib/goldens/TestFish-table +++ b/client/lib/goldens/TestFish-table @@ -1,6 +1,5 @@ -CWD Hostname Exit Code Command -/ ghaction-runner-hostname 0 hishtory config-set displayed-columns CWD Hostname 'Exit Code' Command -/ ghaction-runner-hostname 0 ls /tmp/ & -/ ghaction-runner-hostname 0 echo "foo" -/ ghaction-runner-hostname 0 echo bar -/ ghaction-runner-hostname 0 echo foo +CWD Hostname Exit Code Command +/ ghaction-runner-hostname 0 ls /tmp/ & +/ ghaction-runner-hostname 0 echo "foo" +/ ghaction-runner-hostname 0 echo bar +/ ghaction-runner-hostname 0 echo foo diff --git a/client/lib/goldens/TestTimestampFormat-tquery b/client/lib/goldens/TestTimestampFormat-tquery index d9d6465..7a57ad1 100644 --- a/client/lib/goldens/TestTimestampFormat-tquery +++ b/client/lib/goldens/TestTimestampFormat-tquery @@ -1,5 +1,6 @@ -pipefail -tablesizing + hiSHtory v0.Unknown: search your shell history Search Query: > -pipefail -tablesizing diff --git a/client/lib/goldens/TestTui-Exit b/client/lib/goldens/TestTui-Exit index 3378351..91e72f6 100644 --- a/client/lib/goldens/TestTui-Exit +++ b/client/lib/goldens/TestTui-Exit @@ -1,4 +1,3 @@ -/Users/david/.zshrc:source:22: no such file or directory: /usr/share/fzf/key-bindings.zsh david@Davids-MacBook-Air hishtory % hishtory tquery david@Davids-MacBook-Air hishtory % \ No newline at end of file diff --git a/client/lib/goldens/TestTui-Initial b/client/lib/goldens/TestTui-Initial index 5541816..68f764c 100644 --- a/client/lib/goldens/TestTui-Initial +++ b/client/lib/goldens/TestTui-Initial @@ -1,3 +1,6 @@ +hiSHtory v0.Unknown: search your shell history + + Search Query: > ls ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/client/lib/goldens/TestTui-InitialInvalidSearch b/client/lib/goldens/TestTui-InitialInvalidSearch index da0f133..6926fa8 100644 --- a/client/lib/goldens/TestTui-InitialInvalidSearch +++ b/client/lib/goldens/TestTui-InitialInvalidSearch @@ -1,5 +1,6 @@ foo: + hiSHtory v0.Unknown: search your shell history Search Query: > ls diff --git a/client/lib/goldens/TestTui-InvalidSearch b/client/lib/goldens/TestTui-InvalidSearch index cfc6358..9764d0a 100644 --- a/client/lib/goldens/TestTui-InvalidSearch +++ b/client/lib/goldens/TestTui-InvalidSearch @@ -1,3 +1,5 @@ +hiSHtory v0.Unknown: search your shell history + Warning: failed to search: search query contains unknown search atom 'ls' that doesn't match any column names diff --git a/client/lib/goldens/TestTui-LeftScroll b/client/lib/goldens/TestTui-LeftScroll index 518ffb2..1c3b30f 100644 --- a/client/lib/goldens/TestTui-LeftScroll +++ b/client/lib/goldens/TestTui-LeftScroll @@ -1,3 +1,6 @@ +hiSHtory v0.Unknown: search your shell history + + Search Query: > ls ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/client/lib/goldens/TestTui-Resize b/client/lib/goldens/TestTui-Resize index eb4afad..b0a8287 100644 --- a/client/lib/goldens/TestTui-Resize +++ b/client/lib/goldens/TestTui-Resize @@ -1,3 +1,6 @@ +hiSHtory v0.Unknown: search your shell history + + Search Query: > ls ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/client/lib/goldens/TestTui-Search b/client/lib/goldens/TestTui-Search index 518ffb2..1c3b30f 100644 --- a/client/lib/goldens/TestTui-Search +++ b/client/lib/goldens/TestTui-Search @@ -1,3 +1,6 @@ +hiSHtory v0.Unknown: search your shell history + + Search Query: > ls ┌────────────────────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/client/lib/goldens/TestTui-SmallTerminal b/client/lib/goldens/TestTui-SmallTerminal index 9466871..59ce515 100644 --- a/client/lib/goldens/TestTui-SmallTerminal +++ b/client/lib/goldens/TestTui-SmallTerminal @@ -1,3 +1,6 @@ +hiSHtory v0.Unknown: search your shell history + + Search Query: > ls ┌────────────────────────────────────────────────────────────────────────────────────────┐ diff --git a/client/lib/goldens/testControlR-DisplayMultiline-fish b/client/lib/goldens/testControlR-DisplayMultiline-fish index 0346dec..573c4b5 100644 --- a/client/lib/goldens/testControlR-DisplayMultiline-fish +++ b/client/lib/goldens/testControlR-DisplayMultiline-fish @@ -1,26 +1,26 @@ Search Query: > Slah -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ ghaction-runner-hostname 0 ls -Slah / foo │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-Final b/client/lib/goldens/testControlR-Final index 95c28be..78704a2 100644 --- a/client/lib/goldens/testControlR-Final +++ b/client/lib/goldens/testControlR-Final @@ -1,26 +1,26 @@ Search Query: > -pipefail -exit_code:0 -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ localhost 2 echo 'bar' & │ -│ localhost 2 echo 'aaaaaa bbbb' │ -│ localhost 2 ls ~/bar/ │ -│ localhost 2 ls ~/foo/ │ -│ server 127 ls ~/ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ localhost 2 echo 'bar' & │ +│ localhost 2 echo 'aaaaaa bbbb' │ +│ localhost 2 ls ~/bar/ │ +│ localhost 2 ls ~/foo/ │ +│ server 127 ls ~/ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-InitialSearch b/client/lib/goldens/testControlR-InitialSearch index 38a5fc7..92c6bd8 100644 --- a/client/lib/goldens/testControlR-InitialSearch +++ b/client/lib/goldens/testControlR-InitialSearch @@ -1,26 +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 ~/ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ localhost 2 ls ~/bar/ │ +│ localhost 2 ls ~/foo/ │ +│ server 127 ls ~/ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-InitialSearchExpanded b/client/lib/goldens/testControlR-InitialSearchExpanded index ce8ec4c..a526db5 100644 --- a/client/lib/goldens/testControlR-InitialSearchExpanded +++ b/client/lib/goldens/testControlR-InitialSearchExpanded @@ -1,26 +1,26 @@ Search Query: > echo -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ localhost 2 echo 'bar' & │ -│ localhost 2 echo 'aaaaaa bbbb' │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ localhost 2 echo 'bar' & │ +│ localhost 2 echo 'aaaaaa bbbb' │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-InitialSearchNoResults b/client/lib/goldens/testControlR-InitialSearchNoResults index 7cb79e1..91a4092 100644 --- a/client/lib/goldens/testControlR-InitialSearchNoResults +++ b/client/lib/goldens/testControlR-InitialSearchNoResults @@ -1,26 +1,26 @@ Search Query: > asdf -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-InitialSearchNoResultsThenFoundResults b/client/lib/goldens/testControlR-InitialSearchNoResultsThenFoundResults index ce8ec4c..a526db5 100644 --- a/client/lib/goldens/testControlR-InitialSearchNoResultsThenFoundResults +++ b/client/lib/goldens/testControlR-InitialSearchNoResultsThenFoundResults @@ -1,26 +1,26 @@ Search Query: > echo -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ localhost 2 echo 'bar' & │ -│ localhost 2 echo 'aaaaaa bbbb' │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ localhost 2 echo 'bar' & │ +│ localhost 2 echo 'aaaaaa bbbb' │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testControlR-customColumn b/client/lib/goldens/testControlR-customColumn index c2b9578..70b1442 100644 --- a/client/lib/goldens/testControlR-customColumn +++ b/client/lib/goldens/testControlR-customColumn @@ -1,26 +1,26 @@ Search Query: > -pipefail -┌─────────────────────────────────────────────────────────────────────────────┐ -│ Hostname Exit Code Command foo │ -│─────────────────────────────────────────────────────────────────────────────│ -│ ghaction-runner-hostname 0 ls / foo │ -│ localhost 2 echo 'bar' & │ -│ localhost 2 echo 'aaaaaa bbbb' │ -│ localhost 2 ls ~/bar/ │ -│ localhost 2 ls ~/foo/ │ -│ server 127 ls ~/ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +┌───────────────────────────────────────────────────────────┐ +│ Hostname Exit Code Command foo │ +│───────────────────────────────────────────────────────────│ +│ localhost 2 echo 'bar' & │ +│ localhost 2 echo 'aaaaaa bbbb' │ +│ localhost 2 ls ~/bar/ │ +│ localhost 2 ls ~/foo/ │ +│ server 127 ls ~/ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└───────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testCustomColumns-tquery-zsh b/client/lib/goldens/testCustomColumns-tquery-zsh index a64ddad..661feb0 100644 --- a/client/lib/goldens/testCustomColumns-tquery-zsh +++ b/client/lib/goldens/testCustomColumns-tquery-zsh @@ -1,30 +1,31 @@ david@Davids-MacBook-Air hishtory % hishtory tquery -pipefail + hiSHtory v0.Unknown: search your shell history Search Query: > -pipefail -┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ Exit Code git_remote Command │ -│─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ -│ 0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command │ -│ 0 echo bar │ -│ 0 cd / │ -│ 0 git@github.com:ddworken/hishtory.git echo foo │ +┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ +│ Exit Code git_remote Command │ +│──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────│ +│ 0 git@github.com:ddworken/hishtory.git hishtory config-set displayed-columns 'Exit Code' git_remote Command │ +│ 0 echo bar │ +│ 0 cd / │ +│ 0 git@github.com:ddworken/hishtory.git echo foo │ │ 0 git@github.com:ddworken/hishtory.git hishtory config-add custom-columns git_remote '(git remote -v 2>/dev/null | grep origin 1>/dev/null ) && git remote get-url origin || … │ -│ 0 echo baz │ -│ 0 cd / │ -│ 0 echo $FOOBAR world │ -│ 0 export FOOBAR='hello' │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -│ │ -└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file +│ 0 echo baz │ +│ 0 cd / │ +│ 0 echo $FOOBAR world │ +│ 0 export FOOBAR='hello' │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +│ │ +└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ \ No newline at end of file diff --git a/client/lib/goldens/testRemoveDuplicateRows-enabled-tquery b/client/lib/goldens/testRemoveDuplicateRows-enabled-tquery index 5a5195a..351b3f7 100644 --- a/client/lib/goldens/testRemoveDuplicateRows-enabled-tquery +++ b/client/lib/goldens/testRemoveDuplicateRows-enabled-tquery @@ -1,5 +1,6 @@ -pipefail + hiSHtory v0.Unknown: search your shell history Search Query: > -pipefail diff --git a/client/lib/goldens/testRemoveDuplicateRows-tquery b/client/lib/goldens/testRemoveDuplicateRows-tquery index cfb1572..d6bf383 100644 --- a/client/lib/goldens/testRemoveDuplicateRows-tquery +++ b/client/lib/goldens/testRemoveDuplicateRows-tquery @@ -1,5 +1,6 @@ -pipefail + hiSHtory v0.Unknown: search your shell history Search Query: > -pipefail diff --git a/client/lib/tui.go b/client/lib/tui.go index e0b1b99..3809822 100644 --- a/client/lib/tui.go +++ b/client/lib/tui.go @@ -203,7 +203,14 @@ func (m model) View() string { if m.searchErr != nil { warning += fmt.Sprintf("Warning: failed to search: %v\n\n", m.searchErr) } - return fmt.Sprintf("\n%s\n%s%s\nSearch Query: %s\n\n%s\n", loadingMessage, warning, m.banner, m.queryInput.View(), baseStyle.Render(m.table.View())) + // TODO: change 100 to the actual width + hishtoryInfo := "" + terminalWidth, _, err := getTerminalSize() + if err == nil { + hishtoryInfo = lipgloss.PlaceHorizontal(terminalWidth, lipgloss.Center, fmt.Sprintf("hiSHtory v0.%s: search your shell history", Version)) + hishtoryInfo = lipgloss.NewStyle().Italic(true).Render(hishtoryInfo) + } + return fmt.Sprintf("\n%s\n%s\n%s%s\nSearch Query: %s\n\n%s\n", hishtoryInfo, loadingMessage, warning, m.banner, m.queryInput.View(), baseStyle.Render(m.table.View())) } func getRows(ctx *context.Context, columnNames []string, query string, numEntries int) ([]table.Row, int, error) {