diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-06 18:12:39 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-06 18:12:39 +0200 |
| commit | b566bc141e971ae2a7634c9d836f2ad8b0a62402 (patch) | |
| tree | 111aa195010261c59ae6f53eafa30e9edfbbd212 | |
| parent | 99a6cf4787fd92a25a53acbc9c0bae8bca87cc96 (diff) | |
fix(tui): close help overlay on q instead of quitting
| -rw-r--r-- | internal/tui/tui.go | 20 | ||||
| -rw-r--r-- | internal/tui/tui_test.go | 28 |
2 files changed, 39 insertions, 9 deletions
diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 09b69e5..6b58ab3 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -421,17 +421,17 @@ func (m Model) canHandleDashboardShortcut(msg tea.KeyPressMsg) bool { } func (m Model) handleGlobalKeyPress(msg tea.KeyPressMsg) (tea.Model, tea.Cmd, bool) { - if key.Matches(msg, m.keys.Quit) { - m.quitting = true - m.stopTrace() - return m, tea.Quit, true - } if m.helpOverlayVisible { - if isHelpOverlayCloseKey(msg) || isHelpOverlayOpenKey(msg) { + if isHelpOverlayQuitKey(msg) || isHelpOverlayCloseKey(msg) || isHelpOverlayOpenKey(msg) { m.helpOverlayVisible = false } return m, nil, true } + if key.Matches(msg, m.keys.Quit) { + m.quitting = true + m.stopTrace() + return m, tea.Quit, true + } if isHelpOverlayOpenKey(msg) && !m.attaching && m.lastErr == nil { m.helpOverlayVisible = true return m, nil, true @@ -780,6 +780,10 @@ func isHelpOverlayCloseKey(msg tea.KeyPressMsg) bool { return msg.Code == tea.KeyEsc || msg.String() == "esc" || msg.String() == "?" } +func isHelpOverlayQuitKey(msg tea.KeyPressMsg) bool { + return msg.String() == "q" +} + func runExportCmd(exportEnabled bool, option tuiexport.Option, snap *statsengine.Snapshot) tea.Cmd { return func() tea.Msg { if !exportEnabled { @@ -843,7 +847,7 @@ func renderHelpOverlay(width, height int, groups [][]key.Binding) string { } lines = append(lines, strings.Join(parts, " • ")) } - lines = append(lines, "", "Esc/? close") + lines = append(lines, "", "Esc/?/q close") boxWidth := width - 6 if boxWidth < 72 { @@ -927,7 +931,7 @@ func renderGlobalHelpOverlay(width, height int, sections []helpSection) string { lines = append(lines, " "+truncateHelpLine(line, contentWidth-2)) } } - lines = append(lines, "", "Esc close") + lines = append(lines, "", "Esc/q close") maxLines := height - 4 if maxLines < 6 { diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go index 7c1d886..84d3632 100644 --- a/internal/tui/tui_test.go +++ b/internal/tui/tui_test.go @@ -756,7 +756,7 @@ func TestHelpOverlayOpensWithUppercaseHAndClosesWithEsc(t *testing.T) { t.Fatalf("expected help overlay to become visible after H") } view := m.View().Content - if !strings.Contains(view, "Help") || !strings.Contains(view, "Global") || !strings.Contains(view, "Esc close") { + if !strings.Contains(view, "Help") || !strings.Contains(view, "Global") || !strings.Contains(view, "Esc/q close") { t.Fatalf("expected global help overlay content, got %q", view) } @@ -770,6 +770,32 @@ func TestHelpOverlayOpensWithUppercaseHAndClosesWithEsc(t *testing.T) { } } +func TestHelpOverlayClosesWithQWithoutQuitting(t *testing.T) { + m := NewModel(-1, func(context.Context) error { return nil }) + m.screen = ScreenDashboard + m.attaching = false + m.width = 100 + m.height = 30 + + next, _ := m.Update(tea.KeyPressMsg{Code: []rune{'H'}[0], Text: string([]rune{'H'})}) + m = next.(Model) + if !m.helpOverlayVisible { + t.Fatalf("expected help overlay to become visible after H") + } + + next, cmd := m.Update(tea.KeyPressMsg{Code: []rune{'q'}[0], Text: string([]rune{'q'})}) + m = next.(Model) + if cmd != nil { + t.Fatalf("expected no quit command when closing help with q") + } + if m.helpOverlayVisible { + t.Fatalf("expected q to close help overlay") + } + if m.quitting { + t.Fatalf("expected q in help overlay not to set quitting state") + } +} + func TestHelpOverlayCanOpenFromPIDPicker(t *testing.T) { m := NewModel(-1, func(context.Context) error { return nil }) m.screen = ScreenPIDPicker |
