Paste number 144140: CHICKEN Scheme ansi-escape-codes egg demonstration

Paste number 144140: CHICKEN Scheme ansi-escape-codes egg demonstration
Pasted by: ewfalor
When:5 years, 3 weeks ago
Share:Tweet this! | http://paste.lisp.org/+337W
Channel:None
Paste contents:
Raw Source | XML | Display As
#!/usr/bin/csi -s
(use posix ansi-escape-sequences srfi-18)

(define *banner*
  (vector 
	"        _      ___  _       ___          __   _      ___      ___       "
	"       / ` )_)  )  / ` )_/  )_  )\\ )    (_ ` / ` )_) )_  )\\/) )_        "
	"      (_. ( ( _(_ (_. /  ) (__ (  (    .__) (_. ( ( (__ (  ( (__        "
	"                                                                        "
	))
(define *height* (vector-length *banner*))

(define *colors*
  '((#xff #x00 #xff) (#xff #x00 #xd4) (#xff #x00 #xaa)
	(#xff #x00 #x80) (#xff #x00 #x55) (#xff #x00 #x2a)
	(#xff #x00 #x00) (#xff #x2a #x00) (#xff #x55 #x00)
	(#xff #x80 #x00) (#xff #xaa #x00) (#xff #xd4 #x00)
	(#xff #xff #x00) (#xd4 #xff #x00) (#xaa #xff #x00)
	(#x80 #xff #x00) (#x55 #xff #x00) (#x2a #xff #x00)
	(#x00 #xff #x00) (#x00 #xff #x2a) (#x00 #xff #x55)
	(#x00 #xff #x80) (#x00 #xff #xaa) (#x00 #xff #xd4)
	(#x00 #xff #xff) (#x00 #xd4 #xff) (#x00 #xaa #xff)
	(#x00 #x80 #xff) (#x00 #x55 #xff) (#x00 #x2a #xff)
	(#x00 #x00 #xff) (#x2a #x00 #xff) (#x55 #x00 #xff)
	(#x80 #x00 #xff) (#xaa #x00 #xff) (#xd4 #x00 #xff)))

(set-buffering-mode! (current-output-port) #:none)

(display (save-cursor-position))
(display (hide-cursor))
(display (set-title "The colors of the rainbow, in your console!"))

(do ((n 0 (add1 n))) ((= n (add1 *height*))) (newline))
(display (cursor-up *height*))

;; print a banner
(do ((j 16 (add1 j))) ((= j 52))
  (do ((k 0 (add1 k))) ((= k 2))
	(do ((i 0 (add1 i))) ((= i *height*))
	  (display (set-text256 `(bold (background ,j)) (string (string-ref (vector-ref *banner* i) (+ k (* 2 (- j 16)))))))
	  (thread-sleep! 0.04)
	  (display (cursor-down 1))
	  (display (cursor-backward 1)))
	(display (cursor-up *height*))
	(display (cursor-forward 1))))

;; adjust the banner's colors to look like a rainbow (in supported terminals)
(let ((rotate-left (lambda (lst) (append (cdr lst) (cons (car lst) '())))))
  (for-each (lambda (i c)
			  (display (set-color256! i (first c) (second c) (third c))) (thread-sleep! .04))
			(iota 36 51 -1) (reverse *colors*))
  (thread-sleep! 0.5)

  (let loop ((j 0) (*colors* *colors*))
	(when (< j 175)
	  ;; cycle the palette
	  (for-each (lambda (i c)
				  (display (set-color256! i (first c) (second c) (third c))))
				(iota 36 16) *colors*)
	  (thread-sleep! 0.04)
	  (loop (add1 j) (rotate-left *colors*)))))

(display (set-title "Cursor movement"))
(display (show-cursor))
(display (restore-cursor-position))
(for-each (lambda (letter)
			(display letter)
			(thread-sleep! 0.25)
			(cursor-forward 1))
		  '("C" "H" "I" "C" "K" "E" "N"))

(display " ")
(for-each (lambda (letter)
			(display (set-text '(bg-black fg-yellow) letter))
			(thread-sleep! 0.25)
			(cursor-forward 1))
		  '("r" "o" "c" "k" "s" "!"))

(display (set-title "Let that sink in for a moment..."))
(thread-sleep! 2.25)
(display (restore-cursor-position))
(display (erase-line))

(display (set-title "What I really meant to say:"))
(for-each (lambda (letter)
			(display letter)
			(thread-sleep! 0.25)
			(cursor-forward 1))
		  '("C" "H" "I" "C" "K" "E" "N"))

(display " ")
(for-each (lambda (letter)
			(display (set-text '(bold bg-red fg-white) letter))
			(thread-sleep! 0.25)
			(cursor-forward 1))
		  '("r" "u" "l" "e" "s" "!"))

(display (restore-cursor-position))
(display (cursor-down (add1 *height*)))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.