From 5f95ac48a4c6d0109ceaf2e3b2c36f33eb416a65 Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sun, 18 Dec 2022 00:27:29 -0800 Subject: [PATCH] Add control-d as an alternate key binding to close the TUI to fix #61 (plus some tests) --- client/client_test.go | 12 ++++++++++++ client/lib/goldens/TestTui-Exit | 4 ++++ client/lib/tui.go | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 client/lib/goldens/TestTui-Exit diff --git a/client/client_test.go b/client/client_test.go index 3fa3ff8..3def024 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1884,6 +1884,18 @@ func TestTui(t *testing.T) { }) out = strings.TrimSpace(strings.Split(out, "hishtory tquery")[1]) compareGoldens(t, out, "TestTui-LeftScroll") + + // Check that we can exit the TUI via pressing esc + out = captureTerminalOutput(t, tester, []string{ + "hishtory SPACE tquery ENTER", + "Escape", + }) + if strings.Contains(out, "Search Query:") { + t.Fatalf("unexpected out=\n%s", out) + } + if !testutils.IsGithubAction() { + compareGoldens(t, out, "TestTui-Exit") + } } func captureTerminalOutput(t *testing.T, tester shellTester, commands []string) string { diff --git a/client/lib/goldens/TestTui-Exit b/client/lib/goldens/TestTui-Exit new file mode 100644 index 0000000..3378351 --- /dev/null +++ b/client/lib/goldens/TestTui-Exit @@ -0,0 +1,4 @@ +/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/tui.go b/client/lib/tui.go index d8fc043..e0b1b99 100644 --- a/client/lib/tui.go +++ b/client/lib/tui.go @@ -125,7 +125,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyMsg: switch msg.String() { - case "esc", "ctrl+c": + case "esc", "ctrl+c", "ctrl+d": m.quitting = true return m, tea.Quit case "enter":