diff options
| author | Tom <[email protected]> | 2025-06-24 18:31:02 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-24 06:31:02 -0500 |
| commit | 6bc61cbc2dab6e363b2f333c14772983dd4cd223 (patch) | |
| tree | 3658e3583fbd431a8646dc988928723fd0920746 /packages/tui/internal/components/chat/editor.go | |
| parent | 01d351bebeb0e7ad9b97e63bbebdc7478339018f (diff) | |
| download | opencode-6bc61cbc2dab6e363b2f333c14772983dd4cd223.tar.gz opencode-6bc61cbc2dab6e363b2f333c14772983dd4cd223.zip | |
feat(tui): add debounce logic to escape key interrupt (#169)
Co-authored-by: opencode <[email protected]>
Co-authored-by: adamdottv <[email protected]>
Diffstat (limited to 'packages/tui/internal/components/chat/editor.go')
| -rw-r--r-- | packages/tui/internal/components/chat/editor.go | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index f48dcea1b..d67a226fe 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -32,17 +32,19 @@ type EditorComponent interface { Newline() (tea.Model, tea.Cmd) Previous() (tea.Model, tea.Cmd) Next() (tea.Model, tea.Cmd) + SetInterruptKeyInDebounce(inDebounce bool) } type editorComponent struct { - app *app.App - width, height int - textarea textarea.Model - attachments []app.Attachment - history []string - historyIndex int - currentMessage string - spinner spinner.Model + app *app.App + width, height int + textarea textarea.Model + attachments []app.Attachment + history []string + historyIndex int + currentMessage string + spinner spinner.Model + interruptKeyInDebounce bool } func (m *editorComponent) Init() tea.Cmd { @@ -115,9 +117,14 @@ func (m *editorComponent) Content() string { Background(t.BackgroundElement()). Render(textarea) - hint := base("enter") + muted(" send ") + hint := base(m.getSubmitKeyText()) + muted(" send ") if m.app.IsBusy() { - hint = muted("working") + m.spinner.View() + muted(" ") + base("esc") + muted(" interrupt") + keyText := m.getInterruptKeyText() + if m.interruptKeyInDebounce { + hint = muted("working") + m.spinner.View() + muted(" ") + base(keyText+" again") + muted(" interrupt") + } else { + hint = muted("working") + m.spinner.View() + muted(" ") + base(keyText) + muted(" interrupt") + } } model := "" @@ -263,6 +270,18 @@ func (m *editorComponent) Next() (tea.Model, tea.Cmd) { return m, nil } +func (m *editorComponent) SetInterruptKeyInDebounce(inDebounce bool) { + m.interruptKeyInDebounce = inDebounce +} + +func (m *editorComponent) getInterruptKeyText() string { + return m.app.Commands[commands.SessionInterruptCommand].Keys()[0] +} + +func (m *editorComponent) getSubmitKeyText() string { + return m.app.Commands[commands.InputSubmitCommand].Keys()[0] +} + func createTextArea(existing *textarea.Model) textarea.Model { t := theme.CurrentTheme() bgColor := t.BackgroundElement() @@ -311,11 +330,12 @@ func NewEditorComponent(app *app.App) EditorComponent { ta := createTextArea(nil) return &editorComponent{ - app: app, - textarea: ta, - history: []string{}, - historyIndex: 0, - currentMessage: "", - spinner: s, + app: app, + textarea: ta, + history: []string{}, + historyIndex: 0, + currentMessage: "", + spinner: s, + interruptKeyInDebounce: false, } } |
