Skip to content

@kosh04 /gist:255040
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
256colors2.lsp
#!/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
Something went wrong with that request. Please try again.