howto:add_color_to_your_terminal_text

Add Color to Your Terminal Text

The following works for most modern terminal emulators (ANSI-standards-compliant terminals emulated in software, like Putty, Reflection, TeraTerm and others), but will not work on old (antique) VT100/200/etc. terminals. Those hardware VT-terminals had only single-color phosphors in their cathode-ray tubes (CRTs), like green (hence, “green screen”), amber and white – multiple colors were not available in the 1970s and '80s!

But, if you'd to add a spot of color – hopefully, well-designed, don't go crazy! – to your DCL-generated output text from a command file, here's a reference table of global DCL variables (symbols) which implement the main colors which can be generated by an ANSI-standards-compliant terminal display.

$ esc[0,8]= %X1B                    !  27 decimal,  033 octal - ESCape character
$ !
$ ! ANSI renditions:
$         NORM == esc + "[0m"       ! Normal rendition
$           NC == NORM              ! No Color
$         BOLD == esc + "[1m"       ! Bold
$        ULINE == esc + "[4m"       ! Underline
$    UNDERLINE == ULINE
$        BLINK == esc + "[5m"       ! "slow", use sparingly, if at all...!
$        REVRS == esc + "[7m"       ! Reverse or inverse
$      REVERSE == REVRS
$       NOECHO == esc + "[8m"       ! no echo
$      CONCEAL == NOECHO
$ !
$ ! Not widely (or ever) supported, here for reference/completeness:
$ !      FAINT == esc + "[2m"       ! faint (dim))
$ !     ITALIC == esc + "[3m"       ! italic
$ ! BLINKRAPID == esc + "[6m"       ! "rapid"
$ !   CROSSOUT == esc + "[9m"       ! characters "marked out"
$ !
$ ! ANSI foreground or "normal intensity" colors (forces normal background)):
$        BLACK == esc + "[0;30m"    ! normal black     [  0,  0,  0] \
$          RED == esc + "[0;31m"    ! normal red       [187,  0,  0] |
$        GREEN == esc + "[0;32m"    ! normal green     [  0,187,  0] | PuTTY
$        BROWN == esc + "[0;33m"    ! normal yellow    [187,187,  0] | RGB
$         BLUE == esc + "[0;34m"    ! normal blue      [  0,  0,187] | values
$       PURPLE == esc + "[0;35m"    ! normal magenta   [187,  0,187] |
$         CYAN == esc + "[0;36m"    ! normal cyan      [  0,187,187] |
$    LIGHTGRAY == esc + "[0;37m"    ! normal white     [187,187,187] /
$ !
$ ! Note: Specify background color before foreground color --
$ !       WRITE sys$output BLUE_BG + WHITE + "This is a test!" + NORM
$ !
$ ! ANSI background colors:
$     BLACK_BG == esc + "[0;40m"    ! normal black     [  0,  0,  0] \
$       RED_BG == esc + "[0;41m"    ! normal red       [187,  0,  0] |
$     GREEN_BG == esc + "[0;42m"    ! normal green     [  0,187,  0] | PuTTY
$     BROWN_BG == esc + "[0;43m"    ! normal yellow    [187,187,  0] | RGB
$      BLUE_BG == esc + "[0;44m"    ! normal blue      [  0,  0,187] | values
$    PURPLE_BG == esc + "[0;45m"    ! normal magenta   [187,  0,187] |
$      CYAN_BG == esc + "[0;46m"    ! normal cyan      [  0,187,187] |
$ LIGHTGRAY_BG == esc + "[0;47m"    ! normal white     [187,187,187] /
$ !
$ ! ANSI foreground or "bright intensity" colors (against reverse background)):
$     DARKGRAY == esc + "[1;30m"    ! bright black     [ 85, 85, 85] \
$     LIGHTRED == esc + "[1;31m"    ! bright red       [255, 85, 85] |
$   LIGHTGREEN == esc + "[1;32m"    ! bright green     [ 85,255, 85] | PuTTY
$       YELLOW == esc + "[1;33m"    ! bright yellow    [255,255, 85] | RGB
$    LIGHTBLUE == esc + "[1;34m"    ! bright blue      [ 85, 85,255] | values
$  LIGHTPURPLE == esc + "[1;35m"    ! bright magenta   [255, 85,255] |
$    LIGHTCYAN == esc + "[1;36m"    ! bright cyan      [ 85,255,255] |
$        WHITE == esc + "[1;37m"    ! bright white     [255,255,255] /
$ !

You can cut-&-paste some or all of these DCL variable definitions into any DCL command file, but do include the very first line which defines the ASCII esc (escape, ASCII code 27, or 33-octal, or 1B-hex) character, as that character value is required to create the remaining ANSI escape-sequence command values.

Note that the comment for each DCL color variable includes the RGB color-value (e.g., PURPLE is [187,0,187]), as well as it's well-known “web name” (e.g., PURPLE is “normal magenta”).

This repertory includes:

  • Renditions, which create text-rendition effects, including: NORM (NC, normal or none) text, BOLD text, ULINE (or UNDERLINE text), REVRS (REVERSE-video) text, NOECHO (CONCEAL, invisible) text, and even BLINK text (please don't use this, it's ugly).
  • Foreground colors, the color of the text/letters on a background, including BLACK, RED, GREEN, BROWN, BLUE, PURPLE, CYAN and LIGHTGRAY. Others, the so-called “bright intensity” colors include DARKGRAY, LIGHTRED, (etc.) to WHITE.
  • Background colors, the color of the background field behind text/letters, all ending with the suffix “_BG”, including BLACK_BG, RED_BG, (etc.) to LIGHTGRAY_BG.

The use/application of these color and rendition sequences is simple – just prefix or surround text that you'd like to “decorate” with the appropriate sequence variable(s) in a DCL WRITE statement:

$ WRITE sys$output “This is: ” + RED + BOLD + “red & bold text ” + NORM + “…but now back to normal.”

This WRITE statement's phrase “red & bold text,” should appear in boldface red type (not reproduced here). This would likely look/appear best on a white (light) background screen.

Caution / Hint: Colors can be tricky. Colored text look best on backgrounds which highly contrast with that text color, with white-on-black or black-on-white being the extreme ends of the contrast spectrum. Red, blue, green look good and readable on a white background, but yellow-on-white or lightgray-on-white are practically unreadable. Yellow-on-black looks good, but blue-on-black is unreadable.

Always experiment with color and rendition combinations, and choose only the most readable combos. Remember, some other people may be color-blind or sight-impaired, and what looks “neat” to you may be completely unreadable to them. Use colors and renditions sparingly, for emphasis and effect – Don't go crazy with it.

howto/add_color_to_your_terminal_text.txt · Last modified: 2018/09/10 22:31 by lricker