Better constifying of COLORs

This commit is contained in:
jesopo 2018-11-13 17:23:18 +00:00
parent 8b9062b942
commit 7918f9cc4e

View file

@ -4,26 +4,35 @@ BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
BITBOT_EXPORTS_MAGIC = "__bitbot_exports" BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
class IRCColor(object): class IRCColor(object):
def __init__(self, irc: int, ansi: typing.List[int]): def __init__(self, irc: int, ansi: int, ansi_bold: bool):
self.irc = irc self.irc = irc
self.ansi = ansi self.ansi = ansi
self.ansi_bold = ansi_bold
WHITE = IRCColor(0, [1, 37]) COLOR_NAMES = {}
BLACK = IRCColor(1, [30]) COLOR_CODES = {}
BLUE = IRCColor(2, [34]) def _color(name: str, irc: int, ansi: int, ansi_bold: bool):
GREEN = IRCColor(3, [32]) color = IRCColor(irc, ansi, ansi_bold)
RED = IRCColor(4, [1, 31]) COLOR_NAMES[name] = color
BROWN = IRCColor(5, [31]) COLOR_CODES[irc] = color
PURPLE = IRCColor(6, [35]) return color
ORANGE = IRCColor(7, [33])
YELLOW = IRCColor(8, [1, 33]) WHITE = _color("white", 0, 37, True)
LIGHTGREEN = IRCColor(9, [1, 32]) BLACK = _color("black", 1, 30, False)
CYAN = IRCColor(10, [36]) BLUE = _color("blue", 2, 34, False)
LIGHTCYAN = IRCColor(11, [1, 36]) GREEN = _color("green", 3, 32, False)
LIGHTBLUE = IRCColor(12, [1, 34]) RED = _color("red", 4, 31, True)
PINK = IRCColor(13, [1, 35]) BROWN = _color("brown", 5, 31, False)
GREY = IRCColor(14, [1, 30]) PURPLE = _color("purple", 6, 35, False)
LIGHTGREY = IRCColor(15, [37]) ORANGE = _color("orange", 7, 33, False)
YELLOW = _color("yellow", 8, 33, True)
LIGHTGREEN = _color("light green", 9, 32, True)
CYAN = _color("cyan", 10, 36, False)
LIGHTCYAN = _color("light cyan", 11, 36, True)
LIGHTBLUE = _color("light blue", 12, 34, True)
PINK = _color("pink", 13, 35, True)
GREY = _color("grey", 14, 30, True)
LIGHTGREY = _color("light grey", 15, 37, False)
BOLD = "\x02" BOLD = "\x02"
ITALIC = "\x1D" ITALIC = "\x1D"
@ -32,3 +41,8 @@ INVERT = "\x16"
COLOR = "\x03" COLOR = "\x03"
RESET = "\x0F" RESET = "\x0F"
ANSI_FORMAT = "\033[%sm"
ANSI_RESET = "\033[0m"
ANSI_COLOR_RESET = "\033[22m"
ANSI_BOLD = "\033[1m"
ANSI_BOLD_RESET = "\033[21m"