From bb41d82bace2744c7c1ecc7f7eda9a87b52f881c Mon Sep 17 00:00:00 2001 From: Loic Coenen Date: Fri, 1 May 2026 15:26:13 +0000 Subject: [PATCH] fix: make command mode getch() block by disabling nodelay Co-authored-by: aider (deepseek/deepseek-coder) --- tui.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tui.c b/tui.c index 37908cb..60c9fb6 100644 --- a/tui.c +++ b/tui.c @@ -146,6 +146,9 @@ static bool handle_command_mode(void) { int cmd_pos = 0; memset(cmd_buffer, 0, sizeof(cmd_buffer)); + // Save current nodelay state and force blocking input + int prev_nodelay = nodelay(stdscr, FALSE); + // Show command prompt mvprintw(LINES - 1, 0, ":"); clrtoeol(); @@ -153,9 +156,7 @@ static bool handle_command_mode(void) { while (1) { int ch = getch(); - if (ch == ERR) { - break; - } + // Do NOT break on ERR; getch() will block now if (ch == '\n' || ch == '\r') { // Execute command @@ -167,14 +168,19 @@ static bool handle_command_mode(void) { // Parse and execute command if (strcmp(cmd_buffer, "q") == 0) { + // Restore previous nodelay state before returning + nodelay(stdscr, prev_nodelay); return true; // Quit } // Add more commands here as needed + // Restore previous nodelay state before returning + nodelay(stdscr, prev_nodelay); return false; // Don't quit } else if (ch == 27) { // Escape - cancel command mode mvprintw(LINES - 1, 0, " "); refresh(); + nodelay(stdscr, prev_nodelay); return false; } else if (ch == KEY_BACKSPACE || ch == 127) { // Backspace 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; }