Skip to content

Commit ba9b462

Browse files
authored
Merge pull request #2017 from dgageot/board/nicer-tmux-462c76e9
tui: improve tmux experience and simplify keyboard enhancements
2 parents e08bd1c + 552362d commit ba9b462

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

pkg/tui/tui.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,11 @@ type appModel struct {
116116
// Focus state
117117
focusedPanel FocusedPanel
118118

119-
// keyboardEnhancements stores the last keyboard enhancements message
119+
// keyboardEnhancements stores the last keyboard enhancements message.
120+
// When non-nil with Flags != 0, the terminal supports key disambiguation
121+
// (shift+enter, ctrl+i vs tab, etc.).
120122
keyboardEnhancements *tea.KeyboardEnhancementsMsg
121123

122-
// keyboardEnhancementsSupported tracks whether the terminal supports keyboard enhancements
123-
keyboardEnhancementsSupported bool
124-
125124
// pendingRestores maps runtime tab IDs (supervisor routing keys) to
126125
// persisted session-store IDs. When a tab with a pending restore is first
127126
// switched to, the persisted session is loaded via replaceActiveSession —
@@ -230,15 +229,20 @@ func (m *appModel) SetProgram(p *tea.Program) {
230229
m.supervisor.SetProgram(p)
231230
}
232231

232+
// hasKeyboardEnhancements reports whether the terminal supports keyboard
233+
// enhancements (Kitty keyboard protocol). When true, keybindings like
234+
// shift+enter become available.
235+
func (m *appModel) hasKeyboardEnhancements() bool {
236+
return m.keyboardEnhancements != nil && m.keyboardEnhancements.Flags != 0
237+
}
238+
233239
// reapplyKeyboardEnhancements forwards the cached keyboard enhancements message
234-
// to the active chat page and editor so new/replaced instances pick up the
235-
// terminal's key disambiguation support.
240+
// to the active editor so new/replaced instances pick up the terminal's key
241+
// disambiguation support.
236242
func (m *appModel) reapplyKeyboardEnhancements() {
237243
if m.keyboardEnhancements == nil {
238244
return
239245
}
240-
updated, _ := m.chatPage.Update(*m.keyboardEnhancements)
241-
m.chatPage = updated.(chat.Page)
242246
editorModel, _ := m.editor.Update(*m.keyboardEnhancements)
243247
m.editor = editorModel.(editor.Editor)
244248
}
@@ -543,14 +547,10 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
543547

544548
case tea.KeyboardEnhancementsMsg:
545549
m.keyboardEnhancements = &msg
546-
m.keyboardEnhancementsSupported = msg.Flags != 0
547-
// Forward to content view
548-
updated, cmd := m.chatPage.Update(msg)
549-
m.chatPage = updated.(chat.Page)
550-
// Forward to editor
551-
editorModel, editorCmd := m.editor.Update(msg)
550+
// Forward to editor (only component that uses it for keybinding config)
551+
editorModel, cmd := m.editor.Update(msg)
552552
m.editor = editorModel.(editor.Editor)
553-
return m, tea.Batch(cmd, editorCmd)
553+
return m, cmd
554554

555555
// --- Keyboard input ---
556556

@@ -1452,7 +1452,7 @@ func (m *appModel) Bindings() []key.Binding {
14521452
))
14531453

14541454
// Show newline help based on keyboard enhancement support
1455-
if m.keyboardEnhancementsSupported {
1455+
if m.hasKeyboardEnhancements() {
14561456
bindings = append(bindings, key.NewBinding(
14571457
key.WithKeys("shift+enter"),
14581458
key.WithHelp("Shift+Enter", "newline"),
@@ -2187,6 +2187,8 @@ func toFullscreenView(content, windowTitle string, working bool) tea.View {
21872187
view.MouseMode = tea.MouseModeCellMotion
21882188
view.BackgroundColor = styles.Background
21892189
view.WindowTitle = windowTitle
2190+
view.ReportFocus = true
2191+
view.KeyboardEnhancements.ReportEventTypes = true
21902192
if working {
21912193
view.ProgressBar = tea.NewProgressBar(tea.ProgressBarIndeterminate, 0)
21922194
}

0 commit comments

Comments
 (0)