Common Lisp Package: CL-ANSI-TEXT

README:

cl-ansi-text

Because color in your terminal is nice.

Examples:

[2]> (cl-ansi-text:with-color (cl-colors:+red+) (format t "hi")) hi NIL [3]> (cl-ansi-text:with-color (cl-colors:+green+) (format t "hi")) hi NIL [4]> (cl-ansi-text:with-color (cl-colors:+blue+) (format t "hi")) hi NIL

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.

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.

An earlier variant was tested on OSX 10.6 with SBCL.

License: LLGPL

FUNCTION

Public

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

Private

BUILD-CONTROL-STRING (COLOR &OPTIONAL (EFFECT UNSET) (STYLE FOREGROUND))

Color (cl-color or term-color) Effect Style

EQ-COLORS (A B)

Equality for cl-colors

FIND-COLOR-CODE (COLOR)

Find the list denoting the color

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+

GENERATE-CONTROL-STRING (CODE)

General ANSI code

Undocumented

CL-COLORS-TO-ANSI (COLOR)

CODE-FROM-RGB (STYLE RED GREEN BLUE)

FIND-STYLE-CODE (STYLE)

GENERATE-COLOR-STRING (CODE)

RGB-CODE-P (COLOR)

RGB-TO-ANSI (RED GREEN BLUE)

TERM-COLORS-TO-ANSI (COLOR)

MACRO

Public

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..

GENERIC-FUNCTION

Private

RGB-COLOR-CODE (COLOR &OPTIONAL STYLE)

Returns the 256-color code suitable for rendering on the Linux extensions to xterm

VARIABLE

Public

*ENABLED*

Turns on/off the colorization of functions

+RESET-COLOR-STRING+

This string will reset ANSI colors

Private

+CL-COLORS+

CL-COLORS colors

+TERM-COLORS+

Basic colors

+TERM-EFFECTS+

ANSI terminal effects

+TEXT-STYLE+

One or the other. Not an ANSI effect