L_color¶
Use the L_*
variables for colored output.
Use L_RESET
or L_COLORRESET
to reset color to defaults.
Use L_color_detect
to detect if the terminal is supposed to support colors.
The interface is not great. The ultimate goal was to not to use any subshells.
The L_color_detect
function sets or clears the L_*
variables related to colors.
The issue is that if you redirect the output, you have to call L_color_detect again for each file descriptor change.
Additionally, if you output to a different file descriptor, you have to call L_color_detect
again each time changing the file descriptor.
Usually, colors are really used for logging output. Like the following:
The function L_color_detect is not even that costly. However, I do not enjoy the alternative of spawning a subshell.
exec {logfd}>&1
L_color_detect >&$logfd
echo "$L_GREEN""Hello world""$L_RESET" >&$logfd
Generated documentation from source:¶
colors
¶
Variables storing xterm ANSI escape sequences for colors.
Variables with L_ANSI_
prefix are constant.
Variables without L_ANSI_
prefix are set or empty depending on L_color_detect function.
The
L_color_detect` function can be used to detect if the terminal and user wishes to have output with colors.
Example
echo "$L_RED""hello world""$L_RESET"
$L_BOLD
¶
$L_BRIGHT
¶
$L_DIM
¶
$L_FAINT
¶
$L_ITALIC
¶
$L_STANDOUT
¶
Standaout means italic font.
$L_UNDERLINE
¶
$L_BLINK
¶
$L_REVERSE
¶
$L_CONCEAL
¶
$L_HIDDEN
¶
$L_CROSSEDOUT
¶
$L_FONT0
¶
$L_FONT1
¶
$L_FONT2
¶
$L_FONT3
¶
$L_FONT4
¶
$L_FONT5
¶
$L_FONT6
¶
$L_FONT7
¶
$L_FONT8
¶
$L_FONT9
¶
$L_FRAKTUR
¶
$L_DOUBLE_UNDERLINE
¶
$L_NODIM
¶
$L_NOSTANDOUT
¶
$L_NOUNDERLINE
¶
$L_NOBLINK
¶
$L_NOREVERSE
¶
$L_NOHIDDEN
¶
$L_REVEAL
¶
$L_NOCROSSEDOUT
¶
$L_BLACK
¶
$L_RED
¶
$L_GREEN
¶
$L_YELLOW
¶
$L_BLUE
¶
$L_MAGENTA
¶
$L_CYAN
¶
$L_LIGHT_GRAY
¶
$L_DEFAULT
¶
$L_FOREGROUND_DEFAULT
¶
$L_BG_BLACK
¶
$L_BG_BLUE
¶
$L_BG_CYAN
¶
$L_BG_GREEN
¶
$L_BG_LIGHT_GRAY
¶
$L_BG_MAGENTA
¶
$L_BG_RED
¶
$L_BG_YELLOW
¶
$L_FRAMED
¶
$L_ENCIRCLED
¶
$L_OVERLINED
¶
$L_NOENCIRCLED
¶
$L_NOFRAMED
¶
$L_NOOVERLINED
¶
$L_DARK_GRAY
¶
$L_LIGHT_RED
¶
$L_LIGHT_GREEN
¶
$L_LIGHT_YELLOW
¶
$L_LIGHT_BLUE
¶
$L_LIGHT_MAGENTA
¶
$L_LIGHT_CYAN
¶
$L_WHITE
¶
$L_BG_DARK_GRAY
¶
$L_BG_LIGHT_BLUE
¶
$L_BG_LIGHT_CYAN
¶
$L_BG_LIGHT_GREEN
¶
$L_BG_LIGHT_MAGENTA
¶
$L_BG_LIGHT_RED
¶
$L_BG_LIGHT_YELLOW
¶
$L_BG_WHITE
¶
$L_COLORRESET
¶
$L_RESET
¶
L_color_enable
¶
The L_ color variables are set to the ANSI escape sequences.
Arguments: Takes no arguments
L_color_disable
¶
The L_ color variables are set to empty strings.
Arguments: Takes no arguments
L_term_has_color
¶
Detect if colors should be used on the terminal.
Argument:
[$1]
file descriptor to check, default: 1
Uses environment variables:
-
TERM
-
NO_COLOR
Return: 0 if colors should be used, nonzero otherwise
L_color_detect
¶
Detect if colors should be used on the terminal.
Argument:
[$1]
file descriptor to check, default 1
Shellcheck disable= SC2120
See: https://en.wikipedia.org/wiki/ANSI_escape_code#Unix_environment_variables_relating_to_color_support
$L_ANSI_BOLD
¶
$L_ANSI_BRIGHT
¶
$L_ANSI_DIM
¶
$L_ANSI_FAINT
¶
$L_ANSI_STANDOUT
¶
$L_ANSI_UNDERLINE
¶
$L_ANSI_BLINK
¶
$L_ANSI_REVERSE
¶
$L_ANSI_CONCEAL
¶
$L_ANSI_HIDDEN
¶
$L_ANSI_CROSSEDOUT
¶
$L_ANSI_FONT0
¶
$L_ANSI_FONT1
¶
$L_ANSI_FONT2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