diff --git a/main.cpp b/main.cpp index 374ff1a..4282caa 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ // Released under Apache License v2.0 #include #include +#include #include #include #include @@ -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);