Terminal display broken after killing python curses program
I wrote a small program in python and outputted some screen display using the curses library. For my simple output this开发者_Python百科 seems to work. I run my python program from the command line.
My problem is that if I kill the python program the terminal doesn't properly display. For example: 'ls -al' displays properly before I run my python curses program 'ls -al' does not display properly after I kill the python curses program.
What can I do to make my terminal display output properly after I kill my python curses program?
Usually the reset
command will reset your terminal settings to default values.
If you use curses.wrapper, it will handle all the cleanup (and set up) for you. http://docs.python.org/library/curses.html#curses.wrapper
Initialize the curses the following way, it will handle a cleanup.
class curses_screen:
def __enter__(self):
self.stdscr = curses.initscr()
curses.cbreak()
curses.noecho()
self.stdscr.keypad(1)
SCREEN_HEIGHT, SCREEN_WIDTH = self.stdscr.getmaxyx()
return self.stdscr
def __exit__(self,a,b,c):
curses.nocbreak()
self.stdscr.keypad(0)
curses.echo()
curses.endwin()
with curses_screen() as stdscr:
"""
Execution code plush getch code here
"""
Register a signal handler that will uninitialize curses.
I think you should use curses.endwin()
. It restores the terminal window...
In fact if you don't call it after program is closed terminal will show everything like it is in the curses window...
精彩评论