ContentsIndexPreviousNext

9.8 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:

Foreground and Background Settings

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

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 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, as described later in this section.

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 where 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).

If you want to access the color table directly in your code, simply substitute your variable names and color numbers in the sample code shown above.

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).