io.aviso.ansi

Help with generating textual output that includes ANSI escape codes for formatting.

ansi-output-enabled?

added in 1.3

Determine if ANSI output is enabled. If the environment variable ENABLE_ANSI_COLORS is non-null, then it sets the value: the value false (matched caselessly) disables ANSI colors and fonts, otherwise they are enabled.

Next, there is an attempt to determine if execution is currently inside an REPL environment, possibly started from an IDE; a check is made to see if nrepl.core namespace is available; if so, then ANSI colors are enabled.

This has been verified to work with Cursive, with lein repl, and with clojure (or clj).

This check is necessary, because often in such cases, there is no console (the next check).

Otherwise, if the system has a console (via (System/console)) ANSI output will be enabled; when Clojure is running in a pipe, or as a background job without a terminal attached, the console will be nil and ANSI output will be disabled.

When this value is false, all the generated color and font constants return the empty string, and the color and font functions return the input string unchanged. This is decided during macro expansion when the ansi namespace is first loaded, so it can’t be changed at runtime.

black

(black text)

Wraps the provided text with ANSI codes to render as black text.

black-bg

(black-bg text)

Wraps the provided text with ANSI codes to render as black background text.

black-bg-font

Constant for ANSI code to enable black background text.

black-font

Constant for ANSI code to enable black text.

blue

(blue text)

Wraps the provided text with ANSI codes to render as blue text.

blue-bg

(blue-bg text)

Wraps the provided text with ANSI codes to render as blue background text.

blue-bg-font

Constant for ANSI code to enable blue background text.

blue-font

Constant for ANSI code to enable blue text.

bold

(bold text)

Wraps the provided text with ANSI codes to render as bold text.

bold-black

(bold-black text)

Wraps the provided text with ANSI codes to render as bold black text.

bold-black-bg

(bold-black-bg text)

Wraps the provided text with ANSI codes to render as bold black background text.

bold-black-bg-font

Constant for ANSI code to enable bold black background text.

bold-black-font

Constant for ANSI code to enable bold black text.

bold-blue

(bold-blue text)

Wraps the provided text with ANSI codes to render as bold blue text.

bold-blue-bg

(bold-blue-bg text)

Wraps the provided text with ANSI codes to render as bold blue background text.

bold-blue-bg-font

Constant for ANSI code to enable bold blue background text.

bold-blue-font

Constant for ANSI code to enable bold blue text.

bold-cyan

(bold-cyan text)

Wraps the provided text with ANSI codes to render as bold cyan text.

bold-cyan-bg

(bold-cyan-bg text)

Wraps the provided text with ANSI codes to render as bold cyan background text.

bold-cyan-bg-font

Constant for ANSI code to enable bold cyan background text.

bold-cyan-font

Constant for ANSI code to enable bold cyan text.

bold-font

Constant for ANSI code to enable bold text.

bold-green

(bold-green text)

Wraps the provided text with ANSI codes to render as bold green text.

bold-green-bg

(bold-green-bg text)

Wraps the provided text with ANSI codes to render as bold green background text.

bold-green-bg-font

Constant for ANSI code to enable bold green background text.

bold-green-font

Constant for ANSI code to enable bold green text.

bold-magenta

(bold-magenta text)

Wraps the provided text with ANSI codes to render as bold magenta text.

bold-magenta-bg

(bold-magenta-bg text)

Wraps the provided text with ANSI codes to render as bold magenta background text.

bold-magenta-bg-font

Constant for ANSI code to enable bold magenta background text.

bold-magenta-font

Constant for ANSI code to enable bold magenta text.

bold-red

(bold-red text)

Wraps the provided text with ANSI codes to render as bold red text.

bold-red-bg

(bold-red-bg text)

Wraps the provided text with ANSI codes to render as bold red background text.

bold-red-bg-font

Constant for ANSI code to enable bold red background text.

bold-red-font

Constant for ANSI code to enable bold red text.

bold-white

(bold-white text)

Wraps the provided text with ANSI codes to render as bold white text.

bold-white-bg

(bold-white-bg text)

Wraps the provided text with ANSI codes to render as bold white background text.

bold-white-bg-font

Constant for ANSI code to enable bold white background text.

bold-white-font

Constant for ANSI code to enable bold white text.

bold-yellow

(bold-yellow text)

Wraps the provided text with ANSI codes to render as bold yellow text.

bold-yellow-bg

(bold-yellow-bg text)

Wraps the provided text with ANSI codes to render as bold yellow background text.

bold-yellow-bg-font

Constant for ANSI code to enable bold yellow background text.

bold-yellow-font

Constant for ANSI code to enable bold yellow text.

csi

The control sequence initiator: ESC [

cyan

(cyan text)

Wraps the provided text with ANSI codes to render as cyan text.

cyan-bg

(cyan-bg text)

Wraps the provided text with ANSI codes to render as cyan background text.

cyan-bg-font

Constant for ANSI code to enable cyan background text.

cyan-font

Constant for ANSI code to enable cyan text.

green

(green text)

Wraps the provided text with ANSI codes to render as green text.

green-bg

(green-bg text)

Wraps the provided text with ANSI codes to render as green background text.

green-bg-font

Constant for ANSI code to enable green background text.

green-font

Constant for ANSI code to enable green text.

inverse

(inverse text)

Wraps the provided text with ANSI codes to render as inverse text.

inverse-font

Constant for ANSI code to enable inverse text.

italic

(italic text)

Wraps the provided text with ANSI codes to render as italic text.

italic-font

Constant for ANSI code to enable italic text.

magenta

(magenta text)

Wraps the provided text with ANSI codes to render as magenta text.

magenta-bg

(magenta-bg text)

Wraps the provided text with ANSI codes to render as magenta background text.

magenta-bg-font

Constant for ANSI code to enable magenta background text.

magenta-font

Constant for ANSI code to enable magenta text.

red

(red text)

Wraps the provided text with ANSI codes to render as red text.

red-bg

(red-bg text)

Wraps the provided text with ANSI codes to render as red background text.

red-bg-font

Constant for ANSI code to enable red background text.

red-font

Constant for ANSI code to enable red text.

reset-font

Resets the font, clearing bold, italic, color, and background color.

sgr

The Select Graphic Rendition suffix: m

strip-ansi

(strip-ansi string)

Removes ANSI codes from a string, returning just the raw text.

visual-length

(visual-length string)

Returns the length of the string, with ANSI codes stripped out.

white

(white text)

Wraps the provided text with ANSI codes to render as white text.

white-bg

(white-bg text)

Wraps the provided text with ANSI codes to render as white background text.

white-bg-font

Constant for ANSI code to enable white background text.

white-font

Constant for ANSI code to enable white text.

yellow

(yellow text)

Wraps the provided text with ANSI codes to render as yellow text.

yellow-bg

(yellow-bg text)

Wraps the provided text with ANSI codes to render as yellow background text.

yellow-bg-font

Constant for ANSI code to enable yellow background text.

yellow-font

Constant for ANSI code to enable yellow text.