diff --git a/nmap.cc b/nmap.cc index 4f3a922a3..d475724ed 100644 --- a/nmap.cc +++ b/nmap.cc @@ -1899,8 +1899,7 @@ int nmap_main(int argc, char *argv[]) { else nbase_set_log(fatal, NULL); - - tty_init(); // Put the keyboard in raw mode + TTYState ttystate; // Put the keyboard in raw mode #ifdef WIN32 // Must come after parse_options because of --unprivileged diff --git a/nmap_tty.cc b/nmap_tty.cc index 319dafd3c..50cc3ca45 100644 --- a/nmap_tty.cc +++ b/nmap_tty.cc @@ -246,6 +246,10 @@ void tty_init() #endif //!win32 +TTYState::~TTYState() { + tty_done(); +} + /* Catches all of the predefined keypresses and interpret them, and it will also tell you if you should print anything. A value of true being returned means a diff --git a/nmap_tty.h b/nmap_tty.h index c255db5df..3acab00bf 100644 --- a/nmap_tty.h +++ b/nmap_tty.h @@ -74,4 +74,11 @@ void tty_init(); calling method should print a status message */ bool keyWasPressed(); +/* RAII object for TTY management */ +class TTYState { + public: + TTYState() { tty_init(); } + ~TTYState(); // calls tty_done() +}; + #endif