public
Last active

256colors2.lsp

  • Download Gist
gistfile1.scm
Scheme
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#!/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)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.