diff options
| author | adamdotdevin <[email protected]> | 2025-07-31 11:24:23 -0500 |
|---|---|---|
| committer | adamdotdevin <[email protected]> | 2025-07-31 11:24:23 -0500 |
| commit | 872b1e068f1307326d733663d7b79e0fb75d7232 (patch) | |
| tree | e554eb0984a92313b3dd9f083b62f7995b4531bb /packages/tui | |
| parent | e4e0b8fd344273f48ef66e68d9626de80111cc0b (diff) | |
| download | opencode-872b1e068f1307326d733663d7b79e0fb75d7232.tar.gz opencode-872b1e068f1307326d733663d7b79e0fb75d7232.zip | |
feat: more scriptable tui (api)
Diffstat (limited to 'packages/tui')
| -rw-r--r-- | packages/tui/cmd/opencode/main.go | 2 | ||||
| -rw-r--r-- | packages/tui/internal/tui/tui.go | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/packages/tui/cmd/opencode/main.go b/packages/tui/cmd/opencode/main.go index 66888fe40..5532289fd 100644 --- a/packages/tui/cmd/opencode/main.go +++ b/packages/tui/cmd/opencode/main.go @@ -86,7 +86,7 @@ func main() { logger := slog.New(apiHandler) slog.SetDefault(logger) - slog.Debug("TUI launched", "app", appInfoStr, "modes", modesStr) + slog.Debug("TUI launched", "app", appInfoStr, "modes", modesStr, "url", url) go func() { err = clipboard.Init() diff --git a/packages/tui/internal/tui/tui.go b/packages/tui/internal/tui/tui.go index 9b6ec7ea6..0b87872fa 100644 --- a/packages/tui/internal/tui/tui.go +++ b/packages/tui/internal/tui/tui.go @@ -609,6 +609,15 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case "/tui/open-help": helpDialog := dialog.NewHelpDialog(a.app) a.modal = helpDialog + case "/tui/open-sessions": + sessionDialog := dialog.NewSessionDialog(a.app) + a.modal = sessionDialog + case "/tui/open-themes": + themeDialog := dialog.NewThemeDialog() + a.modal = themeDialog + case "/tui/open-models": + modelDialog := dialog.NewModelDialog(a.app) + a.modal = modelDialog case "/tui/append-prompt": var body struct { Text string `json:"text"` @@ -620,6 +629,34 @@ func (a Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { text = " " + text } a.editor.SetValueWithAttachments(existing + text + " ") + case "/tui/submit-prompt": + updated, cmd := a.editor.Submit() + a.editor = updated.(chat.EditorComponent) + cmds = append(cmds, cmd) + case "/tui/clear-prompt": + updated, cmd := a.editor.Clear() + a.editor = updated.(chat.EditorComponent) + cmds = append(cmds, cmd) + case "/tui/execute-command": + var body struct { + Command string `json:"command"` + } + json.Unmarshal((msg.Body), &body) + command := commands.Command{} + for _, cmd := range a.app.Commands { + if string(cmd.Name) == body.Command { + command = cmd + break + } + } + if command.Name == "" { + slog.Error("Invalid command passed to /tui/execute-command", "command", body.Command) + return a, nil + } + updated, cmd := a.executeCommand(commands.Command(command)) + a = updated.(Model) + cmds = append(cmds, cmd) + default: break } |
