1+ import sys
2+
13from fmtstr .terminal import Terminal
24from fmtstr .terminalcontrol import TerminalController
35
46from bpython .scrollfrontend .repl import Repl
7+ import bpython .args
58
6- import sys
79if '-v' in sys .argv :
810 import logging
911 logging .basicConfig (filename = 'scroll.log' , level = logging .DEBUG )
12+ sys .argv .remove ('-v' )
13+
14+ def cli ():
15+ config , options , exec_args = bpython .args .parse (sys .argv [1 :])
16+ return main (config = config , options = options , exec_args = exec_args )
17+
18+ def main (locals_ = None , config = None , exec_args = None , options = None ):
19+ #TODO this is gross - passing in args and options means you can't
20+ # easily have that functionality without running it frmo the command line,
21+ # but it makes reusing bpython code easier
1022
11- def main ():
1223 with TerminalController () as tc :
1324 with Terminal (tc , keep_last_line = True , hide_cursor = False ) as term :
14- with Repl () as repl :
25+ with Repl (config = config , locals_ = locals_ ) as repl :
1526 rows , columns = tc .get_screen_size ()
1627 repl .width = columns
1728 repl .height = rows
29+
30+ exit_value = 0
31+ if exec_args :
32+ assert options , "don't pass in exec_args without options"
33+ try :
34+ #TODO replace this so that stdout is properly harvested for display!
35+ bpython .args .exec_code (repl .interp , exec_args )
36+ except SystemExit :
37+ pass
38+ if not options .interactive :
39+ #TODO treat this properly: no prompt should ever display, but stdout should!
40+ array , cursor_pos = repl .paint (about_to_exit = True )
41+ term .render_to_terminal (array , cursor_pos )
42+ raise SystemExit (exit_value )
43+
1844 while True :
1945 try :
2046 repl .process_event (tc .get_event ())
@@ -28,4 +54,4 @@ def main():
2854 repl .scroll_offset += scrolled
2955
3056if __name__ == '__main__' :
31- main ()
57+ cli ()
0 commit comments