-
-
Notifications
You must be signed in to change notification settings - Fork 252
Expand file tree
/
Copy pathscroll.py
More file actions
57 lines (48 loc) · 2.28 KB
/
scroll.py
File metadata and controls
57 lines (48 loc) · 2.28 KB
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
51
52
53
54
55
56
57
import sys
from fmtstr.terminal import Terminal
from fmtstr.terminalcontrol import TerminalController
from bpython.scrollfrontend.repl import Repl
import bpython.args
if '-v' in sys.argv:
import logging
logging.basicConfig(filename='scroll.log', level=logging.DEBUG)
sys.argv.remove('-v')
def cli():
config, options, exec_args = bpython.args.parse(sys.argv[1:])
return main(config=config, options=options, exec_args=exec_args)
def main(locals_=None, config=None, exec_args=None, options=None):
#TODO this is gross - passing in args and options means you can't
# easily have that functionality without running it frmo the command line,
# but it makes reusing bpython code easier
with TerminalController() as tc:
with Terminal(tc, keep_last_line=True, hide_cursor=False) as term:
with Repl(config=config, locals_=locals_) as repl:
rows, columns = tc.get_screen_size()
repl.width = columns
repl.height = rows
exit_value = 0
if exec_args:
assert options, "don't pass in exec_args without options"
try:
#TODO replace this so that stdout is properly harvested for display!
bpython.args.exec_code(repl.interp, exec_args)
except SystemExit:
pass
if not options.interactive:
#TODO treat this properly: no prompt should ever display, but stdout should!
array, cursor_pos = repl.paint(about_to_exit=True)
term.render_to_terminal(array, cursor_pos)
raise SystemExit(exit_value)
while True:
try:
repl.process_event(tc.get_event())
except SystemExit:
array, cursor_pos = repl.paint(about_to_exit=True)
term.render_to_terminal(array, cursor_pos)
raise
else:
array, cursor_pos = repl.paint()
scrolled = term.render_to_terminal(array, cursor_pos)
repl.scroll_offset += scrolled
if __name__ == '__main__':
cli()