resetting terminal on exit

With some terminals the terminal is not reset correctly when exiting with ctl-c. added a signal handler to catch program exits and restore previous terminal settings.