Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _render_rules(
renderfuncs,
rules,
) -> Tuple[str, List[RenderType]]:
rendered: str = ''
flattened_rules = []
if isinstance(rules, RenderType):
f1: Callable = renderfuncs[type(rules)]
rendered += f1(*rules.args)
flattened_rules.append(rules)
elif isinstance(rules, Style):
r1, r2 = _render_rules(renderfuncs, rules.rules)
rendered += r1
flattened_rules.extend(r2)
elif isinstance(rules, (list, tuple)):
for rule in rules:
r1, r2 = _render_rules(renderfuncs, rule)
rendered += r1
flattened_rules.extend(r2)
def __init__(self):
self.renderfuncs: Dict[RenderType, Callable] = {}
self.is_muted = False
self.eightbit_call = lambda x: x
self.rgb_call = lambda r, g, b: (r, g, b)
class EightbitBg(RenderType):
"""
Define Eightbit Background.
More info about 8-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
:param num: Eightbit number.
"""
def __init__(self, num: int):
self.args = [num]
class RgbFg(RenderType):
"""
Define RGB Foreground.
More info about 24-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
:param r: Red.
:param g: Green.
:param b: Blue.
"""
def __init__(self, r: int, g: int, b: int):
self.args = [r, g, b]
class RgbBg(RenderType):
"""
"""
"""
class RenderType:
args: list = []
class Sgr(RenderType):
"""
Define SGR styling rule.
More info about SGR parameters: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
:param num: A SGR number.
"""
def __init__(self, num: int):
self.args = [num]
class EightbitFg(RenderType):
"""
Define Eightbit Foreground.
class RgbFg(RenderType):
"""
Define RGB Foreground.
More info about 24-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
:param r: Red.
:param g: Green.
:param b: Blue.
"""
def __init__(self, r: int, g: int, b: int):
self.args = [r, g, b]
class RgbBg(RenderType):
"""
Define RGB Background.
More info about 24-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#24-bit
:param r: Red.
:param g: Green.
:param b: Blue.
"""
def __init__(self, r: int, g: int, b: int):
self.args = [r, g, b]
class Sgr(RenderType):
"""
Define SGR styling rule.
More info about SGR parameters: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR
:param num: A SGR number.
"""
def __init__(self, num: int):
self.args = [num]
class EightbitFg(RenderType):
"""
Define Eightbit Foreground.
More info about 8-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
:param num: Eightbit number.
"""
def __init__(self, num: int):
self.args = [num]
class EightbitBg(RenderType):
"""
Define Eightbit Background.
class EightbitFg(RenderType):
"""
Define Eightbit Foreground.
More info about 8-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
:param num: Eightbit number.
"""
def __init__(self, num: int):
self.args = [num]
class EightbitBg(RenderType):
"""
Define Eightbit Background.
More info about 8-bit terminal colors: https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit
:param num: Eightbit number.
"""
def __init__(self, num: int):
self.args = [num]
class RgbFg(RenderType):
"""
Define RGB Foreground.