from fmtstr.terminal import Terminal
from fmtstr.terminalcontrol import TerminalController

from bpython.scrollfrontend.repl import Repl

def main():
    with TerminalController() as tc:
        with Terminal(tc, keep_last_line=True, hide_cursor=False) as term:
            with Repl() as repl:
                rows, columns = tc.get_screen_size()
                repl.width = columns
                repl.height = rows
                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__':
    main()

@@ -131,16 +131,136 @@
 t Repl%0A%0A
+import sys%0Aif '-v' in sys.argv:%0A    import logging%0A    logging.basicConfig(filename='scroll.log', level=logging.DEBUG)%0A%0A
 def main

add command line flag for logging