in ebcli/bundled/asciimatics/screen.py [0:0]
def get_event(self):
"""
Check for an event without waiting.
"""
# Spin through notifications until we find something we want.
key = 0
while key != -1:
# Get the next key
key = self._screen.getch()
if key == curses.KEY_RESIZE:
# Handle screen resize
self._re_sized = True
elif key == curses.KEY_MOUSE:
# Handle a mouse event
_, x, y, _, bstate = curses.getmouse()
buttons = 0
# Some Linux modes only report clicks, so check for any
# button down or click events.
if (bstate & curses.BUTTON1_PRESSED != 0 or
bstate & curses.BUTTON1_CLICKED != 0):
buttons |= MouseEvent.LEFT_CLICK
if (bstate & curses.BUTTON3_PRESSED != 0 or
bstate & curses.BUTTON3_CLICKED != 0):
buttons |= MouseEvent.RIGHT_CLICK
if bstate & curses.BUTTON1_DOUBLE_CLICKED != 0:
buttons |= MouseEvent.DOUBLE_CLICK
return MouseEvent(x, y, buttons)
elif key != -1:
# Handle any byte streams first
logger.debug("Processing key: %x", key)
if self._unicode_aware and key > 0:
if key & 0xC0 == 0xC0:
self._bytes_to_return = struct.pack(b"B", key)
self._bytes_to_read = bin(key)[2:].index("0") - 1
logger.debug("Byte stream: %d bytes left",
self._bytes_to_read)
continue
elif self._bytes_to_read > 0:
self._bytes_to_return += struct.pack(b"B", key)
self._bytes_to_read -= 1
if self._bytes_to_read > 0:
continue
else:
key = ord(self._bytes_to_return.decode("utf-8"))
# Handle a genuine key press.
logger.debug("Returning key: %x", key)
if key in self._KEY_MAP:
return KeyboardEvent(self._KEY_MAP[key])
elif key != -1:
return KeyboardEvent(key)
return None