Skip to content

Commit 31fd8c9

Browse files
improve imports
1 parent 9b64a08 commit 31fd8c9

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,35 @@
1414
import time
1515
import unicodedata
1616

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
2117
from pygments import format
2218
from pygments.lexers import PythonLexer
2319
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
3020

21+
import blessings
22+
23+
import curtsies
3124
from curtsies import FSArray, fmtstr, FmtStr, Termmode
3225
from curtsies.bpythonparse import parse as bpythonparse
3326
from curtsies.bpythonparse import func_for_letter, color_for_letter
3427
from curtsies import fmtfuncs
3528
from curtsies import events
36-
import curtsies
37-
import blessings
3829

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
4240
from bpython.curtsiesfrontend import sitefix; sitefix.monkeypatch_quit()
43-
import bpython.curtsiesfrontend.replpainter as paint
4441
from bpython.curtsiesfrontend.coderunner import CodeRunner, FakeOutput
4542
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
4646

4747
#TODO other autocomplete modes (also fix in other bpython implementations)
4848

@@ -72,24 +72,28 @@
7272

7373
class FakeStdin(object):
7474
"""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):
7676
self.coderunner = coderunner
7777
self.repl = repl
7878
self.has_focus = False # whether FakeStdin receives keypress events
7979
self.current_line = ''
8080
self.cursor_offset = 0
8181
self.old_num_lines = 0
8282
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
8387

8488
def process_event(self, e):
8589
assert self.has_focus
8690
logger.debug('fake input processing event %r', e)
8791
if isinstance(e, events.PasteEvent):
8892
for ee in e.events:
89-
if ee not in rl_char_sequences:
93+
if ee not in self.rl_char_sequences:
9094
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)
9397
elif isinstance(e, events.SigIntEvent):
9498
self.coderunner.sigint_happened_in_main_greenlet = True
9599
self.has_focus = False
@@ -286,7 +290,7 @@ def smarter_request_reload(desc):
286290
self.coderunner = CodeRunner(self.interp, self.request_refresh)
287291
self.stdout = FakeOutput(self.coderunner, self.send_to_stdout)
288292
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)
290294

291295
self.request_paint_to_clear_screen = False # next paint should clear screen
292296
self.last_events = [None] * 50

0 commit comments

Comments
 (0)