Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions fire/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ def WrappedJoin(items, separator=' | ', width=80):
if len(current_line) + len(item) <= width:
current_line += item
else:
lines.append(current_line.rstrip())
if current_line:
lines.append(current_line.rstrip())
current_line = item
else:
if len(current_line) + len(item) + len(separator) <= width:
current_line += item + separator
else:
lines.append(current_line.rstrip())
if current_line:
lines.append(current_line.rstrip())
current_line = item + separator

lines.append(current_line)
Expand Down
9 changes: 9 additions & 0 deletions fire/formatting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def test_wrap_multiple_items(self):
'chicken |',
'cheese'], lines)

def test_wrap_oversized_first_item(self):
self.assertEqual(['long_command'],
formatting.WrappedJoin(['long_command'], width=5))
self.assertEqual(['first |', 'next'],
formatting.WrappedJoin(['first', 'next'], width=5))

def test_wrap_empty_items(self):
self.assertEqual([''], formatting.WrappedJoin([], width=5))

def test_ellipsis_truncate(self):
text = 'This is a string'
truncated_text = formatting.EllipsisTruncate(
Expand Down
Loading