How to use the sty.ef 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 / docs / customizing.py View on Github external
fg.set_style('my_eightbit_red', EightbitFg(196))
fg.set_style('my_rgb_red', RgbFg(255, 0, 0))

a = fg.my_sgr_red + 'This text has a red fg.' + fg.rs
b = fg.my_eightbit_red + 'This text has a red fg.' + fg.rs
c = fg.my_rgb_red + 'This text has a red fg.' + fg.rs

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

# ===== Start =====
Example("customizing the register-objects: get_style")
from sty import ef, fg, rs

# Make fg.green_i render a green and itelic foreground.
fg.set_style('green_i', fg.get_style('green'), ef.get_style('italic'))

# Make rs.green_i reset green and itelic foregrounds.
rs.set_style('green_i', rs.get_style('fg'), rs.get_style('italic'))

a = fg.green_i + 'This text has a green italic fg.' + rs.green_i

print(a, sep='\n')
# ===== End =====

# ===== Start =====
Example("customizing the register-objects: render-func")
from sty import fg, bg


def my_eightbit_bg_render_func(num: int) -> str:
    return '\033[48;5;' + str(num) + 'm'
github feluxe / sty / tests / docs / muting.py View on Github external
d = fg.red + 'The mute switch is off, so this is red.' + fg.rs
e = fg(10) + 'The mute switch is off, so this is green.' + fg.rs
f = fg(100, 140, 180) + 'The mute switch is off, so this is blue.' + fg.rs

print(a, b, c, d, e, f, sep='\n')
# ===== End =====

# ===== Start =====
Example("mute formatting batch")
from sty import mute, unmute, ef, fg, bg, rs

a1 = fg.red + 'This text is red.' + fg.rs
a2 = bg.red + 'This bg is red.' + bg.rs
a3 = ef.italic + 'This text is italic' + rs.italic

mute(fg, bg, ef, rs)

b1 = fg.red + 'This text is NOT red.' + fg.rs
b2 = bg.red + 'This bg is NOT red.' + bg.rs
b3 = ef.italic + 'This text is NOT italic' + rs.italic

unmute(fg, bg, ef, rs)

c1 = fg.red + 'This text is red.' + fg.rs
c2 = bg.red + 'This bg is red.' + bg.rs
c3 = ef.italic + 'This text is italic' + rs.italic

print(a1, a2, a3, b1, b2, b3, c1, c2, c3, sep='\n')
# ===== End =====
github feluxe / sty / tests / __init__.py View on Github external
def reset_registers():
    import sty
    sty.ef = EfRegister()
    sty.fg = FgRegister()
    sty.bg = BgRegister()
    sty.rs = RsRegister()
github feluxe / sty / tests / docs / effects.py View on Github external
# ===== End =====

# ===== Start =====
Example("blink")
from sty import ef, rs

a = ef.blink + 'Blinking.' + rs.blink + ' Not blinking'

print(a, sep='\n')
# ===== End =====

# ===== Start =====
Example("inverse")
from sty import ef, rs

a = ef.inverse + 'Inversed.' + rs.inverse + ' Not inversed'

print(a, sep='\n')
# ===== End =====

# ===== Start =====
Example("hidden")
from sty import ef, rs

a = ef.hidden + 'Hidden.' + rs.hidden + ' Not Hidden'

print(a, sep='\n')
# ===== End =====

# ===== Start =====
Example("strike")
from sty import ef, rs
github Hellisotherpeople / CX_DB8 / cx_db8_flair.py View on Github external
def parse_word_val_list(word_list, h, n, val_list):
    sum_str = ""
    html_str = ""
    removed_str = ""
    token_removed_ct = 0
    to_highlight = np.asarray([i for i in val_list if i > h])
    scaler = MinMaxScaler(feature_range = (20, 255))
    scaler.fit(to_highlight.reshape(-1, 1))
    for sum_word in word_list:
        prev_word = "n"
        if float(sum_word[1]) > h:
            if dynamic:
                bgnum = int(scaler.transform(sum_word[1].cpu().detach().numpy().reshape(-1, 1)))
            else:
                bgnum = highlight_color_intensity
            html_str += ef.u + bcolors.HIGHLIGHT + sum_word[0] + " "
            sum_str += ef.u + bg(bgnum, bgnum, 0)
            runner = par.add_run(sum_word[0] + " ")
            runner.underline = True
            runner.bold = True
            sum_str += " ".join([str(sum_word[0]), rs.all])
        elif float(sum_word[1]) > n:
            html_str += ef.u + sum_word[0] + " "
            sum_str += ef.u
            runner = par.add_run(sum_word[0] + " ")
            runner.underline = True
            sum_str += " ".join([str(sum_word[0]), rs.all])
        else:
            html_str += sum_word[0] + " " + bcolors.END
            token_removed_ct += 1
            sum_str += str(sum_word[0])
            runner = par.add_run(sum_word[0] + " ")
github Hellisotherpeople / CX_DB8 / cx_db8_flair.py View on Github external
scaler.fit(to_highlight.reshape(-1, 1))
    for sum_word in word_list:
        prev_word = "n"
        if float(sum_word[1]) > h:
            if dynamic:
                bgnum = int(scaler.transform(sum_word[1].cpu().detach().numpy().reshape(-1, 1)))
            else:
                bgnum = highlight_color_intensity
            html_str += ef.u + bcolors.HIGHLIGHT + sum_word[0] + " "
            sum_str += ef.u + bg(bgnum, bgnum, 0)
            runner = par.add_run(sum_word[0] + " ")
            runner.underline = True
            runner.bold = True
            sum_str += " ".join([str(sum_word[0]), rs.all])
        elif float(sum_word[1]) > n:
            html_str += ef.u + sum_word[0] + " "
            sum_str += ef.u
            runner = par.add_run(sum_word[0] + " ")
            runner.underline = True
            sum_str += " ".join([str(sum_word[0]), rs.all])
        else:
            html_str += sum_word[0] + " " + bcolors.END
            token_removed_ct += 1
            sum_str += str(sum_word[0])
            runner = par.add_run(sum_word[0] + " ")
            sum_str += " "
            removed_str += str(sum_word[0])
            removed_str += " "
    return sum_str, removed_str, token_removed_ct, html_str