From 2dbec29f0c6d4900c835b15ec74989097b7e61e2 Mon Sep 17 00:00:00 2001 From: Gabriel Garrett Date: Tue, 15 Jul 2025 12:50:55 -0500 Subject: [PATCH 1/4] tui: add input history --- packages/tui/internal/commands/command.go | 12 ++++++ .../tui/internal/components/chat/editor.go | 37 +++++++++++++++++++ packages/tui/internal/tui/tui.go | 8 ++++ packages/tui/sdk/config.go | 6 +++ 4 files changed, 63 insertions(+) diff --git a/packages/tui/internal/commands/command.go b/packages/tui/internal/commands/command.go index dfa7abdd0dba..1e6e9c157789 100644 --- a/packages/tui/internal/commands/command.go +++ b/packages/tui/internal/commands/command.go @@ -106,6 +106,8 @@ const ( InputPasteCommand CommandName = "input_paste" InputSubmitCommand CommandName = "input_submit" InputNewlineCommand CommandName = "input_newline" + HistoryPreviousCommand CommandName = "history_previous" + HistoryNextCommand CommandName = "history_next" MessagesPageUpCommand CommandName = "messages_page_up" MessagesPageDownCommand CommandName = "messages_page_down" MessagesHalfPageUpCommand CommandName = "messages_half_page_up" @@ -264,6 +266,16 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry { Description: "insert newline", Keybindings: parseBindings("shift+enter", "ctrl+j"), }, + { + Name: HistoryPreviousCommand, + Description: "previous input", + Keybindings: parseBindings("up"), + }, + { + Name: HistoryNextCommand, + Description: "next input", + Keybindings: parseBindings("down"), + }, { Name: MessagesPageUpCommand, Description: "page up", diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index 67f1f75eae1b..0b61244a83d0 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -39,6 +39,8 @@ type EditorComponent interface { Clear() (tea.Model, tea.Cmd) Paste() (tea.Model, tea.Cmd) Newline() (tea.Model, tea.Cmd) + HistoryPrevious() (tea.Model, tea.Cmd) + HistoryNext() (tea.Model, tea.Cmd) SetValue(value string) SetInterruptKeyInDebounce(inDebounce bool) SetExitKeyInDebounce(inDebounce bool) @@ -50,6 +52,8 @@ type editorComponent struct { spinner spinner.Model interruptKeyInDebounce bool exitKeyInDebounce bool + history []string + historyIndex int } func (m *editorComponent) Init() tea.Cmd { @@ -357,6 +361,9 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { }) } + m.history = append(m.history, value) + m.historyIndex = len(m.history) + updated, cmd := m.Clear() m = updated.(*editorComponent) cmds = append(cmds, cmd) @@ -403,6 +410,34 @@ func (m *editorComponent) Newline() (tea.Model, tea.Cmd) { return m, nil } +func (m *editorComponent) HistoryPrevious() (tea.Model, tea.Cmd) { + if len(m.history) == 0 { + return m, nil + } + if m.historyIndex > 0 { + m.historyIndex-- + } + m.SetValue(m.history[m.historyIndex]) + m.textarea.CursorEnd() + return m, nil +} + +func (m *editorComponent) HistoryNext() (tea.Model, tea.Cmd) { + if len(m.history) == 0 { + m.SetValue("") + return m, nil + } + if m.historyIndex < len(m.history)-1 { + m.historyIndex++ + m.SetValue(m.history[m.historyIndex]) + } else { + m.historyIndex = len(m.history) + m.SetValue("") + } + m.textarea.CursorEnd() + return m, nil +} + func (m *editorComponent) SetInterruptKeyInDebounce(inDebounce bool) { m.interruptKeyInDebounce = inDebounce } @@ -487,6 +522,8 @@ func NewEditorComponent(app *app.App) EditorComponent { textarea: ta, spinner: s, interruptKeyInDebounce: false, + history: []string{}, + historyIndex: 0, } return m diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index 1e34d4cbcc49..0a454a4a4742 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -950,6 +950,14 @@ func (a appModel) executeCommand(command commands.Command) (tea.Model, tea.Cmd) updated, cmd := a.editor.Newline() a.editor = updated.(chat.EditorComponent) cmds = append(cmds, cmd) + case commands.HistoryPreviousCommand: + updated, cmd := a.editor.HistoryPrevious() + a.editor = updated.(chat.EditorComponent) + cmds = append(cmds, cmd) + case commands.HistoryNextCommand: + updated, cmd := a.editor.HistoryNext() + a.editor = updated.(chat.EditorComponent) + cmds = append(cmds, cmd) case commands.MessagesFirstCommand: updated, cmd := a.messages.First() a.messages = updated.(chat.MessagesComponent) diff --git a/packages/tui/sdk/config.go b/packages/tui/sdk/config.go index 7c04cd14b83f..e45116cbf4eb 100644 --- a/packages/tui/sdk/config.go +++ b/packages/tui/sdk/config.go @@ -518,6 +518,10 @@ type Keybinds struct { InputPaste string `json:"input_paste,required"` // Submit input InputSubmit string `json:"input_submit,required"` + // Previous input history + HistoryPrevious string `json:"history_previous,required"` + // Next input history + HistoryNext string `json:"history_next,required"` // Leader key for keybind combinations Leader string `json:"leader,required"` // Copy message @@ -580,6 +584,8 @@ type keybindsJSON struct { InputNewline apijson.Field InputPaste apijson.Field InputSubmit apijson.Field + HistoryPrevious apijson.Field + HistoryNext apijson.Field Leader apijson.Field MessagesCopy apijson.Field MessagesFirst apijson.Field From 7d468e545760e1638bc6cfe1a3312642ae1afd34 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Wed, 16 Jul 2025 12:11:34 +0000 Subject: [PATCH 2/4] ignore: update download stats 2025-07-16 --- STATS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/STATS.md b/STATS.md index 9a8b7938b9a9..cbcc13023ad0 100644 --- a/STATS.md +++ b/STATS.md @@ -17,3 +17,4 @@ | 2025-07-13 | 50,803 (+1,501) | 86,394 (+4,217) | 137,197 (+5,718) | | 2025-07-14 | 53,283 (+2,480) | 87,860 (+1,466) | 141,143 (+3,946) | | 2025-07-15 | 57,590 (+4,307) | 91,036 (+3,176) | 148,626 (+7,483) | +| 2025-07-16 | 62,343 (+4,753) | 95,258 (+4,222) | 157,601 (+8,975) | From 97ca035ff1ac335109cf7db9b3771b6200a87859 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Thu, 17 Jul 2025 12:11:22 +0000 Subject: [PATCH 3/4] ignore: update download stats 2025-07-17 --- STATS.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/STATS.md b/STATS.md index cbcc13023ad0..95c30d7e9497 100644 --- a/STATS.md +++ b/STATS.md @@ -1,20 +1,21 @@ # Download Stats -| Date | GitHub Downloads | npm Downloads | Total | -| ---------- | ---------------- | --------------- | ----------------- | -| 2025-06-29 | 18,789 (+0) | 39,420 (+0) | 58,209 (+0) | -| 2025-06-30 | 20,127 (+1,338) | 41,059 (+1,639) | 61,186 (+2,977) | -| 2025-07-01 | 22,108 (+1,981) | 43,745 (+2,686) | 65,853 (+4,667) | -| 2025-07-02 | 24,814 (+2,706) | 46,168 (+2,423) | 70,982 (+5,129) | -| 2025-07-03 | 27,834 (+3,020) | 49,955 (+3,787) | 77,789 (+6,807) | -| 2025-07-04 | 30,608 (+2,774) | 54,758 (+4,803) | 85,366 (+7,577) | -| 2025-07-05 | 32,524 (+1,916) | 58,371 (+3,613) | 90,895 (+5,529) | -| 2025-07-06 | 33,766 (+1,242) | 59,694 (+1,323) | 93,460 (+2,565) | -| 2025-07-08 | 38,052 (+4,286) | 64,468 (+4,774) | 102,520 (+9,060) | -| 2025-07-10 | 43,796 (+5,744) | 71,402 (+6,934) | 115,198 (+12,678) | -| 2025-07-11 | 46,982 (+3,186) | 77,462 (+6,060) | 124,444 (+9,246) | -| 2025-07-12 | 49,302 (+2,320) | 82,177 (+4,715) | 131,479 (+7,035) | -| 2025-07-13 | 50,803 (+1,501) | 86,394 (+4,217) | 137,197 (+5,718) | -| 2025-07-14 | 53,283 (+2,480) | 87,860 (+1,466) | 141,143 (+3,946) | -| 2025-07-15 | 57,590 (+4,307) | 91,036 (+3,176) | 148,626 (+7,483) | -| 2025-07-16 | 62,343 (+4,753) | 95,258 (+4,222) | 157,601 (+8,975) | +| Date | GitHub Downloads | npm Downloads | Total | +| ---------- | ---------------- | ---------------- | ----------------- | +| 2025-06-29 | 18,789 (+0) | 39,420 (+0) | 58,209 (+0) | +| 2025-06-30 | 20,127 (+1,338) | 41,059 (+1,639) | 61,186 (+2,977) | +| 2025-07-01 | 22,108 (+1,981) | 43,745 (+2,686) | 65,853 (+4,667) | +| 2025-07-02 | 24,814 (+2,706) | 46,168 (+2,423) | 70,982 (+5,129) | +| 2025-07-03 | 27,834 (+3,020) | 49,955 (+3,787) | 77,789 (+6,807) | +| 2025-07-04 | 30,608 (+2,774) | 54,758 (+4,803) | 85,366 (+7,577) | +| 2025-07-05 | 32,524 (+1,916) | 58,371 (+3,613) | 90,895 (+5,529) | +| 2025-07-06 | 33,766 (+1,242) | 59,694 (+1,323) | 93,460 (+2,565) | +| 2025-07-08 | 38,052 (+4,286) | 64,468 (+4,774) | 102,520 (+9,060) | +| 2025-07-10 | 43,796 (+5,744) | 71,402 (+6,934) | 115,198 (+12,678) | +| 2025-07-11 | 46,982 (+3,186) | 77,462 (+6,060) | 124,444 (+9,246) | +| 2025-07-12 | 49,302 (+2,320) | 82,177 (+4,715) | 131,479 (+7,035) | +| 2025-07-13 | 50,803 (+1,501) | 86,394 (+4,217) | 137,197 (+5,718) | +| 2025-07-14 | 53,283 (+2,480) | 87,860 (+1,466) | 141,143 (+3,946) | +| 2025-07-15 | 57,590 (+4,307) | 91,036 (+3,176) | 148,626 (+7,483) | +| 2025-07-16 | 62,343 (+4,753) | 95,258 (+4,222) | 157,601 (+8,975) | +| 2025-07-17 | 66,382 (+4,039) | 100,048 (+4,790) | 166,430 (+8,829) | From 90af3e58c5615998839194ebe1fd0de2ff686cfa Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 18 Jul 2025 12:11:40 +0000 Subject: [PATCH 4/4] ignore: update download stats 2025-07-18 --- STATS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/STATS.md b/STATS.md index 95c30d7e9497..6dd6cb68afcb 100644 --- a/STATS.md +++ b/STATS.md @@ -19,3 +19,4 @@ | 2025-07-15 | 57,590 (+4,307) | 91,036 (+3,176) | 148,626 (+7,483) | | 2025-07-16 | 62,343 (+4,753) | 95,258 (+4,222) | 157,601 (+8,975) | | 2025-07-17 | 66,382 (+4,039) | 100,048 (+4,790) | 166,430 (+8,829) | +| 2025-07-18 | 70,404 (+4,022) | 102,587 (+2,539) | 172,991 (+6,561) |