-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathdemo_scrolling.py
33 lines (31 loc) · 1.18 KB
/
demo_scrolling.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
import sys
import signal
from curtsies import CursorAwareWindow, input, fmtstr
rows, columns = '??'
def cursor_winch():
"""
Reports (signals) change in window dimensions; reports change in position
of cursor
"""
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(f'sigwinch! Changed from {(old_rows, old_columns)!r} to {(rows, columns)!r}')
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(((f'.{rows}x{columns}.') * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
if e == '<ESC>':
break
if __name__ == '__main__':
cursor_winch()