Skip to content

Commit 4f0e48a

Browse files
committed
implemented quit as a command in the aiassist
1 parent 40785dd commit 4f0e48a

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

internal/ui/app.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,18 @@ func (a *App) handleAIMessage(message string) tea.Cmd {
20552055
}
20562056
}
20572057

2058+
// Handle /quit command
2059+
if trimmedMsg == "/quit" {
2060+
// Check for unsaved changes
2061+
if a.editorPane.HasUnsavedChanges() && !a.forceQuit {
2062+
a.showExitConfirmation = true
2063+
return nil
2064+
}
2065+
// Clear AI history on normal exit
2066+
a.aiPane.ClearHistory()
2067+
return tea.Quit
2068+
}
2069+
20582070
// Handle /help command
20592071
if trimmedMsg == "/help" {
20602072
helpText := "Keyboard Shortcuts\n"
@@ -2090,7 +2102,8 @@ func (a *App) handleAIMessage(message string) tea.Cmd {
20902102
helpText += " /preview Preview changes before applying\n"
20912103
helpText += " /model Show current agent and model info\n"
20922104
helpText += " /config Edit configuration settings\n"
2093-
helpText += " /help Show this help message\n\n"
2105+
helpText += " /help Show this help message\n"
2106+
helpText += " /quit Quit the program\n\n"
20942107
helpText += "Fix Keywords\n"
20952108
helpText += "------------\n"
20962109
helpText += " fix Request code fix\n"

internal/ui/help.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func (a *App) renderHelpDialog() string {
6767
leftColumn += keyStyle.Render(" /model") + descStyle.Render(" Show current agent and model info") + "\n"
6868
leftColumn += keyStyle.Render(" /config") + descStyle.Render(" Edit configuration settings") + "\n"
6969
leftColumn += keyStyle.Render(" /help") + descStyle.Render(" Show this help message") + "\n"
70+
leftColumn += keyStyle.Render(" /quit") + descStyle.Render(" Quit the program") + "\n"
7071

7172
// Right column - Editor shortcuts
7273
var rightColumn string

tests/unit/model_command_test.go

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestModelCommand(t *testing.T) {
5555

5656
t.Run("model command is case insensitive", func(t *testing.T) {
5757
testCases := []string{"/model", "/MODEL", "/Model", " /model "}
58-
58+
5959
for _, cmd := range testCases {
6060
trimmed := strings.TrimSpace(strings.ToLower(cmd))
6161
if trimmed != "/model" {
@@ -69,7 +69,7 @@ func TestModelCommand(t *testing.T) {
6969
func TestHelpCommand(t *testing.T) {
7070
t.Run("help command is case insensitive", func(t *testing.T) {
7171
testCases := []string{"/help", "/HELP", "/Help", " /help "}
72-
72+
7373
for _, cmd := range testCases {
7474
trimmed := strings.TrimSpace(strings.ToLower(cmd))
7575
if trimmed != "/help" {
@@ -88,7 +88,7 @@ func TestHelpCommand(t *testing.T) {
8888
"Agent Commands",
8989
"Fix Keywords",
9090
}
91-
91+
9292
// Expected keyboard shortcuts
9393
expectedShortcuts := []string{
9494
"Ctrl+O",
@@ -97,16 +97,17 @@ func TestHelpCommand(t *testing.T) {
9797
"Ctrl+Q",
9898
"Tab",
9999
}
100-
100+
101101
// Expected agent commands
102102
expectedCommands := []string{
103103
"/fix",
104104
"/ask",
105105
"/preview",
106106
"/model",
107107
"/help",
108+
"/quit",
108109
}
109-
110+
110111
// Expected fix keywords
111112
expectedKeywords := []string{
112113
"fix",
@@ -115,30 +116,54 @@ func TestHelpCommand(t *testing.T) {
115116
"modify",
116117
"correct",
117118
}
118-
119+
119120
// Verify all expected content would be present
120121
for _, section := range expectedSections {
121122
if section == "" {
122123
t.Errorf("Expected section should not be empty")
123124
}
124125
}
125-
126+
126127
for _, shortcut := range expectedShortcuts {
127128
if shortcut == "" {
128129
t.Errorf("Expected shortcut should not be empty")
129130
}
130131
}
131-
132+
132133
for _, cmd := range expectedCommands {
133134
if cmd == "" {
134135
t.Errorf("Expected command should not be empty")
135136
}
136137
}
137-
138+
138139
for _, keyword := range expectedKeywords {
139140
if keyword == "" {
140141
t.Errorf("Expected keyword should not be empty")
141142
}
142143
}
143144
})
144145
}
146+
147+
// TestQuitCommand tests the /quit command functionality
148+
func TestQuitCommand(t *testing.T) {
149+
t.Run("quit command is case insensitive", func(t *testing.T) {
150+
testCases := []string{"/quit", "/QUIT", "/Quit", " /quit "}
151+
152+
for _, cmd := range testCases {
153+
trimmed := strings.TrimSpace(strings.ToLower(cmd))
154+
if trimmed != "/quit" {
155+
t.Errorf("Expected '%s' to normalize to '/quit', got '%s'", cmd, trimmed)
156+
}
157+
}
158+
})
159+
160+
t.Run("quit command should be documented in help", func(t *testing.T) {
161+
// The /quit command should be listed in the help text
162+
// This is verified by the help test above which includes /quit in expectedCommands
163+
config := types.DefaultConfig()
164+
app := ui.New(config, "test")
165+
if app == nil {
166+
t.Fatal("Expected app to be created, got nil")
167+
}
168+
})
169+
}

0 commit comments

Comments
 (0)