fix: make command mode getch() block by disabling nodelay

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-01 15:26:13 +00:00
parent d416a30944
commit bb41d82bac

14
tui.c
View File

@@ -146,6 +146,9 @@ static bool handle_command_mode(void) {
int cmd_pos = 0; int cmd_pos = 0;
memset(cmd_buffer, 0, sizeof(cmd_buffer)); memset(cmd_buffer, 0, sizeof(cmd_buffer));
// Save current nodelay state and force blocking input
int prev_nodelay = nodelay(stdscr, FALSE);
// Show command prompt // Show command prompt
mvprintw(LINES - 1, 0, ":"); mvprintw(LINES - 1, 0, ":");
clrtoeol(); clrtoeol();
@@ -153,9 +156,7 @@ static bool handle_command_mode(void) {
while (1) { while (1) {
int ch = getch(); int ch = getch();
if (ch == ERR) { // Do NOT break on ERR; getch() will block now
break;
}
if (ch == '\n' || ch == '\r') { if (ch == '\n' || ch == '\r') {
// Execute command // Execute command
@@ -167,14 +168,19 @@ static bool handle_command_mode(void) {
// Parse and execute command // Parse and execute command
if (strcmp(cmd_buffer, "q") == 0) { if (strcmp(cmd_buffer, "q") == 0) {
// Restore previous nodelay state before returning
nodelay(stdscr, prev_nodelay);
return true; // Quit return true; // Quit
} }
// Add more commands here as needed // Add more commands here as needed
// Restore previous nodelay state before returning
nodelay(stdscr, prev_nodelay);
return false; // Don't quit return false; // Don't quit
} else if (ch == 27) { // Escape - cancel command mode } else if (ch == 27) { // Escape - cancel command mode
mvprintw(LINES - 1, 0, " "); mvprintw(LINES - 1, 0, " ");
refresh(); refresh();
nodelay(stdscr, prev_nodelay);
return false; return false;
} else if (ch == KEY_BACKSPACE || ch == 127) { // Backspace } else if (ch == KEY_BACKSPACE || ch == 127) { // Backspace
if (cmd_pos > 0) { if (cmd_pos > 0) {
@@ -191,6 +197,8 @@ static bool handle_command_mode(void) {
} }
} }
// Should never reach here, but restore just in case
nodelay(stdscr, prev_nodelay);
return false; return false;
} }