|
6 | 6 |
|
7 | 7 | import curtsies |
8 | 8 | import curtsies.window |
| 9 | +import curtsies.input |
9 | 10 | import curtsies.terminal |
10 | 11 | import curtsies.events |
11 | | -Window = curtsies.window.Window |
12 | | -Terminal = curtsies.terminal.Terminal |
13 | 12 |
|
14 | 13 | from bpython.curtsiesfrontend.repl import Repl |
15 | 14 | from bpython.curtsiesfrontend.coderunner import SystemExitFromCodeGreenlet |
@@ -52,36 +51,50 @@ def main(args=None, locals_=None, banner=None): |
52 | 51 | mainloop(config, locals_, banner, interp, paste) |
53 | 52 |
|
54 | 53 | def mainloop(config, locals_, banner, interp=None, paste=None): |
55 | | - with Terminal(paste_mode=True) as tc: |
56 | | - with Window(tc, keep_last_line=True, hide_cursor=False) as term: |
| 54 | + with curtsies.input.Input(keynames='curses') as input_generator: |
| 55 | + with curtsies.window.CursorAwareWindow( |
| 56 | + sys.stdout, |
| 57 | + sys.stdin, |
| 58 | + keep_last_line=True, |
| 59 | + hide_cursor=False) as window: |
| 60 | + |
| 61 | + refresh_requests = [] |
| 62 | + def request_refresh(): |
| 63 | + refresh_requests.append(None) |
| 64 | + def event_or_refresh(): |
| 65 | + while True: |
| 66 | + if refresh_requests: |
| 67 | + refresh_requests.pop() |
| 68 | + yield curtsies.events.RefreshRequestEvent() |
| 69 | + else: |
| 70 | + yield input_generator.next() |
| 71 | + |
57 | 72 | with Repl(config=config, |
58 | 73 | locals_=locals_, |
59 | | - request_refresh=tc.stuff_a_refresh_request, |
| 74 | + request_refresh=request_refresh, |
60 | 75 | banner=banner, |
61 | 76 | interp=interp) as repl: |
62 | | - rows, columns = tc.get_screen_size() |
63 | | - repl.width = columns |
64 | | - repl.height = rows |
| 77 | + repl.height, repl.width = window.t.height, window.t.width |
65 | 78 |
|
66 | 79 | def process_event(e): |
67 | 80 | try: |
68 | 81 | repl.process_event(e) |
69 | 82 | except (SystemExitFromCodeGreenlet, SystemExit) as err: |
70 | 83 | array, cursor_pos = repl.paint(about_to_exit=True, user_quit=isinstance(err, SystemExitFromCodeGreenlet)) |
71 | | - scrolled = term.render_to_terminal(array, cursor_pos) |
| 84 | + scrolled = window.render_to_terminal(array, cursor_pos) |
72 | 85 | repl.scroll_offset += scrolled |
73 | 86 | raise |
74 | 87 | else: |
75 | 88 | array, cursor_pos = repl.paint() |
76 | | - scrolled = term.render_to_terminal(array, cursor_pos) |
| 89 | + scrolled = window.render_to_terminal(array, cursor_pos) |
77 | 90 | repl.scroll_offset += scrolled |
78 | 91 |
|
79 | 92 | if paste: |
80 | | - repl.process_event(term.get_annotated_event()) #first event will always be a window size set |
81 | 93 | process_event(paste) |
82 | 94 |
|
83 | | - while True: |
84 | | - process_event(term.get_annotated_event(idle=find_iterator)) |
| 95 | + [None for _ in find_iterator] #TODO get idle events working (instead of this) |
| 96 | + for e in event_or_refresh(): |
| 97 | + process_event(e) |
85 | 98 |
|
86 | 99 | if __name__ == '__main__': |
87 | 100 | sys.exit(main()) |
0 commit comments