8080See {example_config_url} for an example config file.
8181Press {config.edit_config_key} to edit this config file.
8282"""
83+ EXAMPLE_CONFIG_URL = 'https://raw.githubusercontent.com/bpython/bpython/master/bpython/sample-config'
8384
8485# This is needed for is_nop and should be removed once is_nop is fixed.
8586if py3 :
@@ -950,8 +951,8 @@ def run_code_and_maybe_finish(self, for_code=None):
950951 if err :
951952 indent = 0
952953
953- # TODO This should be printed ABOVE the error that just happened instead
954- # or maybe just thrown away and not shown
954+ # TODO This should be printed ABOVE the error that just happened
955+ # instead or maybe just thrown away and not shown
955956 if self .current_stdouterr_line :
956957 self .display_lines .extend (paint .display_linize (self .current_stdouterr_line , self .width ))
957958 self .current_stdouterr_line = ''
@@ -969,7 +970,8 @@ def keyboard_interrupt(self):
969970 self .clear_current_block (remove_from_history = False )
970971
971972 def unhighlight_paren (self ):
972- """modify line in self.display_buffer to unhighlight a paren if possible
973+ """Modify line in self.display_buffer to unhighlight a paren if
974+ possible.
973975
974976 self.highlighted_paren should be a line in ?
975977 """
@@ -1026,7 +1028,8 @@ def send_to_stdin(self, line):
10261028 # formatting, output
10271029 @property
10281030 def done (self ):
1029- """Whether the last block is complete - which prompt to use, ps1 or ps2"""
1031+ """Whether the last block is complete - which prompt to use, ps1 or
1032+ ps2"""
10301033 return not self .buffer
10311034
10321035 @property
@@ -1082,7 +1085,8 @@ def display_line_with_prompt(self):
10821085 def current_cursor_line_without_suggestion (self ):
10831086 """Current line, either output/input or Python prompt + code"""
10841087 value = (self .current_output_line +
1085- ('' if self .coderunner .running else self .display_line_with_prompt ))
1088+ ('' if self .coderunner .running else
1089+ self .display_line_with_prompt ))
10861090 logger .debug ('current cursor line: %r' , value )
10871091 return value
10881092
@@ -1113,12 +1117,13 @@ def current_output_line(self, value):
11131117 self .stdin .current_line = '\n '
11141118
11151119 def paint (self , about_to_exit = False , user_quit = False ):
1116- """Returns an array of min_height or more rows and width columns, plus cursor position
1120+ """Returns an array of min_height or more rows and width columns, plus
1121+ cursor position
11171122
1118- Paints the entire screen - ideally the terminal display layer will take a diff and only
1119- write to the screen in portions that have changed, but the idea is that we don't need
1120- to worry about that here, instead every frame is completely redrawn because
1121- less state is cool!
1123+ Paints the entire screen - ideally the terminal display layer will take
1124+ a diff and only write to the screen in portions that have changed, but
1125+ the idea is that we don't need to worry about that here, instead every
1126+ frame is completely redrawn because less state is cool!
11221127 """
11231128 # The hairiest function in the curtsies - a cleanup would be great.
11241129 if about_to_exit :
@@ -1127,33 +1132,41 @@ def paint(self, about_to_exit=False, user_quit=False):
11271132 width , min_height = self .width , self .height
11281133 show_status_bar = bool (self .status_bar .should_show_message ) or self .status_bar .has_focus
11291134 if show_status_bar :
1130- min_height -= 1 # because we're going to tack the status bar on at the end,
1131- # shoot for an array one less than the height of the screen
1135+ # because we're going to tack the status bar on at the end, shoot
1136+ # for an array one less than the height of the screen
1137+ min_height -= 1
11321138
11331139 current_line_start_row = len (self .lines_for_display ) - max (0 , self .scroll_offset )
1134- #TODO how is the situation of self.scroll_offset < 0 possible?
1135- #current_line_start_row = len(self.lines_for_display) - self.scroll_offset
1140+ # TODO how is the situation of self.scroll_offset < 0 possible?
1141+ # current_line_start_row = len(self.lines_for_display) - self.scroll_offset
11361142 if self .request_paint_to_clear_screen : # or show_status_bar and about_to_exit ?
11371143 self .request_paint_to_clear_screen = False
11381144 arr = FSArray (min_height + current_line_start_row , width )
11391145 else :
11401146 arr = FSArray (0 , width )
1141- #TODO test case of current line filling up the whole screen (there aren't enough rows to show it)
1147+ # TODO test case of current line filling up the whole screen (there
1148+ # aren't enough rows to show it)
11421149
1143- current_line = paint .paint_current_line (min_height , width , self .current_cursor_line )
1144- # needs to happen before we calculate contents of history because calculating
1145- # self.current_cursor_line has the side effect of unhighlighting parens in buffer
1150+ current_line = paint .paint_current_line (min_height , width ,
1151+ self .current_cursor_line )
1152+ # needs to happen before we calculate contents of history because
1153+ # calculating self.current_cursor_line has the side effect of
1154+ # unhighlighting parens in buffer
11461155
11471156 def move_screen_up (current_line_start_row ):
11481157 # move screen back up a screen minus a line
11491158 while current_line_start_row < 0 :
1150- logger .debug ('scroll_offset was %s, current_line_start_row was %s' , self .scroll_offset , current_line_start_row )
1159+ logger .debug ('scroll_offset was %s, current_line_start_row '
1160+ 'was %s' , self .scroll_offset ,
1161+ current_line_start_row )
11511162 self .scroll_offset = self .scroll_offset - self .height
11521163 current_line_start_row = len (self .lines_for_display ) - max (- 1 , self .scroll_offset )
1153- logger .debug ('scroll_offset changed to %s, current_line_start_row changed to %s' , self .scroll_offset , current_line_start_row )
1164+ logger .debug ('scroll_offset changed to %s, '
1165+ 'current_line_start_row changed to %s' ,
1166+ self .scroll_offset , current_line_start_row )
11541167 return current_line_start_row
11551168
1156- if self .inconsistent_history == True and not self .history_already_messed_up :
1169+ if self .inconsistent_history and not self .history_already_messed_up :
11571170 logger .debug (INCONSISTENT_HISTORY_MSG )
11581171 self .history_already_messed_up = True
11591172 msg = INCONSISTENT_HISTORY_MSG
@@ -1165,36 +1178,41 @@ def move_screen_up(current_line_start_row):
11651178 current_line_start_row = move_screen_up (current_line_start_row )
11661179 logger .debug ('current_line_start_row: %r' , current_line_start_row )
11671180
1168- history = paint .paint_history (max (0 , current_line_start_row - 1 ), width , self .lines_for_display )
1169- arr [1 :history .height + 1 ,:history .width ] = history
1181+ history = paint .paint_history (max (0 , current_line_start_row - 1 ),
1182+ width , self .lines_for_display )
1183+ arr [1 :history .height + 1 , :history .width ] = history
11701184
11711185 if arr .height <= min_height :
1172- arr [min_height , 0 ] = ' ' # force scroll down to hide broken history message
1186+ arr [min_height , 0 ] = ' ' # force scroll down to hide broken history message
11731187
1174- elif current_line_start_row < 0 : # if current line trying to be drawn off the top of the screen
1188+ elif current_line_start_row < 0 : # if current line trying to be drawn off the top of the screen
11751189 logger .debug (CONTIGUITY_BROKEN_MSG )
11761190 msg = CONTIGUITY_BROKEN_MSG
11771191 arr [0 , 0 :min (len (msg ), width )] = [msg [:width ]]
11781192
11791193 current_line_start_row = move_screen_up (current_line_start_row )
11801194
1181- history = paint .paint_history (max (0 , current_line_start_row - 1 ), width , self .lines_for_display )
1182- arr [1 :history .height + 1 ,:history .width ] = history
1195+ history = paint .paint_history (max (0 , current_line_start_row - 1 ),
1196+ width , self .lines_for_display )
1197+ arr [1 :history .height + 1 , :history .width ] = history
11831198
11841199 if arr .height <= min_height :
1185- arr [min_height , 0 ] = ' ' # force scroll down to hide broken history message
1200+ # force scroll down to hide broken history message
1201+ arr [min_height , 0 ] = ' '
11861202
11871203 else :
11881204 assert current_line_start_row >= 0
1189- logger .debug ("no history issues. start %i" ,current_line_start_row )
1190- history = paint .paint_history (current_line_start_row , width , self .lines_for_display )
1191- arr [:history .height ,:history .width ] = history
1205+ logger .debug ("no history issues. start %i" , current_line_start_row )
1206+ history = paint .paint_history (current_line_start_row , width ,
1207+ self .lines_for_display )
1208+ arr [:history .height , :history .width ] = history
11921209
11931210 self .inconsistent_history = False
11941211
11951212 if user_quit : # quit() or exit() in interp
11961213 current_line_start_row = current_line_start_row - current_line .height
1197- logger .debug ("---current line row slice %r, %r" , current_line_start_row , current_line_start_row + current_line .height )
1214+ logger .debug ("---current line row slice %r, %r" , current_line_start_row ,
1215+ current_line_start_row + current_line .height )
11981216 logger .debug ("---current line col slice %r, %r" , 0 , current_line .width )
11991217 arr [current_line_start_row :current_line_start_row + current_line .height ,
12001218 0 :current_line .width ] = current_line
@@ -1203,13 +1221,13 @@ def move_screen_up(current_line_start_row):
12031221 return arr , (0 , 0 ) # short circuit, no room for infobox
12041222
12051223 lines = paint .display_linize (self .current_cursor_line + 'X' , width )
1206- # extra character for space for the cursor
1224+ # extra character for space for the cursor
12071225 current_line_end_row = current_line_start_row + len (lines ) - 1
12081226
12091227 if self .stdin .has_focus :
12101228 cursor_row , cursor_column = divmod (len (self .current_stdouterr_line ) + self .stdin .cursor_offset , width )
12111229 assert cursor_column >= 0 , cursor_column
1212- elif self .coderunner .running : # TODO does this ever happen?
1230+ elif self .coderunner .running : # TODO does this ever happen?
12131231 cursor_row , cursor_column = divmod (len (self .current_cursor_line_without_suggestion ) + self .cursor_offset , width )
12141232 assert cursor_column >= 0 , (cursor_column , len (self .current_cursor_line ), len (self .current_line ), self .cursor_offset )
12151233 else :
@@ -1259,20 +1277,21 @@ def move_screen_up(current_line_start_row):
12591277 logger .debug ('cursor pos: %r' , (cursor_row , cursor_column ))
12601278 return arr , (cursor_row , cursor_column )
12611279
1262-
12631280 @contextlib .contextmanager
12641281 def in_paste_mode (self ):
12651282 orig_value = self .paste_mode
12661283 self .paste_mode = True
12671284 yield
12681285 self .paste_mode = orig_value
12691286
1270- ## Debugging shims, good example of embedding a Repl in other code
1287+ # Debugging shims, good example of embedding a Repl in other code
12711288 def dumb_print_output (self ):
12721289 arr , cpos = self .paint ()
12731290 arr [cpos [0 ]:cpos [0 ]+ 1 , cpos [1 ]:cpos [1 ]+ 1 ] = ['~' ]
1291+
12741292 def my_print (msg ):
12751293 self .orig_stdout .write (str (msg )+ '\n ' )
1294+
12761295 my_print ('X' * (self .width + 8 ))
12771296 my_print (' use "/" for enter ' .center (self .width + 8 , 'X' ))
12781297 my_print (' use "\\ " for rewind ' .center (self .width + 8 , 'X' ))
@@ -1355,16 +1374,17 @@ def _set_cursor_offset(self, offset, update_completion=True,
13551374 self .unhighlight_paren ()
13561375
13571376 cursor_offset = property (_get_cursor_offset , _set_cursor_offset , None ,
1358- "The current cursor offset from the front of the line" )
1377+ "The current cursor offset from the front of the "
1378+ "line" )
13591379
13601380 def echo (self , msg , redraw = True ):
13611381 """
13621382 Notification that redrawing the current line is necessary (we don't
13631383 care, since we always redraw the whole screen)
13641384
1365- Supposed to parse and echo a formatted string with appropriate attributes.
1366- It's not supposed to update the screen if it's reevaluating the code (as it
1367- does with undo)."""
1385+ Supposed to parse and echo a formatted string with appropriate
1386+ attributes. It's not supposed to update the screen if it's reevaluating
1387+ the code (as it does with undo)."""
13681388 logger .debug ("echo called with %r" % msg )
13691389
13701390 @property
@@ -1438,7 +1458,7 @@ def reevaluate(self, insert_into_history=False):
14381458 logger .debug ('old_display_lines_offscreen %s' , '|' .join (str (x ) for x in old_display_lines_offscreen ))
14391459 logger .debug (' display_lines_offscreen %s' , '|' .join (str (x ) for x in display_lines_offscreen ))
14401460 if old_display_lines_offscreen [:len (display_lines_offscreen )] != display_lines_offscreen and not self .history_already_messed_up :
1441- #self.scroll_offset = self.scroll_offset + (len(old_display_lines)-len(self.display_lines))
1461+ # self.scroll_offset = self.scroll_offset + (len(old_display_lines)-len(self.display_lines))
14421462 self .inconsistent_history = True
14431463 logger .debug ('after rewind, self.inconsistent_history is %r' , self .inconsistent_history )
14441464
@@ -1499,7 +1519,7 @@ def version_help_text(self):
14991519 return (('bpython-curtsies version %s' % bpython .__version__ ) + ' ' +
15001520 ('using curtsies version %s' % curtsies .__version__ ) + '\n ' +
15011521 HELP_MESSAGE .format (config_file_location = default_config_path (),
1502- example_config_url = 'https://raw.githubusercontent.com/bpython/bpython/master/bpython/sample-config' ,
1522+ example_config_url = EXAMPLE_CONFIG_URL ,
15031523 config = self .config ))
15041524
15051525 def key_help_text (self ):
@@ -1513,8 +1533,10 @@ def key_help_text(self):
15131533 for functionality , key in [(attr [:- 4 ].replace ('_' , ' ' ), getattr (self .config , attr ))
15141534 for attr in self .config .__dict__
15151535 if attr .endswith ('key' )]:
1516- if functionality in NOT_IMPLEMENTED : key = "Not Implemented"
1517- if key == '' : key = 'Disabled'
1536+ if functionality in NOT_IMPLEMENTED :
1537+ key = 'Not Implemented'
1538+ if key == '' :
1539+ key = 'Disabled'
15181540
15191541 pairs .append ([functionality , key ])
15201542
0 commit comments