Skip to content

Commit ef91741

Browse files
Attila Szöllősisebastinas
Attila Szöllősi
authored andcommitted
Use width aware slice
1 parent e621479 commit ef91741

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

bpython/curtsiesfrontend/replpainter.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ def display_linize(msg, columns, blank_line=False):
2525
"""Returns lines obtained by splitting msg over multiple lines.
2626
2727
Warning: if msg is empty, returns an empty list of lines"""
28-
display_lines = ([msg[start:end]
29-
for start, end in zip(
30-
range(0, len(msg), columns),
31-
range(columns, len(msg) + columns, columns))]
32-
if msg else ([''] if blank_line else []))
28+
msg = fmtstr(msg)
29+
try:
30+
display_lines = [msg.width_aware_slice(slice(start, end))
31+
for start, end in zip(
32+
range(0, msg.width, columns),
33+
range(columns, msg.width + columns, columns))]
34+
except ValueError:
35+
display_lines = ([''] if blank_line else [])
3336
return display_lines
3437

3538

0 commit comments

Comments
 (0)