on main help sign in
feat(tui): display newline shitf+enter in help when supported
commit9afc49196707e7706f15e9162ec36de2565f9c04 authorAyman Bagabas <ayman.bagabas@gmail.com> dateWed 9 Jul 2025, 10:21 (1 year ago) parent50e7596
4 files changed+27−3
internal/tui/components/chat/editor/editor.go+3 internal/tui/components/chat/editor/keys.go+12−2 internal/tui/page/chat/chat.go+4 internal/tui/tui.go+8−1
internal/tui/components/chat/editor/editor.go+3
@@ -145,6 +145,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
145145 var cmd tea.Cmd
146146 var cmds []tea.Cmd
147147 switch msg := msg.(type) {
148+ case tea.KeyboardEnhancementsMsg:
149+ m.keyMap.keyboard = msg
150+ return m, nil
148151 case chat.SessionSelectedMsg:
149152 if msg.ID != m.session.ID {
150153 m.session = msg
internal/tui/components/chat/editor/keys.go+12−2
@@ -2,6 +2,7 @@ package editor
22
33import (
44 "github.com/charmbracelet/bubbles/v2/key"
5+ tea "github.com/charmbracelet/bubbletea/v2"
56)
67
78type EditorKeyMap struct {
@@ -9,6 +10,8 @@ type EditorKeyMap struct {
910 SendMessage key.Binding
1011 OpenEditor key.Binding
1112 Newline key.Binding
13+
14+ keyboard tea.KeyboardEnhancementsMsg
1215}
1316
1417func DefaultEditorKeyMap() EditorKeyMap {
@@ -27,18 +30,25 @@ func DefaultEditorKeyMap() EditorKeyMap {
2730 ),
2831 Newline: key.NewBinding(
2932 key.WithKeys("shift+enter", "ctrl+j"),
30− key.WithHelp("shift+enter", "newline"), key.WithHelp("ctrl+j", "newline"),
33+ // "ctrl+j" is a common keybinding for newline in many editors. If
34+ // the terminal supports "shift+enter", we substitute the help text
35+ // to reflect that.
36+ key.WithHelp("ctrl+j", "newline"),
3137 ),
3238 }
3339}
3440
3541// KeyBindings implements layout.KeyMapProvider
3642func (k EditorKeyMap) KeyBindings() []key.Binding {
43+ newline := k.Newline
44+ if k.keyboard.SupportsKeyDisambiguation() {
45+ newline.SetHelp("shift+enter", newline.Help().Desc)
46+ }
3747 return []key.Binding{
3848 k.AddFile,
3949 k.SendMessage,
4050 k.OpenEditor,
41− k.Newline,
51+ newline,
4252 }
4353}
4454
internal/tui/page/chat/chat.go+4
@@ -80,6 +80,10 @@ func (p *chatPage) cancelTimerCmd() tea.Cmd {
8080func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
8181 var cmds []tea.Cmd
8282 switch msg := msg.(type) {
83+ case tea.KeyboardEnhancementsMsg:
84+ m, cmd := p.layout.Update(msg)
85+ p.layout = m.(layout.SplitPaneLayout)
86+ return p, cmd
8387 case CancelTimerExpiredMsg:
8488 p.cancelPending = false
8589 return p, nil
internal/tui/tui.go+8−1
@@ -95,7 +95,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
9595
9696 switch msg := msg.(type) {
9797 case tea.KeyboardEnhancementsMsg:
98− return a, nil
98+ for id, page := range a.pages {
99+ m, pageCmd := page.Update(msg)
100+ a.pages[id] = m.(util.Model)
101+ if pageCmd != nil {
102+ cmds = append(cmds, pageCmd)
103+ }
104+ }
105+ return a, tea.Batch(cmds...)
99106 case tea.WindowSizeMsg:
100107 return a, a.handleWindowResize(msg.Width, msg.Height)
101108