diff --git a/README.org b/README.org index 6a5ea93..b0e7fc3 100644 --- a/README.org +++ b/README.org @@ -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 diff --git a/build.ss b/build.ss index 8358789..eaa8633 100755 --- a/build.ss +++ b/build.ss @@ -4,5 +4,6 @@ (defbuild-script '("fancy/format" - "fancy/table") + "fancy/table" + "fancy/rule") optimize: #t) diff --git a/fancy/rule.ss b/fancy/rule.ss new file mode 100644 index 0000000..4636432 --- /dev/null +++ b/fancy/rule.ss @@ -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"))