()
| 1280 | # before starting it). |
| 1281 | |
| 1282 | def run_with_screen_before_mainloop(): |
| 1283 | try: |
| 1284 | # Currently we just set this to None because I do not |
| 1285 | # expect code hitting stdin to work. For example: exit() |
| 1286 | # (not sys.exit, site.py's exit) tries to close sys.stdin, |
| 1287 | # which breaks urwid's shutdown. bpython.cli sets this to |
| 1288 | # a fake object that reads input through curses and |
| 1289 | # returns it. When using twisted I do not think we can do |
| 1290 | # that because sys.stdin.read and friends block, and we |
| 1291 | # cannot re-enter the reactor. If using urwid's own |
| 1292 | # mainloop we *might* be able to do something similar and |
| 1293 | # re-enter its mainloop. |
| 1294 | sys.stdin = None # FakeStdin(myrepl) |
| 1295 | sys.stdout = myrepl |
| 1296 | sys.stderr = myrepl |
| 1297 | |
| 1298 | myrepl.main_loop.set_alarm_in(0, start) |
| 1299 | |
| 1300 | while True: |
| 1301 | try: |
| 1302 | myrepl.main_loop.run() |
| 1303 | except KeyboardInterrupt: |
| 1304 | # HACK: if we run under a twisted mainloop this should |
| 1305 | # never happen: we have a SIGINT handler set. |
| 1306 | # If we use the urwid select-based loop we just restart |
| 1307 | # that loop if interrupted, instead of trying to cook |
| 1308 | # up an equivalent to reactor.callFromThread (which |
| 1309 | # is what our Twisted sigint handler does) |
| 1310 | myrepl.main_loop.set_alarm_in( |
| 1311 | 0, lambda *args: myrepl.keyboard_interrupt() |
| 1312 | ) |
| 1313 | continue |
| 1314 | break |
| 1315 | |
| 1316 | finally: |
| 1317 | sys.stdin = orig_stdin |
| 1318 | sys.stderr = orig_stderr |
| 1319 | sys.stdout = orig_stdout |
| 1320 | |
| 1321 | # This needs more thought. What needs to happen inside the mainloop? |
| 1322 | def start(main_loop, user_data): |
nothing calls this directly
no test coverage detected