Update to support new uniseg and nicer exception messages

This commit is contained in:
Vivianne 2024-03-11 00:07:49 -04:00
parent 7c4d86d1a7
commit 7dc5e34e3d
Signed by: vv
GPG key ID: F3E249EDFAC7BE26
2 changed files with 9 additions and 13 deletions

View file

@ -54,14 +54,10 @@
(define* (blank #:optional (w 0) (h 1))
(gaart w h (λ (okay? blit! rpos cpos) #f)))
;; TODO: use stock char->grapheme
(define (char->grapheme char)
((make-grapheme-iterator) char))
(define (char ch)
(define grapheme (char->grapheme ch))
(unless grapheme
(error (format #f "Unable to convert ~s to a valid unicode grapheme" ch)))
(scm-error #f "char" "Unable to convert ~s to a valid unicode grapheme" (list ch) (list ch)))
(gaart
1 1
@ -75,12 +71,12 @@
(λ (okay? blit! rpos cpos)
;; Go through each grapheme, print it and advance the position
;; depending on the width
(stream-fold
(fold
(λ (gr c)
(blit! rpos c gr)
(+ c (grapheme-width gr)))
cpos
(string->grapheme-stream str))
(string->grapheme-list str))
#f)))
(define (place-at back row-offset col-offset front)
@ -95,7 +91,7 @@
(match-let ((($ <gaart> xw xh _) x))
(unless (and (<= (+ xw cpos) matte-width)
(<= (+ xh rpos) matte-height))
(error (format #f "matte-at: Original (~ax~a@~a,~a) must fit inside matte (~ax~a)" xw xh cpos rpos matte-width matte-height)))
(scm-error #f "matte-at" "Original (~ax~a@~a,~a) must fit inside matte (~ax~a)" (list xw xh cpos rpos matte-width matte-height) (list x)))
(place-at (blank matte-width matte-height) rpos cpos x)))
(define* (matte matte-width matte-height x #:key (halign 'center) (valign 'center))
@ -104,7 +100,7 @@
(match-let ((($ <gaart> xw xh draw-x) x))
(unless (and (<= xw width)
(<= xh height))
(error (format #f "matte: Original (~ax~a) must fit inside matte (~ax~a)" xw xh width height)))
(scm-error #f "matte" "Original (~ax~a) must fit inside matte (~ax~a)" (list xw xh width height) (list x)))
(matte-at width height
(match halign
@ -186,8 +182,7 @@
(match-let ((($ <gaart> xw xh draw-x) x)
(($ <gaart> yw yh draw-y) y))
(unless (= xw yw)
;; TODO: proper error messages with irritants
(error (format #f "vappend2: Widths must be equal: ~a vs ~a" xw yw)))
(scm-error #f "vappend2" "Widths must be equal: ~a vs ~a" (list xw yw) (list xw yw)))
(gaart
xw (+ xh yh)
(λ (okay? blit! rpos cpos)
@ -218,7 +213,7 @@
(match-let ((($ <gaart> xw xh draw-x) x)
(($ <gaart> yw yh draw-y) y))
(unless (= xh yh)
(error (format #f "happend2: Heights must be equal: ~a vs ~a" xh yh)))
(scm-error #f "happend2" "Heights must be equal: ~a vs ~a" (list xh yh) (list xh yh)))
(gaart
(+ xw yw) xh
(λ (okay? blit! rpos cpos)

View file

@ -14,4 +14,5 @@
(blit! (λ (rpos cpos grapheme)
(buffer-set! buf rpos cpos grapheme))))
(draw okay? blit! 0 0)
(write-buffer buf port)))
(write-buffer buf port)
buf))