fix: handle SIGINT to restore terminal raw mode on Ctrl+C
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
17
tui.c
17
tui.c
@@ -2,6 +2,7 @@
|
||||
#include <ncurses.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define GRID_ROWS 8
|
||||
#define GRID_COLS 8
|
||||
@@ -32,6 +33,9 @@ static int state_to_color(ClipState state) {
|
||||
case CLIP_STOPPED: return COLOR_STOPPED;
|
||||
default: return COLOR_EMPTY;
|
||||
}
|
||||
|
||||
// Install signal handler for Ctrl+C
|
||||
signal(SIGINT, handle_sigint);
|
||||
}
|
||||
|
||||
// Get clip index from grid position
|
||||
@@ -138,6 +142,12 @@ static void draw_grid(void) {
|
||||
refresh();
|
||||
}
|
||||
|
||||
static void handle_sigint(int sig) {
|
||||
(void)sig;
|
||||
tui_cleanup();
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
void tui_init(Engine *engine) {
|
||||
g_engine = engine;
|
||||
|
||||
@@ -171,6 +181,10 @@ void tui_run(Engine *engine) {
|
||||
|
||||
while (1) {
|
||||
int ch = getch();
|
||||
if (ch == ERR) {
|
||||
// getch returned error (e.g., signal interrupted)
|
||||
break;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
case 'h':
|
||||
@@ -261,4 +275,7 @@ void tui_cleanup(void) {
|
||||
// Restore terminal settings
|
||||
curs_set(1);
|
||||
endwin();
|
||||
|
||||
// Reset signal handler to default
|
||||
signal(SIGINT, SIG_DFL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user