31
31
32
32
import bpython
33
33
from bpython .repl import Repl as BpythonRepl , SourceNotFound
34
+ from bpython .repl import LineTypeTranslator as LineType
34
35
from bpython .config import (
35
36
Struct ,
36
37
loadini ,
@@ -396,7 +397,6 @@ def __init__(
396
397
# current line of output - stdout and stdin go here
397
398
self .current_stdouterr_line = ""
398
399
399
-
400
400
# this is every line that's been displayed (input and output)
401
401
# as with formatting applied. Logical lines that exceeded the terminal width
402
402
# at the time of output are split across multiple entries in this list.
@@ -408,8 +408,9 @@ def __init__(
408
408
# This is every logical line that's been displayed, both input and output.
409
409
# Like self.history, lines are unwrapped, uncolored, and without prompt.
410
410
# Entries are tuples, where
411
- # the first element a string of the line
412
- # the second element is one of 2 strings: "input" or "output".
411
+ # - the first element the line (string, not fmtsr)
412
+ # - the second element is one of 2 global constants: "input" or "output"
413
+ # (use LineType.INPUT or LineType.OUTPUT to avoid typing these strings)
413
414
self .all_logical_lines = []
414
415
415
416
# formatted version of lines in the buffer kept around so we can
@@ -881,10 +882,9 @@ def on_enter(self, new_code=True, reset_rl_history=True):
881
882
self .rl_history .reset ()
882
883
883
884
self .history .append (self .current_line )
884
- self .all_logical_lines .append ((self .current_line , "input" ))
885
+ self .all_logical_lines .append ((self .current_line , LineType . INPUT ))
885
886
self .push (self .current_line , insert_into_history = new_code )
886
887
887
-
888
888
def on_tab (self , back = False ):
889
889
"""Do something on tab key
890
890
taken from bpython.cli
@@ -1016,7 +1016,7 @@ def send_session_to_external_editor(self, filename=None):
1016
1016
"""
1017
1017
for_editor = EDIT_SESSION_HEADER
1018
1018
for_editor += "\n " .join (
1019
- line [0 ] if line [1 ] == "input"
1019
+ line [0 ] if line [1 ] == INPUT
1020
1020
else "### " + line [0 ]
1021
1021
for line in self .all_logical_lines
1022
1022
)
@@ -1189,9 +1189,7 @@ def push(self, line, insert_into_history=True):
1189
1189
if c :
1190
1190
logger .debug ("finished - buffer cleared" )
1191
1191
self .cursor_offset = 0
1192
-
1193
1192
self .display_lines .extend (self .display_buffer_lines )
1194
-
1195
1193
self .display_buffer = []
1196
1194
self .buffer = []
1197
1195
@@ -1296,14 +1294,12 @@ def send_to_stdouterr(self, output):
1296
1294
[],
1297
1295
)
1298
1296
)
1299
-
1300
1297
# These can be FmtStrs, but self.all_logical_lines only wants strings
1301
1298
for line in [self .current_stdouterr_line ] + lines [1 :- 1 ]:
1302
1299
if isinstance (line , FmtStr ):
1303
- self .all_logical_lines .append ((line .s , "output" ))
1300
+ self .all_logical_lines .append ((line .s , LineType . OUTPUT ))
1304
1301
else :
1305
- self .all_logical_lines .append ((line , "output" ))
1306
-
1302
+ self .all_logical_lines .append ((line , LineType .OUTPUT ))
1307
1303
1308
1304
self .current_stdouterr_line = lines [- 1 ]
1309
1305
logger .debug ("display_lines: %r" , self .display_lines )
@@ -1846,8 +1842,6 @@ def take_back_empty_line(self):
1846
1842
self .display_lines .pop ()
1847
1843
self .all_logical_lines .pop ()
1848
1844
1849
-
1850
-
1851
1845
def prompt_undo (self ):
1852
1846
if self .buffer :
1853
1847
return self .take_back_buffer_line ()
@@ -1865,7 +1859,7 @@ def redo(self):
1865
1859
if (self .redo_stack ):
1866
1860
temp = self .redo_stack .pop ()
1867
1861
self .history .append (temp )
1868
- self .all_logical_lines .append ((temp , "input" ))
1862
+ self .all_logical_lines .append ((temp , LineType . INPUT ))
1869
1863
self .push (temp )
1870
1864
else :
1871
1865
self .status_bar .message ("Nothing to redo." )
@@ -1954,7 +1948,6 @@ def getstdout(self):
1954
1948
)
1955
1949
return s
1956
1950
1957
-
1958
1951
def focus_on_subprocess (self , args ):
1959
1952
prev_sigwinch_handler = signal .getsignal (signal .SIGWINCH )
1960
1953
try :
0 commit comments