Restore terminal mode on exit