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