Last active
November 21, 2019 10:02
-
-
Save jdz/e42f035569dcee07d25fa83df28472f1 to your computer and use it in GitHub Desktop.
Turns out there was a bug...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Alternative graphics: "⣀⣄⣤⣦⣶⣷⣿" or "⠆⡇⡷⣿" | |
(defun bar (stream width n max &optional (graphics "▏▎▍▌▋▊▉█")) | |
"Draw an N/MAX bar no wider than WIDTH using charecters from GRAPHICS." | |
(declare (type number width n max) | |
(type string graphics)) | |
(assert (<= 1 (length graphics)) | |
(graphics) | |
"Invalid graphics provided: ~S" graphics) | |
(let* ((nchars (length graphics)) | |
(inc (/ 1 nchars 2))) | |
(multiple-value-bind (full part) | |
(truncate (* width (/ n max))) | |
(loop with char = (char graphics (1- nchars)) | |
repeat full | |
do (write-char char stream)) | |
(multiple-value-bind (index rem) | |
(truncate (* nchars (- part inc))) | |
(when (<= 0 rem) | |
(write-char (char graphics index) stream))))) | |
nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment