xonecas.io
62159
Sy

symb / commit 02874d6

feat: help modal

xonecas2026-02-17 02874d66332778a02d43e09ba658d87515d530d9 parent 78cfb44

4 files changed

internal/tui/modal/modal.go+11−3
@@ -61,6 +61,9 @@ type Model struct {
6161
6262 // Prompt shown before the input text.
6363 Prompt string
64+
65+ // WidthPct controls the modal width as a percent of app width.
66+ WidthPct int
6467 }
6568
6669 // New creates a modal with the given search function.
@@ -212,7 +215,11 @@ func (m *Model) handleCursor(key string) {
212215
213216 // View renders the modal at the given app width and height.
214217 func (m *Model) View(appWidth, appHeight int) string {
215- w := appWidth * 80 / 100
218+ widthPct := m.WidthPct
219+ if widthPct <= 0 {
220+ widthPct = 80
221+ }
222+ w := appWidth * widthPct / 100
216223 h := appHeight * 80 / 100
217224 if w < 30 {
218225 w = 30
@@ -283,6 +290,7 @@ func (m *Model) renderList(innerW, listHeight int) []string {
283290 }
284291
285292 bg := lipgloss.Color(m.colors.Bg)
293+ baseStyle := lipgloss.NewStyle().Foreground(lipgloss.Color(m.colors.Fg)).Background(bg)
286294 dimStyle := lipgloss.NewStyle().
287295 Foreground(lipgloss.Color(m.colors.Dim)).
288296 Background(bg)
@@ -300,12 +308,12 @@ func (m *Model) renderList(innerW, listHeight int) []string {
300308 if item.Desc != "" {
301309 line += dimStyle.Render(" " + item.Desc)
302310 }
303- lines = append(lines, padRight(line, innerW))
311+ lines = append(lines, baseStyle.Render(padRight(line, innerW)))
304312 }
305313 }
306314
307315 for len(lines) < listHeight {
308- lines = append(lines, strings.Repeat(" ", innerW))
316+ lines = append(lines, baseStyle.Render(strings.Repeat(" ", innerW)))
309317 }
310318 return lines
311319 }
internal/tui/tui.go+3−1
@@ -246,7 +246,9 @@ type Model struct {
246246
247247 // File finder modal
248248 fileModal *modal.Model
249- searcher *filesearch.Searcher
249+ // Keybinds modal
250+ keybindsModal *modal.Model
251+ searcher *filesearch.Searcher
250252 // Pending tool calls: maps tool call ID → arguments for line extraction
251253 pendingToolCalls map[string]provider.ToolCall
252254
internal/tui/update.go+85−0
@@ -22,8 +22,13 @@ import (
2222 // ---------------------------------------------------------------------------
2323
2424 func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
25+
2526 m.frameLines = nil // invalidate per-frame wrap cache
2627
28+ // Keybinds modal intercepts all input when open.
29+ if mdl, cmd, handled := m.updateKeybindsModal(msg); handled {
30+ return mdl, cmd
31+ }
2732 // File finder modal intercepts all input when open.
2833 if mdl, cmd, handled := m.updateFileModal(msg); handled {
2934 return mdl, cmd
@@ -206,6 +211,7 @@ func (m *Model) keyPressHandlers() map[string]func(*Model) (Model, tea.Cmd, bool
206211 "esc": (*Model).handleEsc,
207212 "enter": (*Model).handleEnter,
208213 "ctrl+f": (*Model).handleCtrlF,
214+ "ctrl+h": (*Model).handleCtrlH,
209215 }
210216 }
211217
@@ -262,6 +268,12 @@ func (m *Model) handleCtrlF() (Model, tea.Cmd, bool) {
262268 return Model{}, nil, false
263269 }
264270
271+func (m *Model) handleCtrlH() (Model, tea.Cmd, bool) {
272+ m.openKeybindsModal()
273+ return *m, nil, true
274+}
275+
276+
265277 // handleUserMsg records a user message in the DB and conversation display.
266278 func (m *Model) handleUserMsg(msg llmUserMsg) Model {
267279 now := time.Now()
@@ -844,9 +856,82 @@ func (m *Model) openFileModal() {
844856 SelBg: palette.Fg,
845857 Border: palette.Border,
846858 })
859+ md.WidthPct = 80
860+
847861 m.fileModal = &md
848862 }
849863
864+func (m *Model) openKeybindsModal() {
865+ items := []modal.Item{
866+ {Name: "ctrl+h", Desc: "keybinds"},
867+ {Name: "ctrl+f", Desc: "file search"},
868+ {Name: "ctrl+s", Desc: "send diff"},
869+ {Name: "ctrl+shift+c", Desc: "copy selection"},
870+ {Name: "ctrl+shift+v", Desc: "paste"},
871+ {Name: "ctrl+c", Desc: "quit"},
872+ {Name: "esc", Desc: "cancel/blur"},
873+ {Name: "enter", Desc: "send message"},
874+ {Name: "shift+enter", Desc: "newline in input"},
875+ {Name: "tab", Desc: "indent"},
876+ {Name: "backspace/ctrl+h", Desc: "delete backward"},
877+ {Name: "delete/ctrl+d", Desc: "delete forward"},
878+ {Name: "up/down/left/right", Desc: "move cursor"},
879+ {Name: "shift+arrows", Desc: "extend selection"},
880+ {Name: "home/end/ctrl+a/ctrl+e", Desc: "line start/end"},
881+ {Name: "pgup/pgdown", Desc: "page scroll"},
882+ {Name: "shift+pgup/shift+pgdown", Desc: "extend selection by page"},
883+ {Name: "ctrl+home/ctrl+end", Desc: "file start/end"},
884+ }
885+ searchFn := func(query string) []modal.Item {
886+ if query == "" {
887+ return items
888+ }
889+ q := strings.ToLower(query)
890+ var filtered []modal.Item
891+ for _, item := range items {
892+ name := strings.ToLower(item.Name)
893+ desc := strings.ToLower(item.Desc)
894+ if strings.Contains(name, q) || strings.Contains(desc, q) {
895+ filtered = append(filtered, item)
896+ }
897+ }
898+ return filtered
899+ }
900+ md := modal.New(searchFn, "Keys: ", modal.Colors{
901+ Fg: palette.Fg,
902+ Bg: palette.Bg,
903+ Dim: palette.Dim,
904+ SelFg: palette.Bg,
905+ SelBg: palette.Fg,
906+ Border: palette.Border,
907+ })
908+ md.WidthPct = 60
909+ m.keybindsModal = &md
910+}
911+
912+func (m *Model) updateKeybindsModal(msg tea.Msg) (Model, tea.Cmd, bool) {
913+ if m.keybindsModal == nil {
914+ return *m, nil, false
915+ }
916+ action, cmd := m.keybindsModal.HandleMsg(msg)
917+ switch action.(type) {
918+ case modal.ActionClose:
919+ m.keybindsModal = nil
920+ return *m, nil, true
921+ case modal.ActionSelect:
922+ return *m, nil, true
923+ }
924+ if cmd != nil {
925+ return *m, cmd, true
926+ }
927+ switch msg.(type) {
928+ case tea.KeyPressMsg, tea.MouseMsg:
929+ return *m, nil, true
930+ }
931+ return *m, nil, false
932+}
933+
934+
850935 func (m *Model) updateFileModal(msg tea.Msg) (Model, tea.Cmd, bool) {
851936 if m.fileModal == nil {
852937 return *m, nil, false
internal/tui/view.go+4−1
@@ -15,7 +15,10 @@ import (
1515
1616 func (m Model) View() tea.View {
1717 content := m.renderContent()
18- if m.fileModal != nil {
18+ switch {
19+ case m.keybindsModal != nil:
20+ content = m.keybindsModal.View(m.width, m.height)
21+ case m.fileModal != nil:
1922 content = m.fileModal.View(m.width, m.height)
2023 }
2124 v := tea.NewView(content)