ladaghini
ladaghini

Reputation: 978

In python, how can I prevent the "^C" from showing up when I press Ctrl+C in the terminal?

I have a signal handler which does its job, but the only ugly thing is whenever Ctrl+C is pressed, a "^C" shows up in the terminal. How do I get rid of that? Or is that a shell behavior?

Upvotes: 1

Views: 195

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 601669

If you are on a Unix platform, the easiest way to control the terminal is the curses module. You can turn the echoing of typed characters off with curses.noecho(), turn it on again with curses.echo(), or wrap a function call in curses.wrapper() to turn echoing off during the function call. The latter is the preferred approach -- it will automatically restore the terminal state if an exception occurs.

Upvotes: 1

Related Questions