Skip to content

Commit 6b14aa6

Browse files
committed
Moved empty line check in table creator
1 parent d4035b4 commit 6b14aa6

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

cmd2/table_creator.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ def add_word(word_to_add: str, is_last_word: bool):
309309
if data_line_index > 0:
310310
wrapped_buf.write('\n')
311311

312+
# If the last line is empty, then add a newline and stop
313+
if data_line_index == len(data_str_lines) - 1 and not data_line:
314+
wrapped_buf.write('\n')
315+
break
316+
312317
# Locate the styles in this line
313318
styles = utils.get_styles_in_text(data_line)
314319

@@ -351,10 +356,6 @@ def add_word(word_to_add: str, is_last_word: bool):
351356
last_word = data_line_index == len(data_str_lines) - 1 and char_index == len(data_line)
352357
add_word(cur_word_buf.getvalue(), last_word)
353358

354-
# If the last line is empty, then add a newline
355-
elif data_line_index == len(data_str_lines) - 1:
356-
wrapped_buf.write('\n')
357-
358359
# Stop line loop if we've written to max_lines
359360
if total_lines == max_lines:
360361
# If this isn't the last data line and there is space

tests/test_table_creator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def test_blank_last_line():
133133
assert row == ('my line \n'
134134
' ')
135135

136+
row_data = ['\n']
137+
row = tc.generate_row(row_data=row_data)
138+
assert row == ' '
139+
140+
row_data = ['']
141+
row = tc.generate_row(row_data=row_data)
142+
assert row == ' '
143+
136144

137145
def test_wrap_text():
138146
column_1 = Column("Col 1", width=10)

0 commit comments

Comments
 (0)