color_bucket_logger.term_colors module

256 color terminal handling

ALL_COLORS is a dict mapping color indexes to the ANSI escape code. ALL_COLORS is essentially a “palette”.

Note that ALL_COLORS is a dict that (mostly) uses integers as the keys. Yeah, that is weird. In theory, the keys could also be other identifiers, although that isn’t used much at the moment. So, yeah, could/should just be a list/array.

Also note that the ordering of the color indexes is fairly arbitrary. It mostly follows the order of the ANSI escape codes. But it is important to note that the order doesn’t mean much. For example, the colors for index 154 and 155 may or may not be related in any way.

This module also defines some convience names for common keys of ALL_COLORS.

The first 8 terminal colors:
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
The terminal reset index:
RESET_SEQ_INDEX
The default color index:
DEFAULT_COLOR_IDX
color_bucket_logger.term_colors.DEFAULT_COLOR = 7

The default color (white)

color_bucket_logger.term_colors.DEFAULT_COLOR_IDX = 257

The index for the default ‘default’ color

color_bucket_logger.term_colors.NAMED_COLOR_IDXS = {'BLACK': 0, 'BLUE': 4, 'CYAN': 6, 'GREEN': 2, 'MAGENTA': 5, 'RED': 1, 'WHITE': 7, 'YELLOW': 3}

Some named colors that map to the first 8 terminal colors

color_bucket_logger.term_colors.NUMBER_OF_ALL_COLORS = 203

The number of total colors when excluded and skipped colors are considered. The color mappers use this to know what number to modulus (%) by to figure out the color bucket.

color_bucket_logger.term_colors.RESET_SEQ_IDX = 256

The index for a ‘reset’

color_bucket_logger.term_colors.RGB_COLOR_OFFSET = 18

Used to determine what color index we start from.

The xterm256 color indexes are:

0-7 normal term colors

8-15 bright term colors

16-231 are the rest from a 6x6x6 (216 color) rgb cube

16, 17 are black and very dark blue so they are skipped since they are hard to read.

232-255 are the grays (white to gray to black) and are skipped and why END_OF_THREAD_COLORS is 231.