hackerbase/src/sgr-cell.scm

67 lines
1.6 KiB
Scheme

;;
;; sgr-cell.scm
;;
;; Surface API for handling strings with SGR sequences as table cells.
;;
;; ISC License
;;
;; Copyright 2023 Dominik Pantůček <dominik.pantucek@trustica.cz>
;;
;; Permission to use, copy, modify, and/or distribute this software
;; for any purpose with or without fee is hereby granted, provided
;; that the above copyright notice and this permission notice appear
;; in all copies.
;;
;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
;;
(declare (unit sgr-cell))
(module
sgr-cell
(
string->sgr-cell
sgr-cell-width
sgr-cell-height
sgr-cell-min-width
sgr-cell-render
sgr-cell-vexpand
)
(import scheme
racket-kwargs
sgr-state
sgr-list
sgr-block)
(define* (string->sgr-cell str (initial-state empty-sgr-state))
(let ((cell0 (sgr-list->sgr-block
(string->sgr-list/words str initial-state)
initial-state)))
(if (null? cell0)
(list (list initial-state))
cell0)))
(define sgr-cell-width sgr-block-width)
(define sgr-cell-height sgr-block-height)
(define (sgr-cell-min-width sc)
(apply max (cons 0 (map sgr-list-min-width sc))))
(define (sgr-cell-render . args)
(apply sgr-block-render args))
(define sgr-cell-vexpand sgr-block-vexpand)
)