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