Simple support for newlines

This commit is contained in:
Vivianne 2024-03-11 00:49:58 -04:00
parent b7ca692420
commit aceb2475f1
Signed by: vv
GPG Key ID: F3E249EDFAC7BE26
1 changed files with 20 additions and 13 deletions

View File

@ -65,19 +65,26 @@
(blit! rpos cpos grapheme)
#f)))
(define (text str)
(gaart
(string-width str) 1
(λ (okay? blit! rpos cpos)
;; Go through each grapheme, print it and advance the position
;; depending on the width
(fold
(λ (gr c)
(blit! rpos c gr)
(+ c (grapheme-width gr)))
cpos
(string->grapheme-list str))
#f)))
;; TODO: detect non-printable characters other than newline
;; We need to discard them and also handle escape codes/printing those, etc.
(define* (text str #:key (halign #f))
(define contains-newline? (string-index str #\newline))
(if contains-newline?
(if halign
(vappend* (map text (string-split str #\newline)) #:halign halign)
(scm-error 'keyword-argument-error "text" "String contained newlines but no halign argument was set" '() (list halign)))
(gaart
(string-width str) 1
(λ (okay? blit! rpos cpos)
;; Go through each grapheme, print it and advance the position
;; depending on the width
(fold
(λ (gr c)
(blit! rpos c gr)
(+ c (grapheme-width gr)))
cpos
(string->grapheme-list str))
#f))))
(define (place-at back row-offset col-offset front)
(match-let ((($ <gaart> bw bh draw-b) back)