Work on cell lines alignment.

This commit is contained in:
Dominik Pantůček 2023-03-28 22:58:50 +02:00
parent 624460132b
commit 3f50d85412

View file

@ -139,24 +139,26 @@
;; Normalizes cell line to required width and handles leading and
;; trailing tabs to allow for right and center alignment.
(define (table-normalize-cell-line line w)
(let ((lst (string->list line))
(let* ((lst (string->list line))
(first-char (if (null? lst) #f (car lst)))
(last-char (if (null? lst) #f (car (reverse lst))))
;; Line without tabs
(len (ansi-string-length line)))
(if (< csl w)
(string-append cs (string-repeat " " (- w csl)))
cs)))
(first-tab (eq? first-char #\tab))
(last-tab (eq? last-char #\tab))
(line0 (if first-tab (substring line 1) line))
(line1 (if last-tab (substring line0 0 (sub1 (string-length line0))) line0))
(len (ansi-string-length line1)))
(if (< len w)
(let* ((miss (- w len))
(do-left-pad first-tab)
(do-right-pad (or (not first-tab) last-tab)))
(string-append line1 (string-repeat " " miss)))
line1)))
;; Pads all lines of this cell to required width
(define (table-normalize-cell c w)
(let loop ((c c)
(r '()))
(if (null? c)
(reverse r)
(loop (cdr c)
(cons (table-normalize-cell-line (car c) w)
r)))))
(map (lambda (line)
(table-normalize-cell-line line w))
c))
;; Returns a row (list) of cells (list of strings) with all strings
;; padded to given column width.