1package modes
2
3import (
4 "fmt"
5 "strings"
6
7 "github.com/mattn/go-runewidth"
8 "github.com/patriceckhart/zot/internal/tui"
9)
10
11// helpKeyRows is the list of keybindings shown by /help.
12var helpKeyRows = [][2]string{
13 {"enter", "submit the current input"},
14 {"alt+enter", "insert a newline"},
15 {"tab", "complete the highlighted slash command"},
16 {"esc", "cancel the current turn (while busy) · clear the input (while idle)"},
17 {"ctrl+c", "exit (while idle) · cancel the current turn (while busy)"},
18 {"ctrl+w", "delete previous word"},
19 {"alt+backspace", "delete previous word (same as ctrl+w)"},
20 {"ctrl+u / ctrl+k", "delete to start / end of line"},
21 {"ctrl+a / ctrl+e", "jump to start / end of line"},
22 {"alt+← / alt+→", "jump one word back / forward"},
23 {"ctrl+l", "redraw the screen"},
24 {"ctrl+o", "expand / collapse long tool results"},
25 {"pgup / pgdn", "scroll the chat one page up / down"},
26 {"up / down", "scroll by 3 lines (when input is empty) · prompt history (otherwise)"},
27}
28
29// renderHelpBlock builds the friendly /help view. Uses the shared
30// frameHeader/frameRule helpers so the rules match every other block
31// in the tui (tool results, code fences, dialogs) — full terminal width
32// in the muted colour.
33//
34// Slash commands and keybindings share the same label column width so
35// every description starts at the same x-position, regardless of which
36// section it lives in. The width is computed from the longest label
37// across BOTH lists, with a minimum of 14 cells so changes to either
38// list don't compress the column visually.
39func renderHelpBlock(th tui.Theme, width int) []string {
40 if width < 20 {
41 width = 20
42 }
43
44 // Label column width uses display cells, not byte length, so
45 // single-cell multibyte runes (← → · …) don't over-count and leave
46 // a raggedy right edge. `len("alt+← / alt+→")` is 17 bytes but
47 // only 13 cells; padding off byte length would either overshoot
48 // (setting labelWidth too high and wasting space on every row)
49 // or undershoot (never padding that row because len >= labelWidth
50 // already, leaving its description mis-aligned).
51 labelWidth := 14
52 for _, c := range slashCatalog {
53 if n := runewidth.StringWidth(c.Name); n > labelWidth {
54 labelWidth = n
55 }
56 }
57 for _, k := range helpKeyRows {
58 if n := runewidth.StringWidth(k[0]); n > labelWidth {
59 labelWidth = n
60 }
61 }
62
63 pad := func(s string) string {
64 w := runewidth.StringWidth(s)
65 if w >= labelWidth {
66 return s
67 }
68 return s + strings.Repeat(" ", labelWidth-w)
69 }
70
71 var out []string
72 out = append(out, frameHeader(th, "zot help", width))
73
74 // commands section
75 out = append(out, tui.Bold("slash commands:"))
76 for _, c := range slashCatalog {
77 out = append(out, fmt.Sprintf(" %s %s",
78 th.FG256(th.Accent, pad(c.Name)),
79 th.FG256(th.Muted, c.Desc)))
80 }
81
82 // keys section
83 out = append(out, "", tui.Bold("keys:"))
84 for _, k := range helpKeyRows {
85 out = append(out, fmt.Sprintf(" %s %s",
86 th.FG256(th.Accent, pad(k[0])),
87 th.FG256(th.Muted, k[1])))
88 }
89
90 out = append(out, frameRule(th, width), "")
91 return out
92}