diff --git a/README.org b/README.org index b0e7fc3..4f3e929 100644 --- a/README.org +++ b/README.org @@ -7,6 +7,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 +- Spinners ** References diff --git a/build.ss b/build.ss index eaa8633..37c6060 100755 --- a/build.ss +++ b/build.ss @@ -5,5 +5,6 @@ (defbuild-script '("fancy/format" "fancy/table" - "fancy/rule") + "fancy/rule" + "fancy/spinner") optimize: #t) diff --git a/fancy/format.ss b/fancy/format.ss index 4f582f6..2163fa4 100644 --- a/fancy/format.ss +++ b/fancy/format.ss @@ -14,8 +14,7 @@ set-graphics-mode set-color parse-markup - remove-markup - spinner) + remove-markup) (import :std/format :std/pregexp @@ -93,14 +92,3 @@ (def (remove-markup text) (pregexp-replace* +re-tags+ text "")) - -(def (spinner i style: (style 'ascii)) - (str (cursor-back 2) - (match style - ('block (string-ref "▖▘▝▗" (modulo i 4))) - ('triangle (string-ref "◢◣◤◥" (modulo i 4))) - ('circle (string-ref "◐◓◑◒" (modulo i 4))) - ('vertical (string-ref "▁▃▄▅▆▇█▇▆▅▄▃" (modulo i 12))) - ('horizontal (string-ref "▉▊▋▌▍▎▏▎▍▌▋▊▉" (modulo i 12))) - ('ascii (string-ref "|/-\\" (modulo i 4)))) - " ")) diff --git a/fancy/spinner.ss b/fancy/spinner.ss new file mode 100644 index 0000000..0c83dc3 --- /dev/null +++ b/fancy/spinner.ss @@ -0,0 +1,23 @@ +(export spinner) + +(import :std/misc/string + :dlozeve/fancy/format) + +(def +spinner-styles+ + '((dots . "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏") + (block . "▖▘▝▗") + (triangle . "◢◣◤◥") + (circle . "◐◓◑◒") + (vertical . "▁▃▄▅▆▇█▇▆▅▄▃") + (horizontal . "▉▊▋▌▍▎▏▎▍▌▋▊▉") + (ascii . "|/-\\"))) + +(def (spinner i text-before text-after style: (style 'dots)) + (def spinner-chars (assgetq style +spinner-styles+)) + (str (cursor-up 1) + (parse-markup text-before) + " " + (string-ref spinner-chars (modulo i (string-length spinner-chars))) + " " + (parse-markup text-after) + "\n"))