aboutsummaryrefslogtreecommitdiff
path: root/src/utils/consts.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-01-16 11:18:51 +0000
committerGravatar jesopo2019-01-16 11:18:51 +0000
commit8f4312d002b286fbddab20251c96aa4c2dfd6922 (patch)
treedb62f58217f617595a85d861f0456e0551dd3c59 /src/utils/consts.py
parentCheck if `page` is null before trying to access `page.data` (eval_python.py) (diff)
signature
Support IRC colors 16 through 98
Diffstat (limited to 'src/utils/consts.py')
-rw-r--r--src/utils/consts.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/utils/consts.py b/src/utils/consts.py
index 56f6950d..81e86626 100644
--- a/src/utils/consts.py
+++ b/src/utils/consts.py
@@ -1,15 +1,26 @@
import typing
+from . import _consts_256_color
BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
class IRCColor(object):
- def __init__(self, irc: int, ansi: int, color_bold: bool):
+ def __init__(self, irc: int, ansi: int, is_256):
self.irc = irc
self.ansi = ansi
- self.color_bold = color_bold
- def ansi_background(self):
- return self.ansi+10
+ 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
+ )
COLOR_NAMES = {}
COLOR_CODES = {}
@@ -37,6 +48,9 @@ GREY = _color("grey", 14, 90, False)
LIGHTGREY = _color("light grey", 15, 37, False)
TRANSPARENT = _color("transparent", 99, 39, False)
+for irc_code, ansi_code in _consts_256_color.COLORS.items():
+ _color("256-%d" % irc_code, irc_code, ansi_code, True)
+
BOLD = "\x02"
ITALIC = "\x1D"
UNDERLINE = "\x1F"
@@ -45,6 +59,7 @@ COLOR = "\x03"
RESET = "\x0F"
ANSI_FORMAT = "\033[%sm"
+ANSI_256_COLOR = "\033[%d;5;%dm"
ANSI_RESET = "\033[0m"
ANSI_FOREGROUND_RESET = "\033[39m"
ANSI_BACKGROUND_RESET = "\033[49m"