COLOR_TABLE Settings

The COLOR_TABLE setting describes a set of specific changes to make to your color scheme. Instead of acting on all the colors uniformly, the COLOR_TABLE causes transformations of individual color combinations. For example, a COLOR_TABLE entry might cause a red foreground on a black background to be translated to a white foreground on a blue background.

There are four values that need to be set: the foreground and background colors (assigned numbers from 1 to 8) and the foreground and background intensity (high or low). These are the basic color values, without any intensity indicator:

Color Color value
Black 1
Blue 2
Green 3
Cyan 4
Red 5
Magenta     6
Brown 7
White 8

For the color table, we combine intensity and color into a single variable by adding 8 to the color value if high intensity applies. These are the possible values for foreground and background settings:

Color Color value
low-intensity Black 1
low-intensity Blue 2
low-intensity Green 3
low-intensity Cyan 4
low-intensity Red 5
low-intensity Magenta 6
low-intensity Brown 7
low-intensity White 8
high-intensity Black 9
high-intensity Blue 10
high-intensity Green 11
high-intensity Cyan 12
high-intensity Red 13
high-intensity Magenta     14
high-intensity Brown 15
high-intensity White 16

With this numbering scheme, you use the COLOR_TABLE variable (or COBOL code) to build a two-dimensional table for background and foreground colors. For example:

Back Fore 1 (low Black) 2 (low Blue) 3 (low Green) 4 (low Cyan)
1          
2          
3          
4     3, 6    
         
         

The table maps the colors specified by your program into the actual colors that will appear on the screen. It tells the runtime system which colors to use when the program specifies a particular background-foreground combination.

For example, if the table carried the equivalent of 3, 6 in row 4, column 2, this would mean that a low-intensity Cyan background (row 4) with a low-intensity Blue foreground (column 2) should be mapped to a background of low-intensity Green (3) with a foreground of low-intensity Magenta (6). The value found in each cell in the table represents the final colors to be used.

The values in the table are not actually stored as numbered pairs. They are stored as 8-bit numbers.

Initially, the table is arranged so that no transformations take place. You use the configuration setting COLOR_TABLE to change entries in the table.

Follow the word COLOR_TABLE with the original foreground and background numbers, separated by a comma. Follow these by an equals sign, and then the new foreground and background numbers, again separated by a comma.

For example, to transform the color combination of foreground 5 on background 2 to foreground 13 on background 2, you would use:

COLOR_TABLE   5, 2 = 13, 2

The color table may also be accessed directly by a COBOL program. It has the following definition:

01 w-default-COLOR-TABLE is external.
    03  occurs 16 times 
        indexed by background-color.
        05  final-color occurs 16 times
            indexed by foreground-color
            pic x comp-x.

Each table value is an 8-bit number in which the low-order four bits indicate the desired foreground color and the high-order four bits are the background color. Because four bits result in a range of 0 to 15, the colors are stored as one less than their actual value of 1 to 16. Mathematically, the colors are determined by:

Foreground = N(mod 16) + 1

Background = (N/16) + 1

where N is the 8-bit value found in the table.

For example, suppose we wanted to transform a background color of 5 and a foreground color of 14 to be the colors represented by the variables back and fore. The following COMPUTE statement does this, and can serve as a template when you want to accomplish a similar color transformation:

compute final-color(5, 14) = 
   (back - 1) * 16 + (fore - 1).

You can also make COLOR_TABLE settings from inside of COBOL by using SET ENVIRONMENT. Using the external table allows you to inquire about current COLOR_TABLE values and allows you to quickly change several values at once (for example, by processing an entire row in a loop).