Context manager for wrapping the use of a curses terminal
This commit is contained in:
parent
07f2e4266a
commit
c161f924e9
25
dungeonbattle/TermManager.py
Normal file
25
dungeonbattle/TermManager.py
Normal file
@ -0,0 +1,25 @@
|
||||
import curses
|
||||
|
||||
class TermManager():
|
||||
|
||||
def __init__(self):
|
||||
self.screen = curses.initscr()
|
||||
# convert escapes sequences to curses abstraction
|
||||
self.screen.keypad(True)
|
||||
# stop printing typed keys to the terminal
|
||||
curses.noecho()
|
||||
# send keys through without having to press <enter>
|
||||
curses.cbreak()
|
||||
# make cursor invisible
|
||||
curses.curs_set(False)
|
||||
|
||||
def __enter__(self):
|
||||
return self.screen
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
# restore the terminal to its original state
|
||||
self.screen.keypad(False)
|
||||
curses.echo()
|
||||
curses.nocbreak()
|
||||
curses.curs_set(True)
|
||||
curses.endwin()
|
Loading…
Reference in New Issue
Block a user