From f7dd48e60dbe0fe05ddd8720af2dba619eae5b0f Mon Sep 17 00:00:00 2001 From: adamdotdevin <2363879+adamdottv@users.noreply.github.com> Date: Wed, 16 Jul 2025 14:20:19 -0500 Subject: [PATCH] feat(tui): more ways to quit --- packages/tui/internal/commands/command.go | 2 +- packages/tui/internal/completions/commands.go | 5 ----- packages/tui/internal/components/chat/editor.go | 6 ++++++ packages/tui/internal/components/dialog/complete.go | 5 +---- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/tui/internal/commands/command.go b/packages/tui/internal/commands/command.go index 6af7a456..a5b33a4b 100644 --- a/packages/tui/internal/commands/command.go +++ b/packages/tui/internal/commands/command.go @@ -336,7 +336,7 @@ func LoadFromConfig(config *opencode.Config) CommandRegistry { Name: AppExitCommand, Description: "exit the app", Keybindings: parseBindings("ctrl+c", "q"), - Trigger: []string{"exit", "quit"}, + Trigger: []string{"exit", "quit", "q"}, }, } registry := make(CommandRegistry) diff --git a/packages/tui/internal/completions/commands.go b/packages/tui/internal/completions/commands.go index 80c9de4f..2ffe3ea9 100644 --- a/packages/tui/internal/completions/commands.go +++ b/packages/tui/internal/completions/commands.go @@ -77,7 +77,6 @@ func (c *CommandCompletionProvider) GetChildEntries( return items, nil } - // Use fuzzy matching for commands var commandNames []string commandMap := make(map[string]CompletionSuggestion) @@ -86,17 +85,13 @@ func (c *CommandCompletionProvider) GetChildEntries( continue } space := space - lipgloss.Width(cmd.PrimaryTrigger()) - // Add all triggers as searchable options for _, trigger := range cmd.Trigger { commandNames = append(commandNames, trigger) commandMap[trigger] = c.getCommandCompletionItem(cmd, space) } } - // Find fuzzy matches matches := fuzzy.RankFindFold(query, commandNames) - - // Sort by score (best matches first) sort.Sort(matches) // Convert matches to completion items, deduplicating by command name diff --git a/packages/tui/internal/components/chat/editor.go b/packages/tui/internal/components/chat/editor.go index de74b489..efbc0834 100644 --- a/packages/tui/internal/components/chat/editor.go +++ b/packages/tui/internal/components/chat/editor.go @@ -344,6 +344,12 @@ func (m *editorComponent) Submit() (tea.Model, tea.Cmd) { if value == "" { return m, nil } + + switch value { + case "exit", "quit", "q", ":q": + return m, tea.Quit + } + if len(value) > 0 && value[len(value)-1] == '\\' { // If the last character is a backslash, remove it and add a newline m.textarea.ReplaceRange(len(value)-1, len(value), "") diff --git a/packages/tui/internal/components/dialog/complete.go b/packages/tui/internal/components/dialog/complete.go index 52501c89..ef02c0a8 100644 --- a/packages/tui/internal/components/dialog/complete.go +++ b/packages/tui/internal/components/dialog/complete.go @@ -85,7 +85,7 @@ func (c *completionDialogComponent) getAllCompletions(query string) tea.Cmd { } // If there's a query, use fuzzy ranking to sort results - if query != "" && len(allItems) > 0 { + if query != "" && len(allItems) > 0 && len(c.providers) > 1 { t := theme.CurrentTheme() baseStyle := styles.NewStyle().Background(t.BackgroundElement()) // Create a slice of display values for fuzzy matching @@ -94,10 +94,7 @@ func (c *completionDialogComponent) getAllCompletions(query string) tea.Cmd { displayValues[i] = item.Display(baseStyle) } - // Get fuzzy matches with ranking matches := fuzzy.RankFindFold(query, displayValues) - - // Sort by score (best matches first) sort.Sort(matches) // Reorder items based on fuzzy ranking