reset terminal after ctrl+c

This commit is contained in:
folkert van heusden 2022-03-16 19:29:25 +01:00
parent 4f21efdf57
commit 7106c83d5d

View file

@ -2,6 +2,7 @@
// Released under Apache License v2.0
#include <poll.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
@ -14,6 +15,13 @@
#include "terminal.h"
#include "error.h"
struct termios org_tty_opts { 0 };
void reset_terminal()
{
tcsetattr(STDIN_FILENO, TCSANOW, &org_tty_opts);
}
void loadbin(bus *const b, uint16_t base, const char *const file)
{
FILE *fh = fopen(file, "rb");
@ -287,6 +295,10 @@ int main(int argc, char *argv[])
resize_terminal();
}
atexit(reset_terminal);
tcgetattr(STDIN_FILENO, &org_tty_opts);
struct termios tty_opts_raw { 0 };
cfmakeraw(&tty_opts_raw);
tcsetattr(STDIN_FILENO, TCSANOW, &tty_opts_raw);