From 9afc49196707e7706f15e9162ec36de2565f9c04 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 9 Jul 2025 10:21:22 -0400 Subject: [PATCH] feat(tui): display newline shitf+enter in help when supported --- internal/tui/components/chat/editor/editor.go | 3 +++ internal/tui/components/chat/editor/keys.go | 14 ++++++++++++-- internal/tui/page/chat/chat.go | 4 ++++ internal/tui/tui.go | 9 ++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/internal/tui/components/chat/editor/editor.go b/internal/tui/components/chat/editor/editor.go index f910efee3b0924ebf2c5f9e77fcf5233ef909d93..ad7f9a57f5232974cbceffedc10a48b3a1b49e0d 100644 --- a/internal/tui/components/chat/editor/editor.go +++ b/internal/tui/components/chat/editor/editor.go @@ -145,6 +145,9 @@ func (m *editorCmp) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmd tea.Cmd var cmds []tea.Cmd switch msg := msg.(type) { + case tea.KeyboardEnhancementsMsg: + m.keyMap.keyboard = msg + return m, nil case chat.SessionSelectedMsg: if msg.ID != m.session.ID { m.session = msg diff --git a/internal/tui/components/chat/editor/keys.go b/internal/tui/components/chat/editor/keys.go index 738e575db220960b2a25b7cfe847901d978786d4..aa2ba1ee44ce7fe9928e7e812acea3898a7496e5 100644 --- a/internal/tui/components/chat/editor/keys.go +++ b/internal/tui/components/chat/editor/keys.go @@ -2,6 +2,7 @@ package editor import ( "github.com/charmbracelet/bubbles/v2/key" + tea "github.com/charmbracelet/bubbletea/v2" ) type EditorKeyMap struct { @@ -9,6 +10,8 @@ type EditorKeyMap struct { SendMessage key.Binding OpenEditor key.Binding Newline key.Binding + + keyboard tea.KeyboardEnhancementsMsg } func DefaultEditorKeyMap() EditorKeyMap { @@ -27,18 +30,25 @@ func DefaultEditorKeyMap() EditorKeyMap { ), Newline: key.NewBinding( key.WithKeys("shift+enter", "ctrl+j"), - key.WithHelp("shift+enter", "newline"), key.WithHelp("ctrl+j", "newline"), + // "ctrl+j" is a common keybinding for newline in many editors. If + // the terminal supports "shift+enter", we substitute the help text + // to reflect that. + key.WithHelp("ctrl+j", "newline"), ), } } // KeyBindings implements layout.KeyMapProvider func (k EditorKeyMap) KeyBindings() []key.Binding { + newline := k.Newline + if k.keyboard.SupportsKeyDisambiguation() { + newline.SetHelp("shift+enter", newline.Help().Desc) + } return []key.Binding{ k.AddFile, k.SendMessage, k.OpenEditor, - k.Newline, + newline, } } diff --git a/internal/tui/page/chat/chat.go b/internal/tui/page/chat/chat.go index b079859c5b935f02247f84ff0757933fc7a11a4f..3e594b9db6d2638dda302791ce579f92b5396323 100644 --- a/internal/tui/page/chat/chat.go +++ b/internal/tui/page/chat/chat.go @@ -80,6 +80,10 @@ func (p *chatPage) cancelTimerCmd() tea.Cmd { func (p *chatPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd switch msg := msg.(type) { + case tea.KeyboardEnhancementsMsg: + m, cmd := p.layout.Update(msg) + p.layout = m.(layout.SplitPaneLayout) + return p, cmd case CancelTimerExpiredMsg: p.cancelPending = false return p, nil diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 7ab868f20f830d040df3a5d2f17347faaec235d0..6327053a014a647331430b71ce52bea143c56e41 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -95,7 +95,14 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { switch msg := msg.(type) { case tea.KeyboardEnhancementsMsg: - return a, nil + for id, page := range a.pages { + m, pageCmd := page.Update(msg) + a.pages[id] = m.(util.Model) + if pageCmd != nil { + cmds = append(cmds, pageCmd) + } + } + return a, tea.Batch(cmds...) case tea.WindowSizeMsg: return a, a.handleWindowResize(msg.Width, msg.Height)