Kitchenlight/text-mode: enforce maximum string length

This commit is contained in:
Shy 2017-03-14 17:15:16 +01:00
parent 92576cd6d3
commit 7b31061b3b

View file

@ -488,6 +488,9 @@ class Kitchenlight:
def text(self, text="Hello World", delay=250): def text(self, text="Hello World", delay=250):
"""Set to mode "text".""" """Set to mode "text"."""
text = text.encode("ascii", "ignore") text = text.encode("ascii", "ignore")
if len(text) > 256: # Maximum text length
print("Warning: text length must not exceed 256 characters!")
text = text[:256]
d = bytearray(8 + len(text) + 1) d = bytearray(8 + len(text) + 1)
v = memoryview(d) v = memoryview(d)
# Screen 8 # Screen 8