Restore state when exiting ncurses