2018-11-13 16:02:26 +00:00
|
|
|
import typing
|
2019-01-16 11:18:51 +00:00
|
|
|
from . import _consts_256_color
|
2018-11-13 16:02:26 +00:00
|
|
|
|
|
|
|
class IRCColor(object):
|
2019-01-16 11:18:51 +00:00
|
|
|
def __init__(self, irc: int, ansi: int, is_256):
|
2018-11-13 16:02:26 +00:00
|
|
|
self.irc = irc
|
|
|
|
self.ansi = ansi
|
2019-01-16 11:18:51 +00:00
|
|
|
self.is_256 = is_256
|
|
|
|
|
|
|
|
def to_irc(self):
|
|
|
|
return str(self.irc)
|
|
|
|
def to_ansi(self, background=False):
|
|
|
|
if not self.is_256:
|
|
|
|
code = self.ansi + (10 if background else 0)
|
|
|
|
return ANSI_FORMAT % code
|
|
|
|
else:
|
|
|
|
return ANSI_256_COLOR % (
|
|
|
|
48 if background else 38,
|
|
|
|
self.ansi
|
|
|
|
)
|
2018-11-13 16:02:26 +00:00
|
|
|
|
2018-11-13 17:23:18 +00:00
|
|
|
COLOR_NAMES = {}
|
|
|
|
COLOR_CODES = {}
|
2018-11-14 11:44:56 +00:00
|
|
|
def _color(name: str, irc: int, ansi: int, color_bold: bool):
|
|
|
|
color = IRCColor(irc, ansi, color_bold)
|
2018-11-13 17:23:18 +00:00
|
|
|
COLOR_NAMES[name] = color
|
|
|
|
COLOR_CODES[irc] = color
|
|
|
|
return color
|
|
|
|
|
2018-12-12 11:49:42 +00:00
|
|
|
WHITE = _color("white", 0, 97, False)
|
|
|
|
BLACK = _color("black", 1, 30, False)
|
|
|
|
BLUE = _color("blue", 2, 34, False)
|
|
|
|
GREEN = _color("green", 3, 32, False)
|
|
|
|
RED = _color("red", 4, 91, False)
|
|
|
|
BROWN = _color("brown", 5, 31, False)
|
|
|
|
PURPLE = _color("purple", 6, 35, False)
|
|
|
|
ORANGE = _color("orange", 7, 33, False)
|
|
|
|
YELLOW = _color("yellow", 8, 93, False)
|
|
|
|
LIGHTGREEN = _color("light green", 9, 92, False)
|
|
|
|
CYAN = _color("cyan", 10, 36, False)
|
|
|
|
LIGHTCYAN = _color("light cyan", 11, 96, False)
|
|
|
|
LIGHTBLUE = _color("light blue", 12, 94, False)
|
|
|
|
PINK = _color("pink", 13, 95, False)
|
|
|
|
GREY = _color("grey", 14, 90, False)
|
|
|
|
LIGHTGREY = _color("light grey", 15, 37, False)
|
|
|
|
TRANSPARENT = _color("transparent", 99, 39, False)
|
2018-11-13 16:02:26 +00:00
|
|
|
|
2019-01-16 11:18:51 +00:00
|
|
|
for irc_code, ansi_code in _consts_256_color.COLORS.items():
|
|
|
|
_color("256-%d" % irc_code, irc_code, ansi_code, True)
|
|
|
|
|
2018-11-13 17:43:00 +00:00
|
|
|
BOLD = "\x02"
|
|
|
|
ITALIC = "\x1D"
|
|
|
|
UNDERLINE = "\x1F"
|
|
|
|
INVERT = "\x16"
|
|
|
|
COLOR = "\x03"
|
|
|
|
RESET = "\x0F"
|
2018-11-13 16:02:26 +00:00
|
|
|
|
2018-11-30 16:30:47 +00:00
|
|
|
ANSI_FORMAT = "\033[%sm"
|
2019-01-16 11:18:51 +00:00
|
|
|
ANSI_256_COLOR = "\033[%d;5;%dm"
|
2018-11-30 16:30:47 +00:00
|
|
|
ANSI_RESET = "\033[0m"
|
2018-11-14 22:07:34 +00:00
|
|
|
ANSI_FOREGROUND_RESET = "\033[39m"
|
|
|
|
ANSI_BACKGROUND_RESET = "\033[49m"
|
2018-11-30 16:30:47 +00:00
|
|
|
ANSI_BOLD = "\033[1m"
|
|
|
|
ANSI_BOLD_RESET = "\033[22m"
|
|
|
|
ANSI_UNDERLINE = "\033[4m"
|
|
|
|
ANSI_UNDERLINE_RESET = "\033[24m"
|
2019-01-28 23:29:52 +00:00
|
|
|
|
|
|
|
PERMISSION_HARD_FAIL = 0
|
|
|
|
PERMISSION_FORCE_SUCCESS = 1
|
|
|
|
PERMISSION_ERROR = 2
|