Pass leading and trailing tab characters in paragraph formatting.
This commit is contained in:
parent
5ceec258f9
commit
19daaf7706
1 changed files with 34 additions and 18 deletions
22
ansi.scm
22
ansi.scm
|
@ -149,13 +149,29 @@
|
||||||
(irregex-replace/all (irregex "\x1b\\[[0-9;]*[^0-9;]" 'u) str ""))
|
(irregex-replace/all (irregex "\x1b\\[[0-9;]*[^0-9;]" 'u) str ""))
|
||||||
|
|
||||||
;; Formats string as paragraph of maximum given width while removing
|
;; Formats string as paragraph of maximum given width while removing
|
||||||
;; all ANSI CSI SGR from it.
|
;; all ANSI CSI SGR from it. If the first character is \t, align
|
||||||
|
;; right, if both first and last characters are \t, align center. The
|
||||||
|
;; alignment is not done here, but the \t are added to all lines
|
||||||
|
;; accordingly.
|
||||||
(define (ansi-paragraph-format str width)
|
(define (ansi-paragraph-format str width)
|
||||||
|
(let* ((strl (string->list str))
|
||||||
|
(first-char (car strl))
|
||||||
|
(last-char (car (reverse strl)))
|
||||||
|
(first-tab (eq? first-char #\tab))
|
||||||
|
(last-tab (eq? last-char #\tab)))
|
||||||
(let loop ((words (string-split
|
(let loop ((words (string-split
|
||||||
(ansi-remove str)))
|
(ansi-remove str)))
|
||||||
(res '("")))
|
(res '("")))
|
||||||
(if (null? words)
|
(if (null? words)
|
||||||
(string-intersperse (reverse res) "\n")
|
(string-intersperse
|
||||||
|
(reverse
|
||||||
|
(map
|
||||||
|
(lambda (line)
|
||||||
|
(string-append (if first-tab "\t" "")
|
||||||
|
line
|
||||||
|
(if last-tab "\t" "")))
|
||||||
|
res))
|
||||||
|
"\n")
|
||||||
(let* ((word (car words))
|
(let* ((word (car words))
|
||||||
(wlen (ansi-string-length word))
|
(wlen (ansi-string-length word))
|
||||||
(llen (ansi-string-length (car res))))
|
(llen (ansi-string-length (car res))))
|
||||||
|
@ -167,7 +183,7 @@
|
||||||
""
|
""
|
||||||
" ")
|
" ")
|
||||||
word)
|
word)
|
||||||
(cdr res))))))))
|
(cdr res)))))))))
|
||||||
|
|
||||||
;; Returns a concatenation of all ANSI styles specified by this
|
;; Returns a concatenation of all ANSI styles specified by this
|
||||||
;; module
|
;; module
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue