Skip to content
Open
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
30 changes: 18 additions & 12 deletions modules/textwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,26 @@ def progress_bar(self, line, percentage, fg=None):
self.display.rect(x, y, 100, self.font.HEIGHT, fg)

def flow_lines(self, text, font=None):
# Don't word wrap, just chop off
lines = text.split("\n")
result = []
max_len = self.width_chars(font)
for line in lines:
line_len = len(line)
if line_len == 0:
result.append(line)
continue
i = 0
while i < line_len:
n = min(line_len - i, max_len)
result.append(line[i:i+n])
i = i + n

while text:
if len(text) <= max_len:
result.append(text)
break

end = max_len
for index in range(max_len, max_len - 10, -1):
character = text[index]
if character == " ":
end = index
break
elif character == "-":
end = index + 1
break

result.append(text[:end])
text = text[index + 1:]

if len(result) == 0:
# Have to return at least one line
Expand Down