Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_send(self):
inp = Input()
inp.unprocessed_bytes = [b'a']
self.assertEqual(inp.send('nonsensical value'), u'a')
def test_send_paste(self):
inp = Input()
inp.unprocessed_bytes = []
inp._wait_for_read_ready_or_timeout = Mock()
inp._wait_for_read_ready_or_timeout.return_value = (True, None)
inp._nonblocking_read = Mock()
n = inp.paste_threshold + 1
first_time = [True]
def side_effect():
if first_time:
inp.unprocessed_bytes.extend([b'a']*n)
first_time.pop()
return n
else:
return None
inp._nonblocking_read.side_effect = side_effect
def test_event_trigger(self):
inp = Input()
f = inp.event_trigger(CustomEvent)
self.assertEqual(inp.send(0), None)
f()
self.assertEqual(type(inp.send(0)), CustomEvent)
self.assertEqual(inp.send(0), None)
def test_schedule_event_trigger(self):
inp = Input()
f = inp.scheduled_event_trigger(CustomScheduledEvent)
self.assertEqual(inp.send(0), None)
f(when=time.time())
self.assertEqual(type(inp.send(0)), CustomScheduledEvent)
self.assertEqual(inp.send(0), None)
f(when=time.time()+0.01)
self.assertEqual(inp.send(0), None)
time.sleep(0.01)
self.assertEqual(type(inp.send(0)), CustomScheduledEvent)
self.assertEqual(inp.send(0), None)
def array_size_test(window):
"""Tests arrays one row to small or too large"""
with window as w:
print('a displays a screen worth of input, s one line less, and d one line more')
with input.Input(sys.stdin) as input_generator:
while True:
c = input_generator.next()
rows, columns = w.height, w.width
if c == "":
sys.exit() # same as raise SystemExit()
elif c == "h":
a = w.array_from_text("a for small array")
elif c == "a":
a = [fmtstr(c*columns) for _ in range(rows)]
elif c == "s":
a = [fmtstr(c*columns) for _ in range(rows-1)]
elif c == "d":
a = [fmtstr(c*columns) for _ in range(rows+1)]
elif c == "f":
a = [fmtstr(c*columns) for _ in range(rows-2)]
elif c == "q":
def fullscreen_winch_with_input():
print('this should be just off-screen')
w = FullscreenWindow(sys.stdout)
def sigwinch_handler(signum, frame):
print('sigwinch! Changed from %r to %r' % ((rows, columns), (w.height, w.width)))
signal.signal(signal.SIGWINCH, sigwinch_handler)
with w:
with Cbreak(sys.stdin):
for e in input.Input():
rows, columns = w.height, w.width
a = [fmtstr((('.%sx%s.%r.' % (rows, columns, e)) * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
def cursor_winch():
global rows, columns # instead of closure for Python 2 compatibility
print('this should be just off-screen')
w = CursorAwareWindow(sys.stdout, sys.stdin, keep_last_line=False, hide_cursor=False)
def sigwinch_handler(signum, frame):
global rows, columns
dy = w.get_cursor_vertical_diff()
old_rows, old_columns = rows, columns
rows, columns = w.height, w.width
print('sigwinch! Changed from %r to %r' % ((old_rows, old_columns), (rows, columns)))
print('cursor moved %d lines down' % dy)
w.write(w.t.move_up)
w.write(w.t.move_up)
signal.signal(signal.SIGWINCH, sigwinch_handler)
with w:
for e in input.Input():
rows, columns = w.height, w.width
a = [fmtstr(((u'.%sx%s.' % (rows, columns)) * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
if e == u'':
break
if __name__ == '__main__':
def handle_input(self):
self.trigger_debug = False
quit_chars = (u'', u'', u'q')
with Input() as input_generator:
input_char = input_generator.send(self.timeout_delay)
if isinstance(input_char, PasteEvent):
input_char = str(input_char)[-1]
if input_char:
self.write_to_manager_logfile('input_char: ' + input_char)
if input_char in quit_chars:
self.quit_autotrace(msg=input_char + ' hit, quitting.')
elif input_char in (u'r',):
self.draw_screen('clearscreen',quick_help=self.get_quick_help())
elif input_char in (u'd',):
self.trigger_debug = True
elif input_char in (u'm',):
self.cycle_panes()
self.draw_screen('sessions',quick_help=self.get_quick_help())
elif input_char in (u'z',):
# Revert layout status from zoomed
def __init__(self, config, locals_, banner, interp=None):
self.input_generator = curtsies.input.Input(
keynames="curtsies", sigint_event=True, paste_threshold=None
)
self.window = curtsies.window.CursorAwareWindow(
sys.stdout,
sys.stdin,
keep_last_line=True,
hide_cursor=False,
extra_bytes_callback=self.input_generator.unget_bytes,
)
self._request_refresh = self.input_generator.event_trigger(
bpythonevents.RefreshRequestEvent
)
self._schedule_refresh = self.input_generator.scheduled_event_trigger(
bpythonevents.ScheduledRefreshRequestEvent
)