@@ -116,18 +116,21 @@ class BPythonEdit(urwid.Edit):
116
116
117
117
"""Customized editor *very* tightly interwoven with URWIDRepl."""
118
118
119
- def __init__ (self , myrepl , * args , ** kwargs ):
120
- self .repl = myrepl
119
+ def __init__ (self , * args , ** kwargs ):
121
120
self ._bpy_text = ''
122
121
self ._bpy_attr = []
123
122
self ._bpy_selectable = True
124
123
urwid .Edit .__init__ (self , * args , ** kwargs )
125
- urwid .connect_signal (self , 'change' , self .on_input_change )
126
124
127
- def on_input_change (self , edit , text ):
128
- tokens = self .repl .tokenize (text , False )
129
- markup = list (format_tokens (tokens ))
125
+ def set_edit_markup (self , markup ):
126
+ """Call this when markup changes but the underlying text does not.
127
+
128
+ You should arrange for this to be called from the 'change' signal.
129
+ """
130
130
self ._bpy_text , self ._bpy_attr = urwid .decompose_tagmarkup (markup )
131
+ # This is redundant when we're called off the 'change' signal.
132
+ # I'm assuming this is cheap, making that ok.
133
+ self ._invalidate ()
131
134
132
135
def get_text (self ):
133
136
return self ._caption + self ._bpy_text , self ._attrib + self ._bpy_attr
@@ -187,6 +190,7 @@ def __init__(self, main_loop, listbox, listwalker, tooltiptext,
187
190
self .listbox = listbox
188
191
self .listwalker = listwalker
189
192
self .tooltiptext = tooltiptext
193
+ self .edits = []
190
194
self .edit = None
191
195
self .statusbar = statusbar
192
196
# XXX repl.Repl uses this? What is it?
@@ -251,10 +255,8 @@ def _populate_completion(self, main_loop, user_data):
251
255
self .tooltiptext .set_text ('NOPE' )
252
256
253
257
def reprint_line (self , lineno , tokens ):
254
- # repl calls this.
255
- # Trundle says it is responsible for paren unhighlighting.
256
- # So who cares!
257
- pass
258
+ edit = self .edits [- len (self .buffer ) + lineno - 1 ]
259
+ edit .set_edit_markup (list (format_tokens (tokens )))
258
260
259
261
def push (self , s , insert_into_history = True ):
260
262
# Pretty blindly adapted from bpython.cli
@@ -271,17 +273,20 @@ def start(self):
271
273
def prompt (self , more ):
272
274
# XXX what is s_hist?
273
275
if not more :
274
- self .edit = BPythonEdit (self , caption = ('prompt' , '>>> ' ))
276
+ self .edit = BPythonEdit (caption = ('prompt' , '>>> ' ))
275
277
self .stdout_hist += '>>> '
276
278
else :
277
- self .edit = BPythonEdit (self , caption = ('prompt_more' , '... ' ))
279
+ self .edit = BPythonEdit (caption = ('prompt_more' , '... ' ))
278
280
self .stdout_hist += '... '
279
281
280
282
urwid .connect_signal (self .edit , 'change' , self .on_input_change )
283
+ self .edits .append (self .edit )
281
284
self .listwalker .append (self .edit )
282
285
self .listbox .set_focus (len (self .listwalker ) - 1 )
283
286
284
287
def on_input_change (self , edit , text ):
288
+ tokens = self .tokenize (text , False )
289
+ edit .set_edit_markup (list (format_tokens (tokens )))
285
290
# If we call this synchronously the get_edit_text() in repl.cw
286
291
# still returns the old text...
287
292
self .main_loop .set_alarm_in (0 , self ._populate_completion )
0 commit comments