A library to use ANSI escape codes to format text and background color, font weigh, and underlining.
Return a string consisting of an ANSI escape code to select the specified text color.Return a string consisting of an ANSI escape code to select the text color specified by thered-level
, green-level
,
and blue-level
arguments, each of which must be an exact
integer in the range [0, 5].
The caller is resonsible for verifying that the terminal supports
256 colors.Return a string consisting of an ANSI escape code to select the
text color specified by the gray-level
argument, which must
be an exact integer in the range [0, 23].
The caller is resonsible for verifying that the terminal supports
256 colors.The true-color equivalent of rgb-escape
. Return a string
consisting of an ANSI escape code to select the text color
specified by the red-level
, green-level
, and
blue-level
arguments, each of which must be an exact integer
in the range [0, 255].Return a string consisting of an ANSI escape code to select the
default text color.If ANSI escapes are enabled, return a string consisting of the
string str
with a prefix that selects specified text color
and a suffix that selects the default text color.
If ANSI escapes are not enabled, return str
.Returns a procedure which takes a single argument, a string, and
which when called behaves as follows.
If ANSI escapes are enabled, the procedure returns a string
consisting of its argument with a prefix that selects specified
text color (obtained by calling the rgb-escape
procedure
with the values of the red-level
, green-level
, and
blue-level
arguments) and a suffix that selects the default
text color.
If ANSI escapes are not enabled, the procedure returns its argument.
The caller is resonsible for verifying that the terminal supports
256 colors.Returns a procedure which takes a single argument, a string, and
which when called behaves as follows.
If ANSI escapes are enabled, the procedure returns a string
consisting of its argument with a prefix that selects specified
text color (obtained by calling the gray-escape
procedure
with the values of the gray-level
argument) and a suffix
that selects the default text color.
If ANSI escapes are not enabled, the procedure returns its argument.
The caller is resonsible for verifying that the terminal supports
256 colors.The true-color equivalent of rbg
, extending the ranges
to [0, 255].Return a string consisting of an ANSI escape code to select the
specified background color.Return a string consisting of an ANSI escape code to select the
background color specified by the red-level
, green-level
,
and blue-level
arguments, each of which must be an exact
integer in the range [0, 5].
The caller is resonsible for verifying that the terminal supports
256 colors.Return a string consisting of an ANSI escape code to select the
background color specified by the gray-level
argument, which
must be an exact integer in the range [0, 23].
The caller is resonsible for verifying that the terminal supports
256 colors.The true-color equivalent of rgb-background-escape
.
Return a string consisting of an ANSI escape code to select the
text color specified by the red-level
, green-level
,
and blue-level
arguments, each of which must be an exact
integer in the range [0, 255].
Return a string consisting of an ANSI escape code to select the
default background color.If ANSI escapes are enabled, return a string consisting of the
string str
with a prefix that selects specified background
color and a suffix that selects the default background color.
If ANSI escapes are not enabled, return str
.Returns a procedure which takes a single argument, a string, and
which when called behaves as follows.
If ANSI escapes are enabled, the procedure returns a string
consisting of its argument with a prefix that selects specified
background color (obtained by calling the rgb-background-escape
procedure with the values of the red-level
, green-level
,
and blue-level
arguments) and a suffix that selects the
default background color.
If ANSI escapes are not enabled, the procedure returns its argument.
The caller is resonsible for verifying that the terminal supports
256 colors.Returns a procedure which takes a single argument, a string, and
which when called behaves as follows.
If ANSI escapes are enabled, the procedure returns a string
consisting of its argument with a prefix that selects specified
background color (obtained by calling the gray-background-escape
procedure with the values of the gray-level
argument) and a
suffix that selects the default background color.
If ANSI escapes are not enabled, the procedure returns its argument.
The caller is resonsible for verifying that the terminal supports
256 colors.The true-color equivalent of rbg-background
, extending
the ranges to [0, 255].Return a string consisting of an ANSI escape code to select bold
style.Return a string consisting of an ANSI escape code to select non-bold
style.If ANSI escapes are enabled, return a string consisting of the
string str
with a prefix that selects bold style and a suffix
that selects non-bold style.
If ANSI escapes are not enabled, return str
.Return a string consisting of an ANSI escape code to select
underlined style.Return a string consisting of an ANSI escape code to select
non-underlined style.If ANSI escapes are enabled, return a string consisting of the
string str
with a prefix that selects underlined style and
a suffix that selects non-underlined style.
If ANSI escapes are not enabled, return str
.Return a string consisting of an ANSI escape code to select
italic style.Return a string consisting of an ANSI escape code to select
non-italic style.Returns str
optionally wrapped in italic escapes.Return a string consisting of an ANSI escape code to select
strikethrough style.Return a string consisting of an ANSI escape code to select
non-strikethrough style.Returns str
optionally wrapped in strikethrough escapes.Return a string consisting of an ANSI escape code to select negative
style (text in the background color and background in the text
color).Return a string consisting of an ANSI escape code to select positive
style (text in the text color and background in the background
color).If ANSI escapes are enabled, return a string consisting of the
string str
with a prefix that selects negative style (text
in the background color and background in the text color) and a
suffix that selects positive style (text in the text color and
background in the background color).
If ANSI escapes are not enabled, return str
.A parameter object that determines whether ANSI escapes are enabled
in some of the preceding procedures. They are disabled if
(ansi-escapes-enabled?)
returns #f
, and otherwise
they are enabled.
The initial value returned by (ansi-escapes-enabled?)
is
determined by the environment.
If the environment variable ANSI_ESCAPES_ENABLED
is set,
its value determines the initial value returned by
(ansi-escapes-enabled?)
. If the value of
ANSI_ESCAPES_ENABLED
is "0"
, the initial value
is #f
, otherwise the initial value is #t
.
If the environment variable ANSI_ESCAPES_ENABLED
is not
set, but the environment variable TERM
is set, the value
of the latter determines the initial value returned by
(ansi-escapes-enabled?)
. If the value of TERM
is "xterm"
, "xterm-color"
, "xterm-256color"
,
"rxvt"
, "rxvt-unicode-256color"
, "kterm"
,
"linux"
, "screen"
, "screen-256color"
,
or "vt100"
, the initial value is #t
, otherwise
the initial value is #f
.
If neither of the environment variables ANSI_ESCAPES_ENABLED
and TERM
are set, the initial value returned by
(ansi-escapes-enabled?)
is #f
.
It is important to remember that the formatting procedures apply
a prefix to set a particular graphics parameter and a suffix to
reset the parameter to its default value. This can lead to surprises.
For example, on an ANSI terminal, one might mistakenly expect the
following to display GREEN in green text and then RED in red text:
(display (red (string-append (green "GREEN") "RED")))
However, it will actually display GREEN in green text and then RED
in the default text color. This is a limitation of ANSI control
codes; graphics attributes are not saved to and restored from a
stack, but instead are simply set. One way to display GREEN in
green text and then RED in red text is:
(display (string-append (green "GREEN") (red "RED")))
On the other hand, text color, background color, font weight (bold
or default), underline (on or off), image (positive or negative)
are orthogonal. So, for example, on an ANSI terminal the following
should display GREEN in green text and then RED in red text, with
both in bold and GREEN underlined.
(display (bold (string-append (underline (green "GREEN")) (red "RED"))))