1
0
Fork 0

Add custom wrapping function for displaying text

Setting text wrapping to true will wrap the text to the beginning of the line
again. This function just returns a list of strings that can be tweaked to
provide the lists of the right length, this way I can make sure that the text
continues in the right place on the next line.
This commit is contained in:
Tom Willemse 2023-07-07 23:41:19 -07:00
parent 48ce1ba157
commit 6da42d558e

View file

@ -17,7 +17,21 @@
;; this program. If not, see <https://www.gnu.org/licenses/>.
(use-modules ((inkplate) #:prefix inkplate:)
(srfi srfi-19))
(srfi srfi-19)
(srfi srfi-1))
(define (my-wrap text max-length)
(reverse
(map string-trim
(fold
(λ (item accumulator)
(let* ((current-line (car accumulator))
(new-line (format #f "~a ~a" current-line item)))
(if (> (string-length new-line) max-length)
(cons item accumulator)
(cons new-line (cdr accumulator)))))
'("")
(string-split text #\ )))))
(let* ((my-dev (inkplate:open "/dev/ttyUSB0"))
(date (current-date))
@ -100,19 +114,20 @@
(inkplate:set-text-size my-dev 4)
(inkplate:print my-dev (inkplate:convert-string-to-hex "S")))
(inkplate:set-cursor my-dev 265 15)
(inkplate:set-text-size my-dev 3)
(inkplate:set-text-wrap my-dev #f)
(inkplate:print my-dev (inkplate:convert-string-to-hex "Choose your own tempo for an"))
(inkplate:set-cursor my-dev 265 45)
(inkplate:set-text-size my-dev 3)
(inkplate:set-text-wrap my-dev #f)
(inkplate:print my-dev (inkplate:convert-string-to-hex "email conversation"))
(let loop ((lines (my-wrap "Give yourself permission to fail; it's the path to success" 29))
(x 265)
(y 15))
(inkplate:set-cursor my-dev x y)
(inkplate:print my-dev (inkplate:convert-string-to-hex (car lines)))
(unless (null? (cdr lines))
(loop (cdr lines) x (+ 30 y))))
(if (member "--reset" (command-line))
(inkplate:update my-dev)
(inkplate:partial-update my-dev 15 800 600))
(inkplate:send my-dev)
(inkplate:send my-dev)
(inkplate:close my-dev))