io.aviso.ansi namespace defines a number of functions and constants for producing
ANSI escape codes.
Starting with 1.4, the
compose function is the best way to construct text with ANSI escape codes:
compose uses a Hiccup inspired data structure to identify how different vector blocks of text should be formatted.
Constants and Functions¶
compose is built on top of a large number of underlying functions and constants.
ANSI supports eight named colors, each with a bright variant. For each of the supported colors (black, red, green, yellow, blue, magenta, cyan, and white) there will be four functions and four constants:
- [bright-] color - function to set foreground text color
- [bright-] color-bg - function to set background color
- [bright-] color-font - constant that enables the text color
- [bright-] color-bg-font - constant that enables the color as background
For example, for the color green there will be
The functions are passed a string and wrap the string with ANSI codes to enable the specific font attributes, with a reset of all attributes after the string.
Note that the exact color interpretation of the ANSI codes varies significantly between platforms and applications, and is frequently configurable, often using themes. You may need to adjust your application’s settings to get an optimum display.
In addition to color, text can be:
inverse (which inverts the foreground and background colors) or
For each of these, there is a function and a
reset-font is a constant that reverts all font characteristics back to defaults.