3131
3232import bpython
3333from bpython .repl import Repl as BpythonRepl , SourceNotFound
34+ from bpython .repl import LineTypeTranslator as LineType
3435from bpython .config import (
3536 Struct ,
3637 loadini ,
@@ -396,7 +397,6 @@ def __init__(
396397 # current line of output - stdout and stdin go here
397398 self .current_stdouterr_line = ""
398399
399-
400400 # this is every line that's been displayed (input and output)
401401 # as with formatting applied. Logical lines that exceeded the terminal width
402402 # at the time of output are split across multiple entries in this list.
@@ -408,8 +408,9 @@ def __init__(
408408 # This is every logical line that's been displayed, both input and output.
409409 # Like self.history, lines are unwrapped, uncolored, and without prompt.
410410 # 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)
413414 self .all_logical_lines = []
414415
415416 # 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):
881882 self .rl_history .reset ()
882883
883884 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 ))
885886 self .push (self .current_line , insert_into_history = new_code )
886887
887-
888888 def on_tab (self , back = False ):
889889 """Do something on tab key
890890 taken from bpython.cli
@@ -1016,7 +1016,7 @@ def send_session_to_external_editor(self, filename=None):
10161016 """
10171017 for_editor = EDIT_SESSION_HEADER
10181018 for_editor += "\n " .join (
1019- line [0 ] if line [1 ] == "input"
1019+ line [0 ] if line [1 ] == INPUT
10201020 else "### " + line [0 ]
10211021 for line in self .all_logical_lines
10221022 )
@@ -1189,9 +1189,7 @@ def push(self, line, insert_into_history=True):
11891189 if c :
11901190 logger .debug ("finished - buffer cleared" )
11911191 self .cursor_offset = 0
1192-
11931192 self .display_lines .extend (self .display_buffer_lines )
1194-
11951193 self .display_buffer = []
11961194 self .buffer = []
11971195
@@ -1296,14 +1294,12 @@ def send_to_stdouterr(self, output):
12961294 [],
12971295 )
12981296 )
1299-
13001297 # These can be FmtStrs, but self.all_logical_lines only wants strings
13011298 for line in [self .current_stdouterr_line ] + lines [1 :- 1 ]:
13021299 if isinstance (line , FmtStr ):
1303- self .all_logical_lines .append ((line .s , "output" ))
1300+ self .all_logical_lines .append ((line .s , LineType . OUTPUT ))
13041301 else :
1305- self .all_logical_lines .append ((line , "output" ))
1306-
1302+ self .all_logical_lines .append ((line , LineType .OUTPUT ))
13071303
13081304 self .current_stdouterr_line = lines [- 1 ]
13091305 logger .debug ("display_lines: %r" , self .display_lines )
@@ -1846,8 +1842,6 @@ def take_back_empty_line(self):
18461842 self .display_lines .pop ()
18471843 self .all_logical_lines .pop ()
18481844
1849-
1850-
18511845 def prompt_undo (self ):
18521846 if self .buffer :
18531847 return self .take_back_buffer_line ()
@@ -1865,7 +1859,7 @@ def redo(self):
18651859 if (self .redo_stack ):
18661860 temp = self .redo_stack .pop ()
18671861 self .history .append (temp )
1868- self .all_logical_lines .append ((temp , "input" ))
1862+ self .all_logical_lines .append ((temp , LineType . INPUT ))
18691863 self .push (temp )
18701864 else :
18711865 self .status_bar .message ("Nothing to redo." )
@@ -1954,7 +1948,6 @@ def getstdout(self):
19541948 )
19551949 return s
19561950
1957-
19581951 def focus_on_subprocess (self , args ):
19591952 prev_sigwinch_handler = signal .getsignal (signal .SIGWINCH )
19601953 try :
0 commit comments