X Tutup
Skip to content

Commit 8b5df4f

Browse files
committed
Make string operations more readable (fixes bpython#439)
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent ab89794 commit 8b5df4f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

bpython/curtsiesfrontend/replpainter.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,23 @@ def paint_infobox(rows, columns, matches, argspec, match, docstring, config, for
152152
(matches_lines(rows, width, matches, match, config, format) if matches else []) +
153153
(formatted_docstring(docstring, width, config) if docstring else []))
154154

155-
output_lines = []
155+
def add_border(line):
156+
"""Add colored borders left and right to a line."""
157+
new_line = border_color(config.left_border + ' ')
158+
new_line += line.ljust(width)[:width]
159+
new_line += border_color(' ' + config.right_border)
160+
return new_line
161+
156162
border_color = func_for_letter(config.color_scheme['main'])
157-
output_lines.append(border_color(config.left_top_corner+config.top_border*(width+2)+config.right_top_corner))
158-
for line in lines:
159-
output_lines.append(border_color(config.left_border+u' ')+((line+' '*(width - len(line)))[:width])+border_color(u' ' + config.right_border))
160-
output_lines.append(border_color(config.left_bottom_corner+config.bottom_border*(width+2)+config.right_bottom_corner))
163+
164+
top_line = border_color(config.left_top_corner +
165+
config.top_border * (width + 2) +
166+
config.right_top_corner)
167+
bottom_line = border_color(config.left_bottom_corner +
168+
config.bottom_border * (width + 2) +
169+
config.right_bottom_corner)
170+
171+
output_lines = [top_line] + map(add_border, lines) + [bottom_line]
161172
r = fsarray(output_lines[:min(rows-1, len(output_lines)-1)] + output_lines[-1:])
162173
return r
163174

0 commit comments

Comments
 (0)
X Tutup