Add spinners
This commit is contained in:
parent
13566e5281
commit
cd0e1e7609
4 changed files with 27 additions and 14 deletions
|
@ -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
|
- [[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]]
|
- Table formatting with [[https://unicode-table.com/en/blocks/box-drawing/][Unicode box drawing characters]]
|
||||||
- Horizontal rules
|
- Horizontal rules
|
||||||
|
- Spinners
|
||||||
|
|
||||||
** References
|
** References
|
||||||
|
|
||||||
|
|
3
build.ss
3
build.ss
|
@ -5,5 +5,6 @@
|
||||||
(defbuild-script
|
(defbuild-script
|
||||||
'("fancy/format"
|
'("fancy/format"
|
||||||
"fancy/table"
|
"fancy/table"
|
||||||
"fancy/rule")
|
"fancy/rule"
|
||||||
|
"fancy/spinner")
|
||||||
optimize: #t)
|
optimize: #t)
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
set-graphics-mode
|
set-graphics-mode
|
||||||
set-color
|
set-color
|
||||||
parse-markup
|
parse-markup
|
||||||
remove-markup
|
remove-markup)
|
||||||
spinner)
|
|
||||||
|
|
||||||
(import :std/format
|
(import :std/format
|
||||||
:std/pregexp
|
:std/pregexp
|
||||||
|
@ -93,14 +92,3 @@
|
||||||
|
|
||||||
(def (remove-markup text)
|
(def (remove-markup text)
|
||||||
(pregexp-replace* +re-tags+ 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))))
|
|
||||||
" "))
|
|
||||||
|
|
23
fancy/spinner.ss
Normal file
23
fancy/spinner.ss
Normal file
|
@ -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"))
|
Loading…
Add table
Add a link
Reference in a new issue