Created
December 12, 2009 20:24
-
-
Save kosh04/255040 to your computer and use it in GitHub Desktop.
256colors2.lsp
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
#!/usr/bin/newlisp | |
# original source: | |
# http://frexx.de/xterm-256-notes/data/256colors2.pl | |
;; FIXME: | |
; (define (printf) (print (apply format (args)))) | |
; current newLISP `format' function cannot use. (v.10.1.7) | |
; (format "%2.2x" 0) => ERR | |
; | |
(import "libc.so.6" "printf") | |
# use the resources for colors 0-15 - usually more-or-less a | |
# reproduction of the standard ANSI colors, but possibly more | |
# pleasing shades | |
# colors 16-231 are a 6x6x6 color cube | |
(for (red 0 5) | |
(for (green 0 5) | |
(for (blue 0 5) | |
(printf "\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\" | |
(+ 16 (* red 36) (* green 6) blue) | |
(if (= red 0) 0 (+ (* red 40) 55)) | |
(if (= green 0) 0 (+ (* green 40) 55)) | |
(if (= blue 0) 0 (+ (* blue 40) 55)) )))) | |
# colors 232-255 are a grayscale ramp, intentionally leaving out | |
# black and white | |
(for (gray 0 23) | |
(let (level (+ (* gray 10) 8)) | |
(printf "\x1b]4;%d;rgb:%2.2x/%2.2x/%2.2x\x1b\\" | |
(+ 232 gray) level level level))) | |
# display the colors | |
# first the system ones: | |
(printf "System colors:\n") | |
(for (color 0 7) | |
(printf "\x1b[48;5;%dm " color)) | |
(printf "\x1b[0m\n") | |
(for (color 8 15) | |
(printf "\x1b[48;5;%dm " color)) | |
(printf "\x1b[0m\n\n") | |
# now the color cube | |
(printf "Color cube, 6x6x6:\n") | |
(for (green 0 5) | |
(for (red 0 5) | |
(for (blue 0 5) | |
(printf "\x1b[48;5;%dm " (+ 16 (* red 36) (* green 6) blue))) | |
(printf "\x1b[0m ")) | |
(printf "\n")) | |
# now the grayscale ramp | |
(printf "Grayscale ramp:\n") | |
(for (color 232 255) | |
(printf "\x1b[48;5;%dm " color)) | |
(printf "\x1b[0m\n") | |
(exit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment