forked from bpython/curtsies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_scrolling.py
27 lines (25 loc) · 1004 Bytes
/
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
import sys
import signal
from curtsies import CursorAwareWindow, input, fmtstr
rows, columns = '??'
def cursor_winch():
global rows, columns
print('this should be just off-screen')
w = CursorAwareWindow(sys.stdout, sys.stdin, keep_last_line=True, 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((('.%sx%s.' % (rows, columns)) * rows)[:columns]) for row in range(rows)]
w.render_to_terminal(a)
if __name__ == '__main__':
cursor_winch()