|
14 | 14 | import time |
15 | 15 | import unicodedata |
16 | 16 |
|
17 | | -from bpython import autocomplete |
18 | | -from bpython.repl import Repl as BpythonRepl |
19 | | -from bpython.config import Struct, loadini, default_config_path |
20 | | -from bpython.formatter import BPythonFormatter |
21 | 17 | from pygments import format |
22 | 18 | from pygments.lexers import PythonLexer |
23 | 19 | from pygments.formatters import TerminalFormatter |
24 | | -from bpython import importcompletion |
25 | | -from bpython import translations |
26 | | -translations.init() |
27 | | -from bpython.translations import _ |
28 | | -from bpython._py3compat import py3 |
29 | | -import bpython |
30 | 20 |
|
| 21 | +import blessings |
| 22 | + |
| 23 | +import curtsies |
31 | 24 | from curtsies import FSArray, fmtstr, FmtStr, Termmode |
32 | 25 | from curtsies.bpythonparse import parse as bpythonparse |
33 | 26 | from curtsies.bpythonparse import func_for_letter, color_for_letter |
34 | 27 | from curtsies import fmtfuncs |
35 | 28 | from curtsies import events |
36 | | -import curtsies |
37 | | -import blessings |
38 | 29 |
|
39 | | -from bpython.curtsiesfrontend.manual_readline import char_sequences as rl_char_sequences |
40 | | -from bpython.curtsiesfrontend.manual_readline import get_updated_char_sequences |
41 | | -from bpython.curtsiesfrontend.interaction import StatusBar |
| 30 | +import bpython |
| 31 | +from bpython.repl import Repl as BpythonRepl |
| 32 | +from bpython.config import Struct, loadini, default_config_path |
| 33 | +from bpython.formatter import BPythonFormatter |
| 34 | +from bpython import autocomplete, importcompletion |
| 35 | +from bpython import translations; translations.init() |
| 36 | +from bpython.translations import _ |
| 37 | +from bpython._py3compat import py3 |
| 38 | + |
| 39 | +from bpython.curtsiesfrontend import replpainter as paint |
42 | 40 | from bpython.curtsiesfrontend import sitefix; sitefix.monkeypatch_quit() |
43 | | -import bpython.curtsiesfrontend.replpainter as paint |
44 | 41 | from bpython.curtsiesfrontend.coderunner import CodeRunner, FakeOutput |
45 | 42 | from bpython.curtsiesfrontend.filewatch import ModuleChangedEventHandler |
| 43 | +from bpython.curtsiesfrontend.interaction import StatusBar |
| 44 | +from bpython.curtsiesfrontend.manual_readline import char_sequences as rl_char_sequences |
| 45 | +from bpython.curtsiesfrontend.manual_readline import get_updated_char_sequences |
46 | 46 |
|
47 | 47 | #TODO other autocomplete modes (also fix in other bpython implementations) |
48 | 48 |
|
|
72 | 72 |
|
73 | 73 | class FakeStdin(object): |
74 | 74 | """Stdin object user code references so sys.stdin.read() asked user for interactive input""" |
75 | | - def __init__(self, coderunner, repl): |
| 75 | + def __init__(self, coderunner, repl, updated_rl_char_sequences=None): |
76 | 76 | self.coderunner = coderunner |
77 | 77 | self.repl = repl |
78 | 78 | self.has_focus = False # whether FakeStdin receives keypress events |
79 | 79 | self.current_line = '' |
80 | 80 | self.cursor_offset = 0 |
81 | 81 | self.old_num_lines = 0 |
82 | 82 | self.readline_results = [] |
| 83 | + if updated_rl_char_sequences: |
| 84 | + self.rl_char_sequences = updated_rl_char_sequences |
| 85 | + else: |
| 86 | + self.rl_char_sequences = rl_char_sequences |
83 | 87 |
|
84 | 88 | def process_event(self, e): |
85 | 89 | assert self.has_focus |
86 | 90 | logger.debug('fake input processing event %r', e) |
87 | 91 | if isinstance(e, events.PasteEvent): |
88 | 92 | for ee in e.events: |
89 | | - if ee not in rl_char_sequences: |
| 93 | + if ee not in self.rl_char_sequences: |
90 | 94 | self.add_input_character(ee) |
91 | | - elif e in rl_char_sequences: |
92 | | - self.cursor_offset, self.current_line = rl_char_sequences[e](self.cursor_offset, self.current_line) |
| 95 | + elif e in self.rl_char_sequences: |
| 96 | + self.cursor_offset, self.current_line = self.rl_char_sequences[e](self.cursor_offset, self.current_line) |
93 | 97 | elif isinstance(e, events.SigIntEvent): |
94 | 98 | self.coderunner.sigint_happened_in_main_greenlet = True |
95 | 99 | self.has_focus = False |
@@ -286,7 +290,7 @@ def smarter_request_reload(desc): |
286 | 290 | self.coderunner = CodeRunner(self.interp, self.request_refresh) |
287 | 291 | self.stdout = FakeOutput(self.coderunner, self.send_to_stdout) |
288 | 292 | self.stderr = FakeOutput(self.coderunner, self.send_to_stderr) |
289 | | - self.stdin = FakeStdin(self.coderunner, self) |
| 293 | + self.stdin = FakeStdin(self.coderunner, self, self.rl_char_sequences) |
290 | 294 |
|
291 | 295 | self.request_paint_to_clear_screen = False # next paint should clear screen |
292 | 296 | self.last_events = [None] * 50 |
|
0 commit comments