How to use the sty.renderfunc function in sty

To help you get started, we’ve selected a few sty examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feluxe / sty / tests / examples_old.py View on Github external
def __init__(self):
            super().__init__()
            self.set_renderfunc(Render.eightbit_bg, renderfunc.eightbit_bg)
            self.set_renderfunc(Render.rgb_bg, renderfunc.rgb_bg)

            self.set_eightbit_callfunc(Render.eightbit_bg)
            self.set_rgb_callfunc(Render.rgb_bg)

            self.set_rule('black', Rule(Render.sgr, 31))
            self.set_rule('red', Rule(Render.sgr, 34))
            self.set_rule('orange', Rule(Render.rgb_bg, 255, 128, 0))
github feluxe / sty / tests / docs / customizing.py View on Github external
return '\033[48;5;' + str(num) + 'm'


# Replace fg render-function with the above bg render-function:
fg.set_renderfunc(EightbitFg, my_eightbit_bg_render_func)

a = fg.da_green + "I have a green bg because my render-func was replaced" + bg.rs

print(a)
# ===== End =====

# ===== Start =====
Example("customizing the register-objects: calls")
from sty import fg, rs, renderfunc, EightbitBg, RgbBg

fg.set_renderfunc(EightbitBg, renderfunc.eightbit_bg)
fg.set_renderfunc(RgbBg, renderfunc.rgb_bg)

fg.set_eightbit_call(EightbitBg)
fg.set_rgb_call(RgbBg)

a = fg(201) + 'I have a pink bg since fg was replaced with bg.' + rs.all
b = fg(255, 10, 10) + 'I have a red bg since fg was replaced with bg.' + rs.all

print(a, b, sep="\n")
# ===== End =====

# ===== Start =====
Example("extending register-classes")
from sty import FgRegister, Sgr, RgbFg

# Extend the default foreground register-class.
github feluxe / sty / tests / examples_old.py View on Github external
return '\033[48;5;' + str(num) + 'm'

    # Extend default Fg register.
    class MyFgRegister(FgRegister):

        def __init__(self):
            super().__init__()

            # Switch fg renderer with bg renderer.
            self.set_renderfunc(Render.eightbit_fg, my_eightbit_bg_renderfunc)

    fg = MyFgRegister()

    a = fg.da_red + 'I have an red background instead of an red fg.' + rs.bg

    fg.set_renderfunc(Render.eightbit_fg, renderfunc.eightbit_fg)

    b = fg.red + 'I have red fg again.' + rs.fg

    print(a, b, sep='\n')
github feluxe / sty / tests / docs / customizing.py View on Github external
# Replace fg render-function with the above bg render-function:
fg.set_renderfunc(EightbitFg, my_eightbit_bg_render_func)

a = fg.da_green + "I have a green bg because my render-func was replaced" + bg.rs

print(a)
# ===== End =====

# ===== Start =====
Example("customizing the register-objects: calls")
from sty import fg, rs, renderfunc, EightbitBg, RgbBg

fg.set_renderfunc(EightbitBg, renderfunc.eightbit_bg)
fg.set_renderfunc(RgbBg, renderfunc.rgb_bg)

fg.set_eightbit_call(EightbitBg)
fg.set_rgb_call(RgbBg)

a = fg(201) + 'I have a pink bg since fg was replaced with bg.' + rs.all
b = fg(255, 10, 10) + 'I have a red bg since fg was replaced with bg.' + rs.all

print(a, b, sep="\n")
# ===== End =====

# ===== Start =====
Example("extending register-classes")
from sty import FgRegister, Sgr, RgbFg

# Extend the default foreground register-class.
github feluxe / sty / sty / register.py View on Github external
def __init__(self):

        super().__init__()

        self.renderfuncs[Sgr] = renderfunc.sgr
        self.renderfuncs[EightbitFg] = renderfunc.eightbit_fg
        self.renderfuncs[RgbFg] = renderfunc.rgb_fg

        self.set_eightbit_call(EightbitFg)
        self.set_rgb_call(RgbFg)

        # Classic terminal foreground color preset.
        # These are well supported.
        self.black = Style(Sgr(30))
        self.red = Style(Sgr(31))
        self.green = Style(Sgr(32))
        self.yellow = Style(Sgr(33))
        self.blue = Style(Sgr(34))
        self.magenta = Style(Sgr(35))
        self.cyan = Style(Sgr(36))
        self.white = Style(Sgr(37))
github feluxe / sty / sty / register.py View on Github external
def __init__(self):

        super().__init__()

        self.renderfuncs[Sgr] = renderfunc.sgr
        self.renderfuncs[EightbitFg] = renderfunc.eightbit_fg
        self.renderfuncs[RgbFg] = renderfunc.rgb_fg

        self.set_eightbit_call(EightbitFg)
        self.set_rgb_call(RgbFg)

        # Classic terminal foreground color preset.
        # These are well supported.
        self.black = Style(Sgr(30))
        self.red = Style(Sgr(31))
        self.green = Style(Sgr(32))
        self.yellow = Style(Sgr(33))
        self.blue = Style(Sgr(34))
        self.magenta = Style(Sgr(35))
        self.cyan = Style(Sgr(36))
        self.white = Style(Sgr(37))
github feluxe / sty / sty / register.py View on Github external
def __init__(self):

        super().__init__()

        self.renderfuncs[Sgr] = renderfunc.sgr
        self.renderfuncs[EightbitBg] = renderfunc.eightbit_bg
        self.renderfuncs[RgbBg] = renderfunc.rgb_bg

        self.set_eightbit_call(EightbitBg)
        self.set_rgb_call(RgbBg)

        # Classic terminal background color preset.
        # These are well supported.
        self.black = Style(Sgr(40))
        self.red = Style(Sgr(41))
        self.green = Style(Sgr(42))
        self.yellow = Style(Sgr(43))
        self.blue = Style(Sgr(44))
        self.magenta = Style(Sgr(45))
        self.cyan = Style(Sgr(46))
        self.white = Style(Sgr(47))
github feluxe / sty / sty / register.py View on Github external
def __init__(self):

        super().__init__()

        self.renderfuncs[Sgr] = renderfunc.sgr
        self.renderfuncs[EightbitFg] = renderfunc.eightbit_fg
        self.renderfuncs[RgbFg] = renderfunc.rgb_fg

        self.set_eightbit_call(EightbitFg)
        self.set_rgb_call(RgbFg)

        # Classic terminal foreground color preset.
        # These are well supported.
        self.black = Style(Sgr(30))
        self.red = Style(Sgr(31))
        self.green = Style(Sgr(32))
        self.yellow = Style(Sgr(33))
        self.blue = Style(Sgr(34))
        self.magenta = Style(Sgr(35))
        self.cyan = Style(Sgr(36))
        self.white = Style(Sgr(37))

        self.rs = Style(Sgr(39))
github feluxe / sty / sty / register.py View on Github external
def __init__(self):

        super().__init__()

        self.renderfuncs[Sgr] = renderfunc.sgr
        self.renderfuncs[EightbitBg] = renderfunc.eightbit_bg
        self.renderfuncs[RgbBg] = renderfunc.rgb_bg

        self.set_eightbit_call(EightbitBg)
        self.set_rgb_call(RgbBg)

        # Classic terminal background color preset.
        # These are well supported.
        self.black = Style(Sgr(40))
        self.red = Style(Sgr(41))
        self.green = Style(Sgr(42))
        self.yellow = Style(Sgr(43))
        self.blue = Style(Sgr(44))
        self.magenta = Style(Sgr(45))
        self.cyan = Style(Sgr(46))
        self.white = Style(Sgr(47))

        self.rs = Style(Sgr(49))