Work on cell lines alignment.
This commit is contained in:
parent
624460132b
commit
3f50d85412
1 changed files with 17 additions and 15 deletions
28
table.scm
28
table.scm
|
@ -139,24 +139,26 @@
|
||||||
;; Normalizes cell line to required width and handles leading and
|
;; Normalizes cell line to required width and handles leading and
|
||||||
;; trailing tabs to allow for right and center alignment.
|
;; trailing tabs to allow for right and center alignment.
|
||||||
(define (table-normalize-cell-line line w)
|
(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)))
|
(first-char (if (null? lst) #f (car lst)))
|
||||||
(last-char (if (null? lst) #f (car (reverse lst))))
|
(last-char (if (null? lst) #f (car (reverse lst))))
|
||||||
;; Line without tabs
|
(first-tab (eq? first-char #\tab))
|
||||||
(len (ansi-string-length line)))
|
(last-tab (eq? last-char #\tab))
|
||||||
(if (< csl w)
|
(line0 (if first-tab (substring line 1) line))
|
||||||
(string-append cs (string-repeat " " (- w csl)))
|
(line1 (if last-tab (substring line0 0 (sub1 (string-length line0))) line0))
|
||||||
cs)))
|
(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
|
;; Pads all lines of this cell to required width
|
||||||
(define (table-normalize-cell c w)
|
(define (table-normalize-cell c w)
|
||||||
(let loop ((c c)
|
(map (lambda (line)
|
||||||
(r '()))
|
(table-normalize-cell-line line w))
|
||||||
(if (null? c)
|
c))
|
||||||
(reverse r)
|
|
||||||
(loop (cdr c)
|
|
||||||
(cons (table-normalize-cell-line (car c) w)
|
|
||||||
r)))))
|
|
||||||
|
|
||||||
;; Returns a row (list) of cells (list of strings) with all strings
|
;; Returns a row (list) of cells (list of strings) with all strings
|
||||||
;; padded to given column width.
|
;; padded to given column width.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue