|
3 | 3 | import sys |
4 | 4 | import code |
5 | 5 | import logging |
6 | | -import select |
7 | 6 | from subprocess import Popen, PIPE |
8 | 7 | from optparse import Option |
9 | 8 | from itertools import izip |
| 9 | +from functools import wraps |
10 | 10 |
|
11 | 11 | import curtsies |
12 | 12 | import curtsies.window |
|
19 | 19 | from bpython.translations import _ |
20 | 20 | from bpython.importcompletion import find_iterator |
21 | 21 |
|
| 22 | +import wdtest |
| 23 | + |
22 | 24 | repl = None # global for `from bpython.curtsies import repl` |
23 | 25 | #WARNING Will be a problem if more than one repl is ever instantiated this way |
24 | 26 |
|
@@ -73,28 +75,38 @@ def mainloop(config, locals_, banner, interp=None, paste=None, interactive=True) |
73 | 75 | hide_cursor=False, |
74 | 76 | extra_bytes_callback=input_generator.unget_bytes) as window: |
75 | 77 |
|
76 | | - p = Popen(['python', '-m', 'bpython.curtsiesfrontend.beeper'], stdout=PIPE) |
77 | | - |
| 78 | + reload_requests = [] |
| 79 | + def request_reload(): |
| 80 | + reload_requests.append('reload!') |
78 | 81 | refresh_requests = [] |
79 | 82 | def request_refresh(): |
80 | 83 | refresh_requests.append(curtsies.events.RefreshRequestEvent()) |
| 84 | + |
| 85 | + watcher = wdtest.ModuleChangedEventHandler([], request_reload) |
| 86 | + |
| 87 | + orig_import = __builtins__['__import__'] |
| 88 | + @wraps(orig_import) |
| 89 | + def new_import(name, globals={}, locals={}, fromlist=[], level=-1): |
| 90 | + m = orig_import(name, globals=globals, locals=locals, fromlist=fromlist) |
| 91 | + watcher.add_module(m.__file__) |
| 92 | + return m |
| 93 | + __builtins__['__import__'] = new_import |
| 94 | + |
81 | 95 | def event_or_refresh(timeout=None): |
82 | 96 | while True: |
83 | 97 | if refresh_requests: |
84 | 98 | yield refresh_requests.pop() |
85 | 99 | else: |
86 | | - try: |
87 | | - rs, ws, es = select.select([input_generator, p.stdout], [], []) |
88 | | - except select.error as e: |
89 | | - print e |
90 | | - yield curtsies.events.SigIntEvent() |
91 | | - else: |
92 | | - for r in rs: |
93 | | - if r is input_generator: |
94 | | - yield input_generator.send(timeout) |
95 | | - else: |
96 | | - p.stdout.readline() |
97 | | - yield u'a' |
| 100 | + while True: |
| 101 | + if reload_requests: |
| 102 | + del reload_requests[:] |
| 103 | + e = '<F6>' |
| 104 | + print 'asdf' |
| 105 | + else: |
| 106 | + e = input_generator.send(.2) |
| 107 | + if e is not None: |
| 108 | + break |
| 109 | + yield e |
98 | 110 |
|
99 | 111 | global repl # global for easy introspection `from bpython.curtsies import repl` |
100 | 112 | with Repl(config=config, |
|
0 commit comments