This is a simple library for applying styles to terminal code using ANSI escape sequences.
This library can be used simply by importing it.
import color
A set of styles can be enabled by passing them as arguments to the
style function. All styles will be disabled with the unstyle
function.
import color using style unstyle BOLD ITALIC
style $BOLD
echo this text will be bold
unstyle
echo "This $(style $BOLD $ITALIC)word$(unstyle) will be bold"
A style can be applied to a single string using span.
import color using style unstyle span BOLD ITALIC
style $BOLD
echo this text will be bold
unstyle
echo "This $(span $BOLD $ITALIC "word") will be bold"
$BOLD$FAINT or $DIM$MEDIUMThe font weight can be made heavier using the $BOLD style and lighter
using the $FAINT style. $DIM is an alias for $FAINT.
The $MEDIUM style reset the font weight.
$ITALIC$FRAKTUR$REGULAR$UNDERLINE$DOUBLE_UNDERLINE$NO_UNDERLINENote: This is not well supported.
The font function can be used to access one of the 10 alternative
fonts. The default font is font 0.
echo "The word $(span $(font 2) "this") will be different"
Note: This is not well supported.
$OVERLINE$NO_OVERLINENote: This is not well supported.
$CROSS_OUT or $STRIKETHROUGH$NO_CROSS_OUT or $NO_STRIKETHROUGH$SLOW_BLINK$RAPID_BLINK or $FAST_BLINK$NO_BLINK$CONCEAL$REVEAL or NO_CONCEALNote: This is not well supported.
$FRAME$ENCIRCLE$NO_FRAME$REVERSE_VIDEO or $INVERT$NO_REVERSE_VIDEO or $NO_INVERTMany common 4-bit colors are defined with styles of the form
<COLOR>_FG to set the foreground color and <COLOR>_BG to set the
background color.
The available colors are:
BLACKREDGREENYELLOWBLUEMAGENTACYANWHITEBR_<COLOR> for bright versions of the above colorsStyles that use one of 24 values of grey can be generated with the
grey_fg and grey_bg functions, setting the foreground and background
colors respectively.
echo $(span $(grey_fg 2) "dark grey")
echo $(span $(grey_fg 22) "light grey")
Styles that use 8-bit color values can be created with the rgb8_fg and
rgb8_bg functions, setting the foreground and background colors
respectively.
Each of these functions takes 3 arguments, each in the range [0..6) for the channels red, green, and blue.
echo $(span $(rgb8_fg 3 1 5) "purple")
Styles that use 24-bit color values can be created with the rgb24_fg
and rgb24_bg functions, setting the foreground and background colors
respectively.
Each of these functions takes 3 arguments, each in the range [0..256) for the channels red, green, and blue.
echo $(span $(rgb24_fg 160 80 192) "purple")