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