File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -353,14 +353,16 @@ def calc_screen(self) -> list[str]:
353353 else :
354354 pre = prompt
355355 prelen = prompt_len
356- for wrap in range ( wrapcount + 1 ) :
356+ while True :
357357 index_to_wrap_before = 0
358358 column = 0
359359 for char_width in char_widths :
360360 if column + char_width + prelen >= self .console .width :
361361 break
362362 index_to_wrap_before += 1
363363 column += char_width
364+ if index_to_wrap_before == 0 and not prelen :
365+ index_to_wrap_before = 1 # force progress
364366 if len (chars ) > index_to_wrap_before :
365367 offset += index_to_wrap_before
366368 post = "\\ "
@@ -378,6 +380,8 @@ def calc_screen(self) -> list[str]:
378380 char_widths = char_widths [index_to_wrap_before :]
379381 pre = ""
380382 prelen = 0
383+ if not post :
384+ break
381385 self .screeninfo = screeninfo
382386 self .cxy = self .pos2xy ()
383387 if self .msg :
Original file line number Diff line number Diff line change @@ -35,6 +35,11 @@ def test_calc_screen_wrap_three_lines(self):
3535 reader , _ = handle_events_narrow_console (events )
3636 self .assert_screen_equal (reader , f"{ 9 * "a" } \\ \n { 9 * "a" } \\ \n aa" )
3737
38+ def test_calc_screen_wrap_three_lines_last_char (self ):
39+ events = code_to_events (19 * "a" )
40+ reader , _ = handle_events_narrow_console (events )
41+ self .assert_screen_equal (reader , f"{ 9 * "a" } \\ \n { 9 * "a" } \\ \n a" )
42+
3843 def test_calc_screen_prompt_handling (self ):
3944 def prepare_reader_keep_prompts (* args , ** kwargs ):
4045 reader = prepare_reader (* args , ** kwargs )
Original file line number Diff line number Diff line change 1+ Fix the :term: `REPL ` dropping the last characters of a long line that wraps
2+ across several rows, which could raise :exc: `IndexError ` when moving the
3+ cursor with the arrow keys.
You can’t perform that action at this time.
0 commit comments