summaryrefslogtreecommitdiff
path: root/wasp/draw565.py
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-11 19:14:30 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-04-11 19:15:02 (GMT)
commitf68eb610c5d77bb71d3952e0dc9ca70a472ebfae (patch)
treeca0b7a1174dc7e7013ce5e67fc18231d1d6ea0c3 /wasp/draw565.py
parent8cf9369efa9083cccee36e7596d52e12ace362d3 (diff)
wasp: On-device crash reporting
If an application crashes let's report it on the device so it can be distinguished from a hang (if nothing else it should mean we get better bug reports).
Diffstat (limited to 'wasp/draw565.py')
-rw-r--r--wasp/draw565.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/wasp/draw565.py b/wasp/draw565.py
index 93032ac..1b1ce11 100644
--- a/wasp/draw565.py
+++ b/wasp/draw565.py
@@ -235,3 +235,32 @@ class Draw565(object):
if width:
display.fill(0, x, y, rightpad, h)
+
+ def wrap(self, s, width):
+ font = self._font
+ max = len(s)
+ chunks = [ 0, ]
+ end = 0
+
+ while end < max:
+ start = end
+ l = 0
+
+ for i in range(start, max+1):
+ if i >= len(s):
+ break
+ ch = s[i]
+ if ch == '\n':
+ end = i+1
+ break
+ if ch == ' ':
+ end = i+1
+ (_, h, w) = font.get_ch(ch)
+ l += w + 1
+ if l > width:
+ break
+ if end <= start:
+ end = i
+ chunks.append(end)
+
+ return chunks