forked from slope-lang/slope
Adds a terminal color chart to the examples
parent
4ff9f4e6ce
commit
ee9542bff5
@ -0,0 +1,49 @@
|
||||
#! /usr/bin/env slope
|
||||
;;; display some terminal colors
|
||||
;;; This example is a fairly naive way to show colors
|
||||
;;; but gives a basic look at some simple display procedures
|
||||
;;; as well as some basic recursion
|
||||
;;;
|
||||
;;; A good intro project would be to make this use a string
|
||||
;;; buffer instead of lots of prints, which will be more
|
||||
;;; performant. Another upgrade would be to use dark foreground
|
||||
;;; on light background and vice versa.
|
||||
|
||||
(define print-simple-color (lambda (fg bg)
|
||||
(display (string-format "\033[1;%vm%6v\033[0m\033[1;%vm%6v\033[0m" fg fg bg bg))))
|
||||
|
||||
(define print-256-color (lambda (col)
|
||||
(define nl (if (equal? 0 (- (/ col 10) (floor (/ col 10)))) "\n" ""))
|
||||
(display (string-format "\033[1;48;5;%vm%6v\033[0m%v" col col nl))))
|
||||
|
||||
(define loop-256 (lambda (col)
|
||||
(if (< col 256)
|
||||
(begin
|
||||
(print-256-color col)
|
||||
(loop-256 (+ 1 col))))))
|
||||
|
||||
(display "\033[1;7m Simple Color \033[0m\n")
|
||||
(print-simple-color 30 40) ; black
|
||||
(print-simple-color 31 41) ; red
|
||||
(print-simple-color 32 42) ; green
|
||||
(print-simple-color 33 43) ; yellow
|
||||
(print-simple-color 34 44) ; blue
|
||||
(newline)
|
||||
(print-simple-color 35 45) ; magenta
|
||||
(print-simple-color 36 46) ; cyan
|
||||
(print-simple-color 37 47) ; white
|
||||
(print-simple-color 90 100) ; bright black
|
||||
(print-simple-color 91 101) ; bright red
|
||||
(newline)
|
||||
(print-simple-color 92 102) ; bright green
|
||||
(print-simple-color 93 103) ; bright yellow
|
||||
(print-simple-color 94 104) ; bright blue
|
||||
(print-simple-color 95 105) ; bright magenta
|
||||
(print-simple-color 96 106) ; bright cyan
|
||||
(newline)
|
||||
(print-simple-color 97 107) ; bright white
|
||||
(newline)
|
||||
(newline)
|
||||
(display "\033[1;7m 256 Color \033[0m\n")
|
||||
(loop-256 1) ; All 256, as backgrounds
|
||||
(newline)
|
Loading…
Reference in New Issue