Add horizontal rules

This commit is contained in:
Dimitri Lozeve 2021-04-27 21:07:07 +02:00
parent e4b7f7461d
commit 13566e5281
3 changed files with 22 additions and 1 deletions

View file

@ -6,6 +6,7 @@ Fancy pretty-printing utilities for [[https://cons.io/][Gerbil Scheme]].
- [[https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences][ANSI control codes]] for styling and cursor movement
- Table formatting with [[https://unicode-table.com/en/blocks/box-drawing/][Unicode box drawing characters]]
- Horizontal rules
** References

View file

@ -4,5 +4,6 @@
(defbuild-script
'("fancy/format"
"fancy/table")
"fancy/table"
"fancy/rule")
optimize: #t)

19
fancy/rule.ss Normal file
View file

@ -0,0 +1,19 @@
(export rule)
(import :std/misc/string
:dlozeve/fancy/format)
(def (rule text width: (width 80) style: (style 'simple))
(def rule-len (- width (+ 2 (string-length (remove-markup text)))))
(def left-len (1- (quotient rule-len 2)))
(def right-len (1- (+ (remainder rule-len 2) (quotient rule-len 2))))
(def c (match style
('simple #\━)
('double #\═)
('dashed #\╌)))
(str (make-string left-len c)
" "
(parse-markup text)
" "
(make-string right-len c)
"\n"))