Customizing Colors of the opalsShell

By default, the opalsShell console uses a blue background for easier differentiation to the standard system console. For the OPALS release 2.6.0, colorization of messages of different types was introduced. This feature emphasizes errors and warning within the console window with different foreground colors and graphic mode (i.e. underlined).

Standard color theme of the opalsShell

As depited in Figure 1, the default color theme shows warnings in yellow and errors in red (both underlined).

Fig 1: opalsShell with standard colors under Windows 10

The standard theme was chosen carefully but due to limitations of ANSI color definition, the displayed color may vary slightly from operating system, operating system version and console application.

Fig 2: Standard colors within different operating systems: Windows 10 Pro (upper left), Windows 10 Edu (upper right), Windows 11 (lower left) and Ubuntu 20.04 LTS (lower right)

Hence, the predefined color theme might be unsatisfactory in certain environments. Therefore, it is possible to customize the color theme and adapt it to the users' preferences.

ANSI color codes

OPALS uses the ANSI color codes for colorizing console messages which work on all operating systems. In principle, one can chose from 16 foreground and 16 background colors. Furthermore, it is possible to use different graphic modes (underline, blinking, etc.) as listed in Table 1.

Table 1: ANSI Codes
Color Foreground Background
Default Esc[0m  
Black Esc[30m Esc[40m
Red Esc[31m Esc[41m
Green Esc[32m Esc[42m
Yellow Esc[33m Esc[43m
Blue Esc[34m Esc[44m
Magenta Esc[35m Esc[45m
Cyan Esc[36m Esc[46m
Light gray Esc[37m Esc[47m
Dark gray Esc[90m Esc[100m
Light red Esc[91m Esc[101m
Light green Esc[92m Esc[102m
Light yellow Esc[93m Esc[103m
Light blue Esc[94m Esc[104m
Light magenta Esc[95m Esc[105m
Light cyan Esc[96m Esc[106m
White Esc[97m Esc[107m
Bold Esc[1m  
Underline Esc[4m  
No underline Esc[24m  
Reverse text Esc[7m  
Positive text (not reversed) Esc[27m  

More details on ANSI codes can be found e.g. at here, where more specific feature codes are described.

Customizing color for the opalsShell

To define a customized color theme, a specific configuration file needs to placed into the $OPALS_ROOT/cfg directory. If OPALS finds a configuration file named consoleColors.cfg there, the standard hard coded color values will be overruled. This means that in a standard installation $OPALS_ROOT/cfg/consoleColors.cfg does NOT exist. This secures that user color customizations will never be overwritten in case a newer OPALS version is installed into the same directory. However, the installation comes with a few color theme files which can be found in

$OPALS_ROOT/addons/colorThemes/

There, e.g. the default color theme defaultColors.cfg can be found, which is equivalent to the hard coded values:

##########################################
# color configuration for the opalsShell #
##########################################
# using ANSI Escape Sequences for colorizing the output. For more details see OPALS docu or
# https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
# https://ss64.com/nt/syntax-ansi.html
#
# Copy to $OPALS_ROOT/cfg/consoleColors.cfg for activating
# default color schema
background=44;37 # blue background and white foreground - only set by opalsShell
default=24;22;37 # unset underlined, unset bold/bright, use white foreground
error=31;1;4 # red, bold/bright, underlined
warning=33;1;4 # yellow, bold/bright, underlined
verbose=37 # white (light gray)
debug=30;1 # black, bold/bright (dark gray)

As it can be seen, the necessary ANSI code prefix and postfix, Esc[ and m must be omitted within the definition. Hence, only the code number or a sequence of code numbers (separated by semi-colons) are set for the corresponding config file entry. Table 2 describes the six config file entries and their meaning supported by OPALS.

Table 2: consoleColors.cfg entries
Entry Standard Comment
background 44;37 This entry is only consider by the opalsShell start script
default 24;22;37 standard text; used for info message and always set after any output message
error 31;1;4 used for error messages
warning 33;1;4 used for warnings
verbose 37 used for verbose messages
debug 30;1 used for debug messages

In case no code sequence should be used, the corresponding entry can be left empty. $OPALS_ROOT/addons/colorThemes/noColors.cfg doesn't contain any ANSI codes which results in using the standard colors of the corresponding console application (if copied to $OPALS_ROOT/cfg/consoleColors.cfg). Please have a look at $OPALS_ROOT/addons/colorThemes for more color theme config files.