forked from bpython/curtsies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_window.py
51 lines (46 loc) · 2.06 KB
/
demo_window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from __future__ import unicode_literals
import sys
import signal
import logging
from curtsies import input, fmtstr, events, FullscreenWindow, CursorAwareWindow
from curtsies import events
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":
a = [fmtstr(c*columns) for _ in range(1)]
elif c == "w":
a = [fmtstr(c*columns) for _ in range(1)]
elif c == "e":
a = [fmtstr(c*columns) for _ in range(1)]
elif c == "c":
w.write(w.t.move(w.t.height-1, 0))
w.scroll_down()
elif isinstance(c, events.WindowChangeEvent):
a = w.array_from_text("window just changed to %d rows and %d columns" % (c.rows, c.columns))
elif c == '\x0c': # ctrl-L
[w.write('\n') for _ in range(rows)]
continue
else:
a = w.array_from_text("unknown command")
w.render_to_terminal(a)
if __name__ == '__main__':
logging.basicConfig(filename='display.log',level=logging.DEBUG)
array_size_test(FullscreenWindow(sys.stdout))