Skip to content

Commit 8717242

Browse files
authored
Merge pull request #105 from makermelissa/master
Fixed wrapping function when text length = maxchars
2 parents 9bc4d2b + ed44f77 commit 8717242

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

adafruit_display_text/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def chunks(lst, n):
4949
the_line = ""
5050
for w in words:
5151
if len(w) > max_chars:
52+
if the_line: # add what we had stored
53+
the_lines.append(the_line)
5254
parts = []
5355
for part in chunks(w, max_chars - 1):
5456
parts.append("{}-".format(part))
@@ -58,11 +60,16 @@ def chunks(lst, n):
5860

5961
if len(the_line + " " + w) <= max_chars:
6062
the_line += " " + w
63+
elif not the_line and len(w) == max_chars:
64+
the_lines.append(w)
6165
else:
6266
the_lines.append(the_line)
6367
the_line = "" + w
6468
if the_line: # Last line remaining
6569
the_lines.append(the_line)
70+
# Remove any blank lines
71+
while not the_lines[0]:
72+
del the_lines[0]
6673
# Remove first space from first line:
6774
if the_lines[0][0] == " ":
6875
the_lines[0] = the_lines[0][1:]

0 commit comments

Comments
 (0)