in ebcli/bundled/asciimatics/screen.py [0:0]
def __init__(self, win, height=200, catch_interrupt=False,
unicode_aware=False):
"""
:param win: The window object as returned by the curses wrapper
method.
:param height: The height of the screen buffer to be used.
:param catch_interrupt: Whether to catch SIGINT or not.
:param unicode_aware: Whether this Screen can use unicode or not.
"""
# Determine unicode support if needed.
if unicode_aware is None:
try:
encoding = getlocale()[1]
if not encoding:
encoding = getdefaultlocale()[1]
except ValueError:
encoding = os.environ.get("LC_CTYPE")
unicode_aware = (encoding is not None and
encoding.lower() == "utf-8")
# Save off the screen details.
super(_CursesScreen, self).__init__(
win.getmaxyx()[0], win.getmaxyx()[1], height, unicode_aware)
self._screen = win
self._screen.keypad(1)
# Set up basic colour schemes.
self.colours = curses.COLORS
# Disable the cursor.
curses.curs_set(0)
# Non-blocking key checks.
self._screen.nodelay(1)
# Store previous handlers for restoration at close
self._signal_state = _SignalState()
# Set up signal handler for screen resizing.
self._re_sized = False
self._signal_state.set(signal.SIGWINCH, self._resize_handler)
# Catch SIGINTs and translated them to ctrl-c if needed.
if catch_interrupt:
# Ignore SIGINT (ctrl-c) and SIGTSTP (ctrl-z) signals.
self._signal_state.set(signal.SIGINT, self._catch_interrupt)
self._signal_state.set(signal.SIGTSTP, self._catch_interrupt)
# Enable mouse events
curses.mousemask(curses.ALL_MOUSE_EVENTS |
curses.REPORT_MOUSE_POSITION)
# Lookup the necessary escape codes in the terminfo database.
self._move_y_x = curses.tigetstr("cup")
self._up_line = curses.tigetstr("ri").decode("utf-8")
self._down_line = curses.tigetstr("ind").decode("utf-8")
self._fg_color = curses.tigetstr("setaf")
self._bg_color = curses.tigetstr("setab")
self._clear_line = curses.tigetstr("el").decode("utf-8")
if curses.tigetflag("hs"):
self._start_title = curses.tigetstr("tsl").decode("utf-8")
self._end_title = curses.tigetstr("fsl").decode("utf-8")
else:
self._start_title = self._end_title = None
self._a_normal = curses.tigetstr("sgr0").decode("utf-8")
self._a_bold = curses.tigetstr("bold").decode("utf-8")
self._a_reverse = curses.tigetstr("rev").decode("utf-8")
self._a_underline = curses.tigetstr("smul").decode("utf-8")
self._clear_screen = curses.tigetstr("clear").decode("utf-8")
# Look for a mismatch between the kernel terminal and the terminfo
# database for backspace. Fix up keyboard mappings if needed.
kbs = curses.tigetstr("kbs").decode("utf-8")
tbs = termios.tcgetattr(sys.stdin)[6][termios.VERASE]
if tbs != kbs:
self._KEY_MAP[ord(tbs)] = Screen.KEY_BACK
# Conversion from Screen attributes to curses equivalents.
self._ATTRIBUTES = {
Screen.A_BOLD: self._a_bold,
Screen.A_NORMAL: self._a_normal,
Screen.A_REVERSE: self._a_reverse,
Screen.A_UNDERLINE: self._a_underline
}
# Byte stream processing for unicode input.
self._bytes_to_read = 0
self._bytes_to_return = b""
# We'll actually break out into low-level output, so flush any
# high level buffers now.
self._screen.refresh()