antsy
provides a number of methods for including ANSI Select Graphics
Rendition (SGR) display aspects in strings intended for terminal output.
These include:
For more details on ANSI SGR display aspects, see the ECMA 48 Standard Document
antsy
antsy
can be required with:
(require '[antsy.core :as antsy])
The antsy.core
namespace includes escape sequence constants for each supported
display aspect, with name <aspect>-escape-sequence
as well as a
reset-escape-sequence
constant to reset display to the default.
Changing the display aspect for a string is a case of concatenating together the display aspect escape sequence with the string and then resetting back to the default using the reset escape sequence.
For example, to construct a bold string:
(str antsy/bold-escape-sequence "Hello!" antsy/reset-escape-sequence)
; => "[1mHello![0m"
or to construct a string with a red background:
(str antsy/red-bg-escape-sequence "Hello!" antsy/reset-escape-sequence)
; => "[41mHello![0m"
or to construct a string with a blue foreground:
(str antsy/blue-fg-escape-sequence "Hello!" antsy/reset-escape-sequence)
; => "[34mHello![0m"
Escape sequences can be combined as follows:
(str
antsy/red-bg-escape-sequence
antsy/blue-fg-escape-sequence
antsy/bold-escape-sequence
"Hello!"
antsy/reset-escape-sequence)
; => "[34mHello![0m"
To simplify applying and resetting display aspects, functions are also provided for each display aspect with the name of the aspect which wrap the provided text in the relevant escape sequences and reset at the end of the text.
For example, to construct a bold string:
(antsy/bold "Hello!")
; => "[1mHello![0m"
Many such functions can be applied as follows:
(antsy/bold (antsy/blue-fg "Hello!"))
; => "[1m[34mHello![0m[0m"
To simplify applying many display aspects to text, the render
function allows
a variable number of display aspect names to be provided:
(antsy/render "Hello!" :bold :red-bg :blue-fg)
; => "[1m[41m[34mHello![0m"
The render
function is also aliased as ->
since in effect it threads the
text through each of the provided display aspects left to right:
(antsy/-> "Hello!" :bold :red-bg :blue-fg)
; => "[1m[41m[34mHello![0m"
Details of all supported display aspects can be found in Supported Display Aspects.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close