From c1db755f659e27afc718340607359c9733f7152b Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Thu, 17 Dec 2020 10:10:20 -0800 Subject: [PATCH 1/3] Fixed wrapping function when text length = maxchars --- adafruit_display_text/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 26bb3ca..147de03 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -53,6 +53,7 @@ def chunks(lst, n): for part in chunks(w, max_chars - 1): parts.append("{}-".format(part)) the_lines.extend(parts[:-1]) + # Remove the last hyphen on the last chunk the_line = parts[-1][:-1] continue @@ -63,6 +64,9 @@ def chunks(lst, n): the_line = "" + w if the_line: # Last line remaining the_lines.append(the_line) + # Remove any blank lines + while not the_lines[0]: + del the_lines[0] # Remove first space from first line: if the_lines[0][0] == " ": the_lines[0] = the_lines[0][1:] From 2a786af5e49be273b14a3b6846f452711bd44242 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Fri, 18 Dec 2020 08:37:44 -0800 Subject: [PATCH 2/3] Adjusted to work in all cases --- adafruit_display_text/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 147de03..6a7e338 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -53,12 +53,13 @@ def chunks(lst, n): for part in chunks(w, max_chars - 1): parts.append("{}-".format(part)) the_lines.extend(parts[:-1]) - # Remove the last hyphen on the last chunk the_line = parts[-1][:-1] continue if len(the_line + " " + w) <= max_chars: the_line += " " + w + elif not the_line and len(w) == max_chars: + the_lines.append(w) else: the_lines.append(the_line) the_line = "" + w From ed44f778b7a2e205894d7efe86a13b81eb91e273 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Mon, 21 Dec 2020 08:47:04 -0800 Subject: [PATCH 3/3] Fixed missing chunks in the middle of the line --- adafruit_display_text/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/adafruit_display_text/__init__.py b/adafruit_display_text/__init__.py index 6a7e338..ea290dc 100644 --- a/adafruit_display_text/__init__.py +++ b/adafruit_display_text/__init__.py @@ -49,6 +49,8 @@ def chunks(lst, n): the_line = "" for w in words: if len(w) > max_chars: + if the_line: # add what we had stored + the_lines.append(the_line) parts = [] for part in chunks(w, max_chars - 1): parts.append("{}-".format(part))