squirrel-battle/dungeonbattle/term_manager.py
Yohann D'ANELLO bec53dbf1e Linting...
2020-10-09 17:04:50 +02:00

28 lines
796 B
Python

import curses
from types import TracebackType
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
def __exit__(self, exc_type: type, exc_value: Exception,
exc_traceback: TracebackType) -> None:
# restore the terminal to its original state
self.screen.keypad(False)
curses.echo()
curses.nocbreak()
curses.curs_set(True)
curses.endwin()