feat: add command mode with :q quit support and tests

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 15:23:00 +00:00
parent 68ec0abb99
commit efe51944a1
3 changed files with 194 additions and 0 deletions

63
tui.c
View File

@@ -139,6 +139,61 @@ static void draw_grid(void) {
refresh();
}
// Handle command mode input (after pressing ':')
// Returns true if the application should quit
static bool handle_command_mode(void) {
char cmd_buffer[256];
int cmd_pos = 0;
memset(cmd_buffer, 0, sizeof(cmd_buffer));
// Show command prompt
mvprintw(LINES - 1, 0, ":");
clrtoeol();
refresh();
while (1) {
int ch = getch();
if (ch == ERR) {
break;
}
if (ch == '\n' || ch == '\r') {
// Execute command
cmd_buffer[cmd_pos] = '\0';
// Clear command line
mvprintw(LINES - 1, 0, " ");
refresh();
// Parse and execute command
if (strcmp(cmd_buffer, "q") == 0) {
return true; // Quit
}
// Add more commands here as needed
return false; // Don't quit
} else if (ch == 27) { // Escape - cancel command mode
mvprintw(LINES - 1, 0, " ");
refresh();
return false;
} else if (ch == KEY_BACKSPACE || ch == 127) { // Backspace
if (cmd_pos > 0) {
cmd_pos--;
cmd_buffer[cmd_pos] = '\0';
mvprintw(LINES - 1, 0, ":%s ", cmd_buffer);
refresh();
}
} else if (cmd_pos < (int)sizeof(cmd_buffer) - 1) {
cmd_buffer[cmd_pos++] = (char)ch;
cmd_buffer[cmd_pos] = '\0';
mvprintw(LINES - 1, 0, ":%s", cmd_buffer);
refresh();
}
}
return false;
}
static void handle_sigint(int sig) {
(void)sig;
tui_cleanup();
@@ -252,6 +307,14 @@ void tui_run(Engine *engine) {
engine_reset_transport(engine);
break;
case ':': {
bool should_quit = handle_command_mode();
if (should_quit) {
return;
}
break;
}
case '?':
show_help = !show_help;
break;