/usr/lib/python3/dist-packages/colorlog/escape_codes.py is in python3-colorlog 3.1.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | """
Generates a dictionary of ANSI escape codes.
http://en.wikipedia.org/wiki/ANSI_escape_code
Uses colorama as an optional dependancy to support color on Windows
"""
try:
import colorama
except ImportError:
pass
else:
colorama.init()
__all__ = ('escape_codes', 'parse_colors')
# Returns escape codes from format codes
def esc(*x):
return '\033[' + ';'.join(x) + 'm'
# The initial list of escape codes
escape_codes = {
'reset': esc('0'),
'bold': esc('01'),
'thin': esc('02')
}
# The color names
COLORS = [
'black',
'red',
'green',
'yellow',
'blue',
'purple',
'cyan',
'white'
]
PREFIXES = [
# Foreground without prefix
('3', ''), ('01;3', 'bold_'), ('02;3', 'thin_'),
# Foreground with fg_ prefix
('3', 'fg_'), ('01;3', 'fg_bold_'), ('02;3', 'fg_thin_'),
# Background with bg_ prefix - bold/light works differently
('4', 'bg_'), ('10', 'bg_bold_'),
]
for prefix, prefix_name in PREFIXES:
for code, name in enumerate(COLORS):
escape_codes[prefix_name + name] = esc(prefix + str(code))
def parse_colors(sequence):
"""Return escape codes from a color sequence."""
return ''.join(escape_codes[n] for n in sequence.split(',') if n)
|