diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-11 19:14:30 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-04-11 19:15:02 (GMT) |
| commit | f68eb610c5d77bb71d3952e0dc9ca70a472ebfae (patch) | |
| tree | ca0b7a1174dc7e7013ce5e67fc18231d1d6ea0c3 /wasp/draw565.py | |
| parent | 8cf9369efa9083cccee36e7596d52e12ace362d3 (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.py | 29 |
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 |
