From 40c826b26a5523f163a39cf53ee27c800c835725 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 09:55:49 -0500 Subject: [PATCH 01/18] bugfix --- cl-ansi-text.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cl-ansi-text.lisp b/cl-ansi-text.lisp index 7cba11c..1fc2f14 100644 --- a/cl-ansi-text.lisp +++ b/cl-ansi-text.lisp @@ -268,7 +268,7 @@ extensions to xterm")) (unless (and (integerp (first color)) (integerp (second color)) - (integerp (second color))) + (integerp (third color))) (error "~a must have three integers" color)) (code-from-rgb style From f9f98b95d0e5801131d2317dfe62e9f58323622e Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:31 -0500 Subject: [PATCH 02/18] modernized the tests --- .travis.yml | 50 +++++++++++++++---- README.md | 4 ++ ci-test-run.sh | 15 ------ ...nsi-text-test.asd => cl-ansi-text.test.asd | 2 +- run-tests.lisp | 29 ----------- test/cl-ansi-text-test.lisp | 20 +------- testscr.ros | 16 ++++++ 7 files changed, 62 insertions(+), 74 deletions(-) delete mode 100755 ci-test-run.sh rename cl-ansi-text-test.asd => cl-ansi-text.test.asd (90%) delete mode 100644 run-tests.lisp create mode 100755 testscr.ros diff --git a/.travis.yml b/.travis.yml index 033c340..788c488 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,41 @@ -before_script: - - curl -O -L http://prdownloads.sourceforge.net/sbcl/sbcl-1.2.6-x86-64-linux-binary.tar.bz2 - - tar xjf sbcl-1.2.6-x86-64-linux-binary.tar.bz2 - - pushd sbcl-1.2.6-x86-64-linux/ && sudo bash install.sh && popd - - curl -O -L http://beta.quicklisp.org/quicklisp.lisp - - sbcl --load quicklisp.lisp --eval '(quicklisp-quickstart:install)' --eval '(quit)' - - curl -OL http://ccl.clozure.com/ftp/pub/release/1.10/ccl-1.10-linuxx86.tar.gz - - tar xzf ccl-1.10-linuxx86.tar.gz - - export PATH=`pwd`/ccl:$PATH -# - lx86cl64 -b --load quicklisp.lisp --eval '(progn (quicklisp-quickstart:install) (quit))' +language: common-lisp +sudo: false + +addons: + apt: + packages: + - libc6-i386 + - clisp + - openjdk-7-jre + +env: + global: + - PATH=~/.roswell/bin:$PATH + - ROSWELL_INSTALL_DIR=$HOME/.roswell + matrix: + - LISP=sbcl-bin + - LISP=ccl-bin + - LISP=abcl + - LISP=clisp + - LISP=ecl + - LISP=cmucl + - LISP=alisp + +matrix: + allow_failures: + - env: LISP=clisp + - env: LISP=abcl + - env: LISP=ecl + - env: LISP=cmucl + - env: LISP=alisp + +install: + - curl -L https://raw.githubusercontent.com/snmsts/roswell/release/scripts/install-for-ci.sh | sh + +cache: + directories: + - $HOME/.roswell + - $HOME/.config/common-lisp script: - - ./ci-test-run.sh \ No newline at end of file + - ./testscr.ros diff --git a/README.md b/README.md index 45fad05..8bd039b 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,10 @@ Returns a string with the `white'string denotation preppended and the `reset' st This string will reset ANSI colors +# Running test + +Run `./testscr.ros` with Roswell. You can also manually run the test with +`(ql:quickload :cl-ansi-text.test) (fiveam:run! :cl-ansi-text)`. # Note diff --git a/ci-test-run.sh b/ci-test-run.sh deleted file mode 100755 index 25e8107..0000000 --- a/ci-test-run.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -error=0 -if which sbcl; then - echo "CI run using SBCL" - sbcl --script run-tests.lisp - error=$? -fi - -if which lx86cl64; then - echo "CI run using CCL" - lx86cl64 -b --load run-tests.lisp - error=$(($error+$?)) -fi - -exit $error diff --git a/cl-ansi-text-test.asd b/cl-ansi-text.test.asd similarity index 90% rename from cl-ansi-text-test.asd rename to cl-ansi-text.test.asd index 73cee9c..81a502b 100644 --- a/cl-ansi-text-test.asd +++ b/cl-ansi-text.test.asd @@ -1,4 +1,4 @@ -(asdf:defsystem #:cl-ansi-text-test +(asdf:defsystem #:cl-ansi-text.test :depends-on ( #:cl-colors #:alexandria #:cl-ansi-text #:fiveam) :components ((:module "test" :components diff --git a/run-tests.lisp b/run-tests.lisp deleted file mode 100644 index f369b89..0000000 --- a/run-tests.lisp +++ /dev/null @@ -1,29 +0,0 @@ -#-quicklisp -(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp" - (user-homedir-pathname)))) - (when (probe-file quicklisp-init) - (load quicklisp-init))) - -#+sbcl(require "sb-posix") - -(defparameter *pwd* - (concatenate 'string - (progn #+sbcl(sb-posix:getcwd) - #+ccl(ccl::current-directory-name)) - "/")) - -(push *pwd* asdf:*central-registry*) - - -(ql:quickload '(:cl-colors - :alexandria - :fiveam - - :cl-ansi-text - :cl-ansi-text-test)) - -(let ((result-status (cl-ansi-text-test::ci-run))) - (let ((posix-status - (if result-status 0 1))) - #+sbcl(sb-posix:exit posix-status) - #+ccl (quit posix-status))) diff --git a/test/cl-ansi-text-test.lisp b/test/cl-ansi-text-test.lisp index 20cfc04..0f2b725 100644 --- a/test/cl-ansi-text-test.lisp +++ b/test/cl-ansi-text-test.lisp @@ -8,13 +8,10 @@ :fiveam)) (in-package :cl-ansi-text-test) -(use-package :fiveam) -(use-package :cl-ansi-text) -(def-suite test-suite - :description "test suite.") +(def-suite :cl-ansi-text :description "test suite.") -(in-suite test-suite) +(in-suite :cl-ansi-text) (test basic-color-strings @@ -108,16 +105,3 @@ (equal str (white (cyan (magenta (blue (yellow (green (red (black str)))))))))))) -(defun run-tests () - (let ((results (run 'test-suite))) - (explain! results) - (if (position-if #'(lambda (e) - (eq (type-of e) - 'IT.BESE.FIVEAM::TEST-FAILURE - )) - results) - nil - t))) - -(defun ci-run () - (run-tests)) diff --git a/testscr.ros b/testscr.ros new file mode 100755 index 0000000..0d83252 --- /dev/null +++ b/testscr.ros @@ -0,0 +1,16 @@ +#!/bin/sh +#|-*- mode:lisp -*-|# +#| +exec ros -Q -- $0 "$@" +|# + +(defun main (&rest argv) + (declare (ignorable argv)) + (uiop:quit (if (handler-case + (progn + (ql:quickload :cl-ansi-text.test) + (eval (read-from-string "(every #'fiveam::TEST-PASSED-P (5am:run! :cl-ansi-text))"))) + (serious-condition (c) + (describe c) + (uiop:quit 2))) + 0 1))) From 3f55be27fc969511bd9bbe4a7234824213966ff7 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:34 -0500 Subject: [PATCH 03/18] use cl-colors2 : cl-colors is no longer maintained by tppap --- cl-ansi-text.asd | 2 +- cl-ansi-text.test.asd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cl-ansi-text.asd b/cl-ansi-text.asd index a29781f..c6d0ce5 100644 --- a/cl-ansi-text.asd +++ b/cl-ansi-text.asd @@ -1,5 +1,5 @@ (asdf:defsystem #:cl-ansi-text - :depends-on ( #:cl-colors #:alexandria) + :depends-on ( #:cl-colors2 #:alexandria) :components ((:file "cl-ansi-text")) :name "cl-ansi-text" :version "1.0" diff --git a/cl-ansi-text.test.asd b/cl-ansi-text.test.asd index 81a502b..80f174d 100644 --- a/cl-ansi-text.test.asd +++ b/cl-ansi-text.test.asd @@ -1,5 +1,5 @@ (asdf:defsystem #:cl-ansi-text.test - :depends-on ( #:cl-colors #:alexandria #:cl-ansi-text #:fiveam) + :depends-on ( #:cl-colors2 #:alexandria #:cl-ansi-text #:fiveam) :components ((:module "test" :components ((:file "cl-ansi-text-test")))) From 4cfbe3a56e4efd567af5d24b0c25b7312dbd14a2 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:43 -0500 Subject: [PATCH 04/18] this problem is gone now --- cl-ansi-text.lisp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/cl-ansi-text.lisp b/cl-ansi-text.lisp index 1fc2f14..1f722ea 100644 --- a/cl-ansi-text.lisp +++ b/cl-ansi-text.lisp @@ -25,18 +25,6 @@ #:white)) (in-package :cl-ansi-text) -;;; !!! NOTE TO CCL USERS !!! -;;; -;;; This seems to be *required* to make this compile in CCL. The -;;; reason is that CCL expects to be able to inline on compile, but -;;; structs don't set up that infrastructure by default. -;;; -;;; At least from the thread "Compiler problem, MCL 3.9" by Arthur -;;; Cater around '96. -#+ccl(common-lisp:eval-when (:compile-toplevel :load-toplevel :execute) - (defmethod make-load-form ((obj cl-colors:rgb ) &optional env) - (make-load-form-saving-slots obj))) - (defparameter *enabled* t "Turns on/off the colorization of functions") From aadbb5b936670718d6c2873ce1ba08849080bde0 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:43 -0500 Subject: [PATCH 05/18] moved gen-color-functions into define-colors --- cl-ansi-text.asd | 4 +++- cl-ansi-text.lisp | 25 ------------------------- define-colors.lisp | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 26 deletions(-) create mode 100644 define-colors.lisp diff --git a/cl-ansi-text.asd b/cl-ansi-text.asd index c6d0ce5..aa9c20f 100644 --- a/cl-ansi-text.asd +++ b/cl-ansi-text.asd @@ -1,6 +1,8 @@ (asdf:defsystem #:cl-ansi-text :depends-on ( #:cl-colors2 #:alexandria) - :components ((:file "cl-ansi-text")) + :serial t + :components ((:file "cl-ansi-text") + (:file "define-colors")) :name "cl-ansi-text" :version "1.0" :maintainer "Paul Nathan" diff --git a/cl-ansi-text.lisp b/cl-ansi-text.lisp index 1f722ea..9442db7 100644 --- a/cl-ansi-text.lisp +++ b/cl-ansi-text.lisp @@ -200,31 +200,6 @@ then writes out the string denoting a `reset`. (when *enabled* (format ,stream "~a" +reset-color-string+))))) -(defmacro gen-color-functions (color-names-vector) - `(progn - ,@(map 'list - (lambda (color) - `(defun ,(intern (symbol-name color)) (string &key - (effect :unset) - (style :foreground)) - ,(concatenate - 'string - "Returns a string with the `" (string-downcase color) - "'string denotation preppended and the `reset' string denotation appended. - -*enabled* dynamically controls the function." ) - (concatenate - 'string - (when *enabled* - (format nil "~a" (make-color-string ,color - :effect effect - :style style))) - string - (when *enabled* - (format nil "~a" +reset-color-string+))))) - color-names-vector))) - -(gen-color-functions #.(coerce +term-colors+ 'list)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; RGB color codes for some enhanced terminals diff --git a/define-colors.lisp b/define-colors.lisp new file mode 100644 index 0000000..c6f2e64 --- /dev/null +++ b/define-colors.lisp @@ -0,0 +1,17 @@ + +(in-package :cl-ansi-text) + +(defmacro define-colors () + `(progn + ,@(map 'list + (lambda (color) + `(defun ,(intern (symbol-name color)) (string &key (effect :unset) (style :foreground)) + ,(format nil "Returns a string decolated in ~(~a~)." color) + (with-output-to-string (s) + (with-color (,color :stream s :effect effect :style style) + (write-string string s))))) + +term-colors+))) + +(define-colors) + + From 70d83cc8b1ca7b2fcbbb763290384bd5b22776d0 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:43 -0500 Subject: [PATCH 06/18] major rewrite: support each color mode explicitly, cleaner code --- cl-ansi-text.asd | 1 + cl-ansi-text.lisp | 248 ------------------- src/cl-ansi-text.lisp | 221 +++++++++++++++++ define-colors.lisp => src/define-colors.lisp | 0 test/cl-ansi-text-test.lisp | 37 ++- 5 files changed, 238 insertions(+), 269 deletions(-) delete mode 100644 cl-ansi-text.lisp create mode 100644 src/cl-ansi-text.lisp rename define-colors.lisp => src/define-colors.lisp (100%) diff --git a/cl-ansi-text.asd b/cl-ansi-text.asd index aa9c20f..85bc528 100644 --- a/cl-ansi-text.asd +++ b/cl-ansi-text.asd @@ -1,6 +1,7 @@ (asdf:defsystem #:cl-ansi-text :depends-on ( #:cl-colors2 #:alexandria) :serial t + :pathname "src/" :components ((:file "cl-ansi-text") (:file "define-colors")) :name "cl-ansi-text" diff --git a/cl-ansi-text.lisp b/cl-ansi-text.lisp deleted file mode 100644 index 9442db7..0000000 --- a/cl-ansi-text.lisp +++ /dev/null @@ -1,248 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;;; Paul Nathan 2013 -;;;; cl-ansi-text.lisp -;;;; -;;;; Portions of this code were written by taksatou under the -;;;; cl-rainbow name. -;;;; -;;;; A library to produce ANSI escape sequences. Particularly, -;;;; produces colorized text on terminals - -(defpackage :cl-ansi-text - (:use :common-lisp) - (:export - #:with-color - #:make-color-string - #:+reset-color-string+ - #:*enabled* - #:black - #:red - #:green - #:yellow - #:blue - #:magenta - #:cyan - #:white)) -(in-package :cl-ansi-text) - -(defparameter *enabled* t - "Turns on/off the colorization of functions") - -(defparameter +reset-color-string+ - (concatenate 'string (list (code-char 27) #\[ #\0 #\m)) - "This string will reset ANSI colors") - -(defvar +cl-colors+ - (vector - cl-colors:+black+ - cl-colors:+red+ - cl-colors:+green+ - cl-colors:+yellow+ - cl-colors:+blue+ - cl-colors:+magenta+ - cl-colors:+cyan+ - cl-colors:+white+) - "CL-COLORS colors") - -(eval-when (:compile-toplevel :load-toplevel :execute) - (defparameter +term-colors+ - (vector - :black - :red - :green - :yellow - :blue - :magenta - :cyan - :white) - "Basic colors")) - -(defparameter +text-style+ - '((:foreground . 30) - (:background . 40)) - "One or the other. Not an ANSI effect") - -(defparameter +term-effects+ - '((:unset . t) - (:reset . 0) - (:bright . 1) - (:italic . 3) - (:underline . 4) - (:blink . 5) - (:inverse . 7) - (:hide . 8) - (:normal . 22) - (:framed . 51) - (:encircled . 52) - (:overlined . 53) - (:not-framed-or-circled . 54) - (:not-overlined . 55)) - "ANSI terminal effects") - -(defun eq-colors (a b) - "Equality for cl-colors" - - ;; CL-COLORS LIB! - - ;; eql, equal doesn't quite work for compiled cl-colors on CCL - (and - (= (cl-colors:rgb-red a) - (cl-colors:rgb-red b)) - (= (cl-colors:rgb-green a) - (cl-colors:rgb-green b)) - (= (cl-colors:rgb-blue a) - (cl-colors:rgb-blue b)))) - -(defun cl-colors-to-ansi (color) - (position color +cl-colors+ :test #'eq-colors)) - -(defun term-colors-to-ansi (color) - (position color +term-colors+)) - - - -;; Find-X-code is the top-level interface for code-finding - -(defun find-color-code (color) - "Find the list denoting the color" - (typecase color - ;; Did we get a cl-color that we know about? - (cl-colors:rgb (cl-colors-to-ansi color)) - (symbol (term-colors-to-ansi color)))) - -(defun find-effect-code (effect) - "Returns the number for the text effect OR -t if no effect should be used OR -nil if the effect is unknown. - -effect should be a member of +term-effects+" - (cdr (assoc effect +term-effects+))) - -(defun find-style-code (style) - (cdr (assoc style +text-style+))) - -(defun rgb-code-p (color) - (typecase color - (list t) - (integer t))) - -(defun generate-control-string (code) - "General ANSI code" - (format nil "~c[~a" (code-char #o33) code)) - -(defun generate-color-string (code) - ;; m is the action character for color - (format nil "~am" (generate-control-string code))) - -(defun build-control-string (color - &optional - (effect :unset) - (style :foreground)) - "Color (cl-color or term-color) -Effect -Style" - (let ((effect-code (find-effect-code effect)) - (color-code (find-color-code color)) - (style-code (find-style-code style))) - - ;; Nil here indicates an error - (assert effect-code) - (assert style-code) - - ;; Returns a list for inspection; next layer turns it back into a - ;; string. - (concatenate - 'list - ;; We split between RGB and 32-color here; this preserves the - ;; interface without cluttering the 32-color code up. - ;; - (let ((codes nil)) - (unless (eq effect-code t) - (setf codes (cons effect-code codes))) - (if (rgb-code-p color) - (setf codes (cons (rgb-color-code color style) codes)) - (setf codes (cons (+ style-code color-code) codes))) - - (generate-color-string (format nil "~{~A~^;~}" codes)))))) - -;; Public callables. - -(defun make-color-string (color &key - (effect :unset) - (style :foreground) - ((enabled *enabled*) *enabled*)) - "Takes either a cl-color or a list denoting the ANSI colors and -returns a string sufficient to change to the given color. - -Will be dynamically controlled by *enabled* unless manually specified -otherwise" - (when *enabled* - (concatenate 'string - (build-control-string color effect style)))) - -(defmacro with-color ((color &key - (stream t) - (effect :unset) - (style :foreground)) - &body body) - "Writes out the string denoting a switch to `color`, executes body, -then writes out the string denoting a `reset`. - -*enabled* dynamically controls expansion.." - `(progn - (when *enabled* - (format ,stream "~a" (make-color-string ,color - :effect ,effect - :style ,style))) - (unwind-protect - (progn - ,@body) - (when *enabled* - (format ,stream "~a" +reset-color-string+))))) - - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;;; RGB color codes for some enhanced terminals - -;;; http://www.frexx.de/xterm-256-notes/ -(defun rgb-to-ansi (red green blue) - (let ((ansi-domain (mapcar #'(lambda (x) - (floor (* 6 (/ x 256.0)))) - (list red green blue)))) - (+ 16 - (* 36 (first ansi-domain)) - (* 6 (second ansi-domain)) - (third ansi-domain)))) - -(defun code-from-rgb (style red green blue) - (format nil "~d;5;~d" - (if (eql style :foreground) 38 48) - (rgb-to-ansi red green blue))) - - -(defgeneric rgb-color-code (color &optional style) - (:documentation - "Returns the 256-color code suitable for rendering on the Linux -extensions to xterm")) - -(defmethod rgb-color-code ((color list) &optional (style :foreground)) - (unless (consp color) - (error "~a must be a three-integer list" color)) - - (unless (and (integerp (first color)) - (integerp (second color)) - (integerp (third color))) - (error "~a must have three integers" color)) - - (code-from-rgb style - (first color) - (second color) - (third color))) - -(defmethod rgb-color-code ((color integer) &optional (style :foreground)) - ;; Takes RGB integer ala Web integers - (code-from-rgb style - ;; classic bitmask - (ash (logand color #xff0000) -16) - (ash (logand color #x00ff00) -8) - (logand color #x0000ff))) diff --git a/src/cl-ansi-text.lisp b/src/cl-ansi-text.lisp new file mode 100644 index 0000000..93fe28b --- /dev/null +++ b/src/cl-ansi-text.lisp @@ -0,0 +1,221 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; Paul Nathan 2013 +;;;; cl-ansi-text.lisp +;;;; +;;;; Portions of this code were written by taksatou under the +;;;; cl-rainbow name. +;;;; +;;;; A library to produce ANSI escape sequences. Particularly, +;;;; produces colorized text on terminals + +(defpackage :cl-ansi-text + (:use :common-lisp) + (:export + #:with-color + #:make-color-string + #:+reset-color-string+ + #:*enabled* + #:black + #:red + #:green + #:yellow + #:blue + #:magenta + #:cyan + #:white + #:*color-mode*)) +(in-package :cl-ansi-text) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; constants + +(defvar *enabled* t + "Turns on/off the colorization of functions") + +(declaim (type (member :3bit :8bit :24bit) *color-mode*)) +(defvar *color-mode* :3bit + "Changes the mode used to encode the color") + +(defvar +reset-color-string+ + (concatenate 'string (list (code-char 27) #\[ #\0 #\m)) + "This string will reset ANSI colors") + +(defvar +cl-colors-basic-colors+ + (vector + cl-colors:+black+ + cl-colors:+red+ + cl-colors:+green+ + cl-colors:+yellow+ + cl-colors:+blue+ + cl-colors:+magenta+ + cl-colors:+cyan+ + cl-colors:+white+) + "CL-COLORS basic colors") + +(defvar +term-colors+ + (vector + :black + :red + :green + :yellow + :blue + :magenta + :cyan + :white) + "Basic colors") + +(defvar +text-style+ + '((:foreground . 30) + (:background . 40)) + "One or the other. Not an ANSI effect") + +(defvar +term-effects+ + '((:unset . t) + (:reset . 0) + (:bright . 1) + (:italic . 3) + (:underline . 4) + (:blink . 5) + (:inverse . 7) + (:hide . 8) + (:normal . 22) + (:framed . 51) + (:encircled . 52) + (:overlined . 53) + (:not-framed-or-circled . 54) + (:not-overlined . 55)) + "ANSI terminal effects") + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defun find-effect-code (effect) + "Returns the number for the text effect OR +t if no effect should be used OR +nil if the effect is unknown. + +effect should be a member of +term-effects+" + (cdr (assoc effect +term-effects+))) + +(defun find-style-code (style) + (cdr (assoc style +text-style+))) + +;; Public callables. + +(defun make-color-string (color &key + (effect :unset) + (style :foreground) + ((enabled *enabled*) *enabled*)) + "Takes either a cl-color or a list denoting the ANSI colors and +returns a string sufficient to change to the given color. + +Will be dynamically controlled by *enabled* unless manually specified +otherwise" + (when *enabled* + (let ((effect-code (find-effect-code effect))) + ;; Nil here indicates an error + (assert effect-code) + (let ((codes nil)) + (unless (eq effect-code t) + (push effect-code codes)) + + ;; on 3bit, a list containing an integer in 30 - 37, 40 - 47. + ;; on 8bit, a list containing 5 and an integer. 38;5;n + ;; on 24bit, a list containing 2 and 3 more integers (r,g,b). 38;2;r;g;b + (setf codes (append (rgb-color-code color style) codes)) + (format nil "~c[~{~A~^;~}m" (code-char #o33) codes))))) + +(defmacro with-color ((color &key + (stream t) + (effect :unset) + (style :foreground)) + &body body) + "Writes out the string denoting a switch to `color`, executes body, +then writes out the string denoting a `reset`. + +*enabled* dynamically controls expansion.." + `(progn + (when *enabled* + (format ,stream "~a" (make-color-string ,color + :effect ,effect + :style ,style))) + (unwind-protect + (progn + ,@body) + (when *enabled* + (format ,stream "~a" +reset-color-string+))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; color handling + +(defgeneric rgb-color-code (color &optional style) + (:documentation + "Returns a list of codes suitable for the current color mode.")) + +(defmethod rgb-color-code ((color list) &optional (style :foreground)) + (assert (and (= 3 (length color)) + (every #'realp color) + (every (lambda (x) (<= 0 x 256)) color)) + nil "~a must be a list of numbers in [0,256]" color) + (rgb-color-code (apply #'cl-colors:rgb (mapcar (lambda (x) (/ x 256)) color)) + style)) + +(defmethod rgb-color-code ((color integer) &optional (style :foreground)) + "Takes RGB integer ala Web integers" + (rgb-color-code (cl-colors:rgb + ;; classic bitmask + (/ (ash (logand color #xff0000) -16) 256) + (/ (ash (logand color #x00ff00) -8) 256) + (/ (logand color #x0000ff) 256)) + style)) + +(defmethod rgb-color-code ((color string) &optional (style :foreground)) + "Takes RGB integer ala Web integers" + (rgb-color-code (cl-colors:hex-to-rgb color) + style)) + +(defmethod rgb-color-code ((color cl-colors:rgb) &optional (style :foreground)) + (code-from-rgb color style)) + +(defmethod rgb-color-code ((color cl-colors:hsv) &optional (style :foreground)) + (code-from-rgb (cl-colors:hsv-to-rgb color) style)) + +(defmethod rgb-color-code ((color symbol) &optional (style :foreground)) + (code-from-rgb (aref +cl-colors-basic-colors+ (position color +term-colors+)) style)) + +(defun code-from-rgb (color style) + (ecase *color-mode* + (:3bit + (list (+ (find-style-code style) ; 30 or 40 + ;; 0-7 + (rgb-to-ansi-3bit color)))) + (:8bit + (list (+ (find-style-code style) 8) ; 38 or 48 + 5 + (rgb-to-ansi-8bit color))) + (:24bit + (list (+ (find-style-code style) 8) + 2 + (ceiling (* 255 (cl-colors:rgb-red color))) + (ceiling (* 255 (cl-colors:rgb-green color))) + (ceiling (* 255 (cl-colors:rgb-blue color))))))) + +(defun rgb-to-ansi-3bit (color) + "find the closest color from +cl-colors-basic-colors+" + (labels ((square (x) + (* x x)) + (distance (color2) + (+ (square (- (cl-colors:rgb-red color) (cl-colors:rgb-red color2))) + (square (- (cl-colors:rgb-green color) (cl-colors:rgb-green color2))) + (square (- (cl-colors:rgb-blue color) (cl-colors:rgb-blue color2)))))) + (position (reduce (lambda (a b) + (if (< (distance a) (distance b)) + a b)) + +cl-colors-basic-colors+) + +cl-colors-basic-colors+))) + +(defun rgb-to-ansi-8bit (color) + "http://www.frexx.de/xterm-256-notes/" + (+ 16 + (* 36 (min 5 (floor (* 6 (cl-colors:rgb-red color))))) + (* 6 (min 5 (floor (* 6 (cl-colors:rgb-green color))))) + (* 1 (min 5 (floor (* 6 (cl-colors:rgb-blue color))))))) diff --git a/define-colors.lisp b/src/define-colors.lisp similarity index 100% rename from define-colors.lisp rename to src/define-colors.lisp diff --git a/test/cl-ansi-text-test.lisp b/test/cl-ansi-text-test.lisp index 0f2b725..9ba01c1 100644 --- a/test/cl-ansi-text-test.lisp +++ b/test/cl-ansi-text-test.lisp @@ -13,28 +13,26 @@ (in-suite :cl-ansi-text) +(defun make-color-string-as-list (&rest args) + (coerce (apply #'cl-ansi-text:make-color-string args) 'list)) (test basic-color-strings "Test the basic stuff" (is (equal '(#\Esc #\[ #\3 #\1 #\m) - (cl-ansi-text::build-control-string :red :unset :foreground))) + (make-color-string-as-list :red :effect :unset :style :foreground))) (is (equal '(#\Esc #\[ #\4 #\1 #\m) - (cl-ansi-text::build-control-string :red :unset :background))) + (make-color-string-as-list :red :effect :unset :style :background))) (is (equal '(#\Esc #\[ #\4 #\2 #\; #\1 #\m) - (cl-ansi-text::build-control-string :green :bright :background)))) + (make-color-string-as-list :green :effect :bright :style :background)))) (test enabled-connectivity "Test *enabled*'s capability" (is (equal '(#\Esc #\[ #\3 #\1 #\m) (let ((*enabled* t)) - (concatenate - 'list - (cl-ansi-text:make-color-string :red))))) + (make-color-string-as-list :red)))) (is (equal '() (let ((*enabled* nil)) - (concatenate - 'list - (cl-ansi-text:make-color-string :red))))) + (make-color-string-as-list :red)))) (is (equal "hi" (let ((*enabled* nil)) (with-output-to-string (s) @@ -48,18 +46,15 @@ (test rgb-suite "Test RGB colors" - (is (equal '(#\Esc #\[ #\3 #\8 #\; #\5 #\; #\2 #\1 #\4 #\m) - (cl-ansi-text::build-control-string #xFFAA00 - :unset :foreground))) - (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\2 #\1 #\4 #\m) - (cl-ansi-text::build-control-string #xFFAA00 - :unset :background))) - (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\1 #\6 #\m) - (cl-ansi-text::build-control-string #x000000 - :unset :background))) - (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\2 #\3 #\1 #\m) - (cl-ansi-text::build-control-string #xFFFFFF - :unset :background)))) + (let ((*color-mode* :8bit)) + (is (equal '(#\Esc #\[ #\3 #\8 #\; #\5 #\; #\2 #\1 #\4 #\m) + (make-color-string-as-list #xFFAA00 :effect :unset :style :foreground))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\2 #\1 #\4 #\m) + (make-color-string-as-list #xFFAA00 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\1 #\6 #\m) + (make-color-string-as-list #x000000 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\2 #\3 #\1 #\m) + (make-color-string-as-list #xFFFFFF :effect :unset :style :background))))) (test color-named-functions (let ((str "Test string.")) From 52549ee01b9609a540ef71c276f3aa44e6c01cd5 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:43 -0500 Subject: [PATCH 07/18] use truecolor by default --- src/cl-ansi-text.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cl-ansi-text.lisp b/src/cl-ansi-text.lisp index 93fe28b..0736f86 100644 --- a/src/cl-ansi-text.lisp +++ b/src/cl-ansi-text.lisp @@ -33,7 +33,7 @@ "Turns on/off the colorization of functions") (declaim (type (member :3bit :8bit :24bit) *color-mode*)) -(defvar *color-mode* :3bit +(defvar *color-mode* :24bit "Changes the mode used to encode the color") (defvar +reset-color-string+ From 621fcfa8bc336b9546ad2c644a4497a62e20e0af Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Sun, 8 Dec 2019 15:04:43 -0500 Subject: [PATCH 08/18] test more color options --- test/cl-ansi-text-test.lisp | 66 ++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/test/cl-ansi-text-test.lisp b/test/cl-ansi-text-test.lisp index 9ba01c1..5ed2e29 100644 --- a/test/cl-ansi-text-test.lisp +++ b/test/cl-ansi-text-test.lisp @@ -18,34 +18,47 @@ (test basic-color-strings "Test the basic stuff" - (is (equal '(#\Esc #\[ #\3 #\1 #\m) - (make-color-string-as-list :red :effect :unset :style :foreground))) - (is (equal '(#\Esc #\[ #\4 #\1 #\m) - (make-color-string-as-list :red :effect :unset :style :background))) - (is (equal '(#\Esc #\[ #\4 #\2 #\; #\1 #\m) - (make-color-string-as-list :green :effect :bright :style :background)))) + (let ((*color-mode* :3bit)) + (is (equal '(#\Esc #\[ #\3 #\1 #\m) + (make-color-string-as-list :red :effect :unset :style :foreground))) + (is (equal '(#\Esc #\[ #\4 #\1 #\m) + (make-color-string-as-list :red :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\2 #\; #\1 #\m) + (make-color-string-as-list :green :effect :bright :style :background))))) (test enabled-connectivity "Test *enabled*'s capability" - (is (equal '(#\Esc #\[ #\3 #\1 #\m) - (let ((*enabled* t)) - (make-color-string-as-list :red)))) - (is (equal '() - (let ((*enabled* nil)) - (make-color-string-as-list :red)))) - (is (equal "hi" - (let ((*enabled* nil)) - (with-output-to-string (s) - (with-color (:red :stream s) (format s "hi")))))) - (is (equal '(#\Esc #\[ #\3 #\1 #\m #\T #\e #\s #\t #\! #\Esc #\[ #\0 #\m) - (concatenate - 'list - (with-output-to-string (s) - (with-color (:red :stream s) - (format s "Test!"))))))) + (let ((*color-mode* :3bit)) + (is (equal '(#\Esc #\[ #\3 #\1 #\m) + (let ((*enabled* t)) + (make-color-string-as-list :red)))) + (is (equal '() + (let ((*enabled* nil)) + (make-color-string-as-list :red)))) + (is (equal "hi" + (let ((*enabled* nil)) + (with-output-to-string (s) + (with-color (:red :stream s) (format s "hi")))))) + (is (equal '(#\Esc #\[ #\3 #\1 #\m #\T #\e #\s #\t #\! #\Esc #\[ #\0 #\m) + (concatenate + 'list + (with-output-to-string (s) + (with-color (:red :stream s) + (format s "Test!")))))))) (test rgb-suite "Test RGB colors" + (let ((*color-mode* :3bit)) + (is (equal '(#\Esc #\[ #\3 #\1 #\m) + (make-color-string-as-list #xFF0000 :effect :unset :style :foreground))) + (is (equal '(#\Esc #\[ #\4 #\2 #\m) + (make-color-string-as-list #x00FF00 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\4 #\m) + (make-color-string-as-list #x0000FF :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\0 #\m) + (make-color-string-as-list #x000000 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\7 #\m) + (make-color-string-as-list #xFFFFFF :effect :unset :style :background)))) (let ((*color-mode* :8bit)) (is (equal '(#\Esc #\[ #\3 #\8 #\; #\5 #\; #\2 #\1 #\4 #\m) (make-color-string-as-list #xFFAA00 :effect :unset :style :foreground))) @@ -54,6 +67,15 @@ (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\1 #\6 #\m) (make-color-string-as-list #x000000 :effect :unset :style :background))) (is (equal '(#\Esc #\[ #\4 #\8 #\; #\5 #\; #\2 #\3 #\1 #\m) + (make-color-string-as-list #xFFFFFF :effect :unset :style :background)))) + (let ((*color-mode* :24bit)) + (is (equal '(#\Esc #\[ #\3 #\8 #\; #\2 #\; #\2 #\5 #\5 #\; #\1 #\7 #\0 #\; #\0 #\m) + (make-color-string-as-list #xFFAA00 :effect :unset :style :foreground))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\2 #\; #\2 #\5 #\5 #\; #\1 #\7 #\0 #\; #\0 #\m) + (make-color-string-as-list #xFFAA00 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\2 #\; #\0 #\; #\0 #\; #\0 #\m) + (make-color-string-as-list #x000000 :effect :unset :style :background))) + (is (equal '(#\Esc #\[ #\4 #\8 #\; #\2 #\; #\2 #\5 #\5 #\; #\2 #\5 #\5 #\; #\2 #\5 #\5 #\m) (make-color-string-as-list #xFFFFFF :effect :unset :style :background))))) (test color-named-functions From 36d13c5e96fad7534dc30591f665b66028a27990 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 01:03:04 -0500 Subject: [PATCH 09/18] types --- src/cl-ansi-text.lisp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/cl-ansi-text.lisp b/src/cl-ansi-text.lisp index 0736f86..cfd0661 100644 --- a/src/cl-ansi-text.lisp +++ b/src/cl-ansi-text.lisp @@ -11,6 +11,7 @@ (defpackage :cl-ansi-text (:use :common-lisp) (:export + #:color-specifier #:with-color #:make-color-string #:+reset-color-string+ @@ -23,7 +24,8 @@ #:magenta #:cyan #:white - #:*color-mode*)) + #:*color-mode* + #:color-string)) (in-package :cl-ansi-text) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -86,6 +88,33 @@ (:not-overlined . 55)) "ANSI terminal effects") +(defun color-string-p (string) + (every (lambda (c) + (member c '(#\# #\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9 + #\a #\b #\c #\d #\e #\f #\A #\B #\C #\D #\E #\F))) + string)) + +(deftype color-specifier () + `(or unsigned-byte + (cons (real 0 256) + (cons (real 0 256) + (cons (real 0 256) + nil))) + cl-colors:rgb + cl-colors:hsv + term-colors + color-string)) + +(deftype color-string () + `(and (or (string 3) + (string 4) + (string 6) + (string 7)) + (satisfies color-string-p))) + +(deftype term-colors () + `(member :black :red :green :yellow :blue :magenta :cyan :white)) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun find-effect-code (effect) @@ -110,6 +139,7 @@ returns a string sufficient to change to the given color. Will be dynamically controlled by *enabled* unless manually specified otherwise" + (declare (type color-specifier color)) (when *enabled* (let ((effect-code (find-effect-code effect))) ;; Nil here indicates an error From 14e74577847be93d29ce96b0b24b93b4a0f6308a Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 01:03:11 -0500 Subject: [PATCH 10/18] documentation --- README.md | 150 +++++++++++++++++++++++------------------- src/cl-ansi-text.lisp | 25 +++---- 2 files changed, 98 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index 8bd039b..9f56057 100644 --- a/README.md +++ b/README.md @@ -3,39 +3,57 @@ Because color in your terminal is nice. [![Build Status](https://travis-ci.org/pnathan/cl-ansi-text.svg?branch=master)](https://travis-ci.org/pnathan/cl-ansi-text) +Installation: `(ql:quickload :cl-ansi-text)` + ## Usage example - -```lisp -* (ql:quickload :cl-ansi-text) -;To load "cl-ansi-text": -; Load 1 ASDF system: -; cl-ansi-text -;; Loading "cl-ansi-text" -; => (:CL-ANSI-TEXT) -``` -The main macro is called `with-color`, which creates an enviroment where everything that is put on `stream` gets colored according to `color`. Color options are `:black`, `:red`, `:green`, `:yellow`, `:blue`, `:magenta`, `:cyan` and `:white`. You can also use a color structure from `CL-COLORS`, like `cl-colors:+red+`. +The main macro is `with-color`, which creates an enviroment where everything that is put on `stream` gets colored according to `color`. + +Color options comes in several forms. + +### Keyword Symbol + +Basic 8 colors in the 3-bit color mode are supported, which are `:black`, `:red`, `:green`, `:yellow`, `:blue`, `:magenta`, `:cyan` and `:white`. ```lisp -* (import 'cl-ansi-text:with-color) -; => T * (with-color (:red) (princ "Gets printed red...") (princ "and this too!")) ; Gets printed red...and this too! ; => "and this too!" ``` +### `CL-COLORS2:RGB` and `CL-COLORS2:HSV` object + +These are color structures from `CL-COLORS2` (a maintained fork of `CL-COLORS`). +`CL-COLORS2` has several constants e.g. `cl-colors:+red+` that holds the corresponding color values. +`CL-COLORS2` also supports useful blending operations on colors. +Note that `CL-COLORS2` library provides a package `CL-COLORS`, not `CL-COLORS2`. + +### Hex representation + +These are CSS-style color strings such as `"#FF0000"`. + +### Integer as a 24-bit color + +It treats an integer as a hex string. +The bottom 8 bit is used for the blue, the 8th to 16th bits are used for green, +the 16th to 24th bits are used for red. +Remaining bits are ignored. + +### List of numbers as a 24-bit color + +It takes a list of three numbers (RGB) between 0 and 256. + +## Function interface for printing in specific colors + +We provide shorthand functions for generating a colored strings: -There are also functions with the name of the colors, that return the string, colored: ```lisp -* (import 'cl-ansi-text:yellow) -; => T * (yellow "Yellow string") ; => "Yellow string" * (princ (yellow "String with yellow background" :style :background)) ; "String with yellow background" ; => "String with yellow background" -* (import 'cl-ansi-text:red) -; => T * (princ (concatenate 'string @@ -43,7 +61,9 @@ There are also functions with the name of the colors, that return the string, co ; Five test results went terribly wrong! ; => "Five test results went terribly wrong!" ``` -At any point, you can bind the `*enabled*` special variable to `nil`, and anything inside that binding will not be printed colorfully: + +You can bind the `*enabled*` special variable to `nil` to control the colorization: + ```lisp * (let (cl-ansi-text:*enabled*) (princ (red "This string is printed normally"))) @@ -51,77 +71,75 @@ At any point, you can bind the `*enabled*` special variable to `nil`, and anythi # API +## *Type* color-specifier + +``` lisp +(or unsigned-byte + (cons (real 0 256) + (cons (real 0 256) + (cons (real 0 256) + nil))) + cl-colors:rgb + cl-colors:hsv + term-colors + color-string) +``` -## BLUE - -Returns a string with the `blue'string denotation preppended and the `reset' string denotation appended. - -*enabled* dynamically controls the function. - -## MAGENTA - -Returns a string with the `magenta'string denotation preppended and the `reset' string denotation appended. - -*enabled* dynamically controls the function. - -## CYAN - -Returns a string with the `cyan'string denotation preppended and the `reset' string denotation appended. - -*enabled* dynamically controls the function. - -## GREEN - -Returns a string with the `green'string denotation preppended and the `reset' string denotation appended. - -*enabled* dynamically controls the function. - -## WITH-COLOR +## *Type* term-colors -Writes out the string denoting a switch to `color`, executes body, -then writes out the string denoting a `reset`. +``` lisp +(member :black :red :green :yellow :blue :magenta :cyan :white) +``` -*enabled* dynamically controls expansion.. +## *Type* color-string -## YELLOW +A string of length 3, 4, 6, or 7, that optionally starts with a `#`, and +the rest consists of 3 or 6 hexademical alphadigits (case-insensitive). -Returns a string with the `yellow'string denotation preppended and the `reset' string denotation appended. +## *Macro* with-color -*enabled* dynamically controls the function. +``` lisp +with-color (color &key (stream t) (effect :unset) (style :foreground)) &body body +``` -## BLACK +Writes out the ANSI escape code string +denoting `effect`, `style`, and a switch to `color`, then executes `body`, +then writes out the string that resets the decoration. -Returns a string with the `black'string denotation preppended and the `reset' string denotation appended. +## *Function* make-color-string -*enabled* dynamically controls the function. +``` lisp +make-color-string color &key (effect :unset) (style :foreground) enabled +``` -## *ENABLED* +Takes an object of `color-specifier` and returns a string sufficient to change to the given color. -Turns on/off the colorization of functions +Colorization is controlled by *enabled* unless manually specified otherwise by `:enabled` keyword. -## MAKE-COLOR-STRING +## *Function* black, red, green, yellow, blue, magenta, cyan, white -Takes either a cl-color or a list denoting the ANSI colors and -returns a string sufficient to change to the given color. +Shortcut functions that takes a single argument, `string`, and returns a string +decorated by the corresponding color. -Will be dynamically controlled by *enabled* unless manually specified -otherwise +## *Special variable* `*enabled*` -## RED +Turns on/off the colorization. -Returns a string with the `red'string denotation preppended and the `reset' string denotation appended. +## *Special variable* `*color-mode*` -*enabled* dynamically controls the function. +Controls the way `make-color-string` emits the color code. -## WHITE +It should be one of the following keyword symbols: `:3bit`, `:8bit`, `:24bit`. +The specified color is converted to the nearest color in the color space. +The default value is `:8bit`. -Returns a string with the `white'string denotation preppended and the `reset' string denotation appended. +Note that the actual appearance of the screen in the `:3bit` mode may be affected by +the terminal setting -- For example, many terminals do not use `FF0000` for the red. -*enabled* dynamically controls the function. +## *Constant* `+reset-color-string+` -## +RESET-COLOR-STRING+ +A constant string that resets the color state of the terminal. -This string will reset ANSI colors # Running test diff --git a/src/cl-ansi-text.lisp b/src/cl-ansi-text.lisp index cfd0661..a8edcd0 100644 --- a/src/cl-ansi-text.lisp +++ b/src/cl-ansi-text.lisp @@ -32,15 +32,21 @@ ;; constants (defvar *enabled* t - "Turns on/off the colorization of functions") + "Turns on/off the colorization.") (declaim (type (member :3bit :8bit :24bit) *color-mode*)) (defvar *color-mode* :24bit - "Changes the mode used to encode the color") + "Controls the way `make-color-string` emits the color code. + +It should be one of the following keyword symbols: `:3bit`, `:8bit`, `:24bit`. +The specified color is converted to the nearest color in the color space. + +Note that the actual appearance of the screen in the `:3bit` mode may be affected by +the terminal setting -- For example, many terminals do not use `FF0000` for the red.") (defvar +reset-color-string+ (concatenate 'string (list (code-char 27) #\[ #\0 #\m)) - "This string will reset ANSI colors") + "A constant string that resets the color state of the terminal.") (defvar +cl-colors-basic-colors+ (vector @@ -134,11 +140,9 @@ effect should be a member of +term-effects+" (effect :unset) (style :foreground) ((enabled *enabled*) *enabled*)) - "Takes either a cl-color or a list denoting the ANSI colors and -returns a string sufficient to change to the given color. + "Takes an object of `color-specifier` and returns a string sufficient to change to the given color. -Will be dynamically controlled by *enabled* unless manually specified -otherwise" +Colorization is controlled by *enabled* unless manually specified otherwise by `:enabled` keyword." (declare (type color-specifier color)) (when *enabled* (let ((effect-code (find-effect-code effect))) @@ -159,10 +163,9 @@ otherwise" (effect :unset) (style :foreground)) &body body) - "Writes out the string denoting a switch to `color`, executes body, -then writes out the string denoting a `reset`. - -*enabled* dynamically controls expansion.." + "Writes out the ANSI escape code string +denoting `effect`, `style`, and a switch to `color`, then executes `body`, +then writes out the string that resets the decoration." `(progn (when *enabled* (format ,stream "~a" (make-color-string ,color From de5481049d8f9020b99de0b07c07a576a0e516f8 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 01:17:50 -0500 Subject: [PATCH 11/18] use 8bit color by default --- src/cl-ansi-text.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cl-ansi-text.lisp b/src/cl-ansi-text.lisp index a8edcd0..418cc0e 100644 --- a/src/cl-ansi-text.lisp +++ b/src/cl-ansi-text.lisp @@ -35,7 +35,7 @@ "Turns on/off the colorization.") (declaim (type (member :3bit :8bit :24bit) *color-mode*)) -(defvar *color-mode* :24bit +(defvar *color-mode* :8bit "Controls the way `make-color-string` emits the color code. It should be one of the following keyword symbols: `:3bit`, `:8bit`, `:24bit`. From 4812381a9b8edee2c8f480c02f5e782ca371c786 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 21:46:47 -0500 Subject: [PATCH 12/18] fix typo --- src/define-colors.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/define-colors.lisp b/src/define-colors.lisp index c6f2e64..47b8ac2 100644 --- a/src/define-colors.lisp +++ b/src/define-colors.lisp @@ -6,7 +6,7 @@ ,@(map 'list (lambda (color) `(defun ,(intern (symbol-name color)) (string &key (effect :unset) (style :foreground)) - ,(format nil "Returns a string decolated in ~(~a~)." color) + ,(format nil "Returns a string decorated in ~(~a~)." color) (with-output-to-string (s) (with-color (,color :stream s :effect effect :style style) (write-string string s))))) From 10cf3cd4a9581e82c2cbd0f732efa9d4d4d13601 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 21:46:53 -0500 Subject: [PATCH 13/18] remove openjdk-7-jre --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 788c488..078eae1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ addons: packages: - libc6-i386 - clisp - - openjdk-7-jre env: global: From 2a264ffcc27d22916a9209950cdb7013359873b7 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 21:55:22 -0500 Subject: [PATCH 14/18] updated the old tester code --- testscr.ros | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testscr.ros b/testscr.ros index 0d83252..ba3d136 100755 --- a/testscr.ros +++ b/testscr.ros @@ -4,12 +4,14 @@ exec ros -Q -- $0 "$@" |# +(ql:quickload :fiveam) + (defun main (&rest argv) (declare (ignorable argv)) (uiop:quit (if (handler-case (progn (ql:quickload :cl-ansi-text.test) - (eval (read-from-string "(every #'fiveam::TEST-PASSED-P (5am:run! :cl-ansi-text))"))) + (5am:run! :cl-ansi-text)) (serious-condition (c) (describe c) (uiop:quit 2))) From 90571535f2f8645b01b6dfe74fc57e0cc17ec5cd Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 21:59:01 -0500 Subject: [PATCH 15/18] bump version to 1.1 --- cl-ansi-text.asd | 2 +- cl-ansi-text.test.asd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cl-ansi-text.asd b/cl-ansi-text.asd index 85bc528..4e444aa 100644 --- a/cl-ansi-text.asd +++ b/cl-ansi-text.asd @@ -5,7 +5,7 @@ :components ((:file "cl-ansi-text") (:file "define-colors")) :name "cl-ansi-text" - :version "1.0" + :version "1.1" :maintainer "Paul Nathan" :author "Paul Nathan" :licence "LLGPL" diff --git a/cl-ansi-text.test.asd b/cl-ansi-text.test.asd index 80f174d..0989a06 100644 --- a/cl-ansi-text.test.asd +++ b/cl-ansi-text.test.asd @@ -4,7 +4,7 @@ :components ((:file "cl-ansi-text-test")))) :name "cl-ansi-text-test" - :version "1.0" + :version "1.1" :maintainer "Paul Nathan" :author "Paul Nathan" :licence "LLGPL" From c1de46101de5a67adb9fe53d444c3481c011d877 Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 22:06:22 -0500 Subject: [PATCH 16/18] [ci skip] README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f56057..f8ab8d3 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Basic 8 colors in the 3-bit color mode are supported, which are `:black`, `:red` ; Gets printed red...and this too! ; => "and this too!" ``` -### `CL-COLORS2:RGB` and `CL-COLORS2:HSV` object +### `CL-COLORS:RGB` and `CL-COLORS:HSV` object These are color structures from `CL-COLORS2` (a maintained fork of `CL-COLORS`). `CL-COLORS2` has several constants e.g. `cl-colors:+red+` that holds the corresponding color values. From 94ab235d8b6a44ec60db28f26d06efa1e04c576b Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 22:14:51 -0500 Subject: [PATCH 17/18] [ci skip] README --- README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f8ab8d3..f70e3bf 100644 --- a/README.md +++ b/README.md @@ -149,14 +149,15 @@ Run `./testscr.ros` with Roswell. You can also manually run the test with # Note Note that your terminal MUST be ANSI-compliant to show these -colors. My SLIME REPL (as of Feb 2013) does not display these -colors. I have to use a typical Linux/OSX terminal to see them. +colors. -This has been tested to work on a Linux system with SBCL, CLISP and -CCL. CCL may not work quite perfectly, some level of conniptions were -encountered in testing. The interested reader is advised to check the -MAKE-LOAD-FORM defmethod in cl-ansi-text.lisp. +SLIME REPL does not display these colors by default (2019.12.13). +To make it understand the ANSI escape sequence, +install `slime-repl-ansi-color` package available from [MELPA](https://melpa.org/) +using `package-install` and insert `(require 'slime-repl-ansi-color)` in `.emacs`. -An earlier variant was tested on OSX 10.6 with SBCL. +You can view the list of lisp implementation this library is tested +on [Travis-CI](https://travis-ci.org/pnathan/cl-ansi-text). +The testing environment is Linux, but we believe this should work also on OSX. License: LLGPL From f4347d59e9fe4183afda88f4920e2f1417b39e3c Mon Sep 17 00:00:00 2001 From: Masataro Asai Date: Fri, 13 Dec 2019 22:21:35 -0500 Subject: [PATCH 18/18] [ci skip] README --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f70e3bf..692cf6c 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,13 @@ colors. SLIME REPL does not display these colors by default (2019.12.13). To make it understand the ANSI escape sequence, install `slime-repl-ansi-color` package available from [MELPA](https://melpa.org/) -using `package-install` and insert `(require 'slime-repl-ansi-color)` in `.emacs`. +using `package-install` and add the following in `.emacs`: + +``` lisp +(with-eval-after-load 'slime-repl + (require 'slime-repl-ansi-color)) +(add-hook 'slime-repl-mode-hook 'slime-repl-ansi-color-mode) +``` You can view the list of lisp implementation this library is tested on [Travis-CI](https://travis-ci.org/pnathan/cl-ansi-text).