From 941cd141f488122e5d5c8834e5ff47289479aa64 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Tue, 9 Dec 2025 09:49:30 +0000 Subject: [PATCH] Cleanup terminal on ctrl-c --- host/host.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/host/host.c b/host/host.c index 5d306e7..f9f48af 100644 --- a/host/host.c +++ b/host/host.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "uvm32.h" #include "../common/uvm32_common_custom.h" @@ -40,9 +41,15 @@ void disableRawMode(void) { fflush(stdout); } +void cleanexit(int sig) { + disableRawMode(); + exit(0); +} + void enableRawMode(void) { tcgetattr(STDIN_FILENO, &orig_termios); atexit(disableRawMode); + sigset(SIGINT, cleanexit); struct termios raw = orig_termios; raw.c_lflag &= ~(ECHO | ICANON | IEXTEN); raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON); @@ -116,6 +123,7 @@ bool poll_getch(uint8_t* c) { if (len) { if (*c == 0x03 || *c == 0x04) { // ctrl-c ctrl-d + disableRawMode(); exit(0); } if (*c == 0x0d) {