Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def direct_attribute_customization():
# ef.italic now renders underlined text.
ef.set_rule('italic', Rule(Render.sgr, 4))
# fg.red renders green text from now on.
fg.set_rule('red', Rule(Render.sgr, 32))
# fg.blue renders red text from now on (using an 8bit color code).
fg.set_rule('blue', Rule(Render.eightbit_fg, 88))
# Create a new item that renders brown text.
fg.set_rule('my_new_item', Rule(Render.eightbit_fg, 130))
# bg.green renders blue bg from now on (using a 24bit rgb code).
bg.set_rule('green', Rule(Render.rgb_bg, 0, 128, 255))
# rs.all only resets the underline effect from now on.
rs.set_rule('bold_dim', Rule(Render.sgr, 24))
a = ef.italic + 'This is not italic any more, but underlined' + rs.underl
b = fg.red + 'This is not red any more, but green.' + rs.fg
c = fg.blue + 'This is not blue any more, but red' + rs.fg
d = fg.my_new_item + 'This is a new brown attribute' + rs.fg
e = bg.green + 'This is not green bg any more, but blue.' + rs.bg
f = ef.bold + 'This does not reset bold any more' + rs.bold_dim \
+ ' -> This is still bold' + rs.all
print(a, b, c, d, e, f, sep='\n')
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))
def dynamic_attribute_customization_with_multiple_rules():
my_color_name1 = 'teal_b'
my_color_name2 = 'green_i'
my_color_name3 = 'red_ul'
fg.set_rule(
my_color_name1, Rule(Render.eightbit_fg, 51), Rule(Render.sgr, 1)
)
fg.set_rule(my_color_name2, fg.green, ef.i)
fg.set_rule(my_color_name3, Rule(Render.sgr, 31), ef.underl)
a = fg.teal_b + 'This is custom teal and bold text.' + rs.all
b = fg.green_i + 'This is green italic text.' + rs.all
c = fg.red_ul + 'This is red and undelrined text.' + rs.all
print(a, b, c, sep='\n')
def getting_started(args):
fg, bg, ef, rs = args
# from sty import fg, bg, ef, rs, Render
foo = fg.red + 'This is red text!' + fg.rs
bar = bg.blue + 'This has a blue background!' + bg.rs
baz = ef.italic + 'This is italic text' + rs.italic
qux = fg(201) + 'This is pink text using 8bit colors' + fg.rs
qui = fg(255, 10, 10) + 'This is red text using 24bit colors.' + fg.rs
# Add new colors:
fg.set_rule('orange', Rule(Render.rgb_fg, 255, 150, 50))
buf = fg.orange + 'Yay, Im orange.' + fg.rs
print(foo, bar, baz, qux, qui, buf, sep='\n')
a = ef('italic') + 'Italic text.' + rs.italic
b = fg('blue') + 'Blue text.' + rs.fg
c = bg(randint(0, 254)) + 'Random colored bg' + rs.bg
print(a, b, c, sep='\n')
def direct_attribute_customization_with_multiple_rules():
fg.set_rule('green_ul', Rule(Render.sgr, 32), Rule(Render.sgr, 4))
fg.set_rule('red_i', Rule(Render.sgr, 31), ef.i)
fg.blue_b = fg.blue + ef.b
a = fg.green_ul + 'This is green and underline text.' + rs.all
b = fg.red_i + 'This is red and italic text.' + rs.all
c = fg.blue_b + 'This is blue and bold text.' + rs.all
print(a, b, c, sep='\n')
def direct_attribute_customization():
# ef.italic now renders underlined text.
ef.set_rule('italic', Rule(Render.sgr, 4))
# fg.red renders green text from now on.
fg.set_rule('red', Rule(Render.sgr, 32))
# fg.blue renders red text from now on (using an 8bit color code).
fg.set_rule('blue', Rule(Render.eightbit_fg, 88))
# Create a new item that renders brown text.
fg.set_rule('my_new_item', Rule(Render.eightbit_fg, 130))
# bg.green renders blue bg from now on (using a 24bit rgb code).
bg.set_rule('green', Rule(Render.rgb_bg, 0, 128, 255))
# rs.all only resets the underline effect from now on.
rs.set_rule('bold_dim', Rule(Render.sgr, 24))
a = ef.italic + 'This is not italic any more, but underlined' + rs.underl
b = fg.red + 'This is not red any more, but green.' + rs.fg
c = fg.blue + 'This is not blue any more, but red' + rs.fg
d = fg.my_new_item + 'This is a new brown attribute' + rs.fg
e = bg.green + 'This is not green bg any more, but blue.' + rs.bg
f = ef.bold + 'This does not reset bold any more' + rs.bold_dim \
def direct_attribute_customization():
# ef.italic now renders underlined text.
ef.set_rule('italic', Rule(Render.sgr, 4))
# fg.red renders green text from now on.
fg.set_rule('red', Rule(Render.sgr, 32))
# fg.blue renders red text from now on (using an 8bit color code).
fg.set_rule('blue', Rule(Render.eightbit_fg, 88))
# Create a new item that renders brown text.
fg.set_rule('my_new_item', Rule(Render.eightbit_fg, 130))
# bg.green renders blue bg from now on (using a 24bit rgb code).
bg.set_rule('green', Rule(Render.rgb_bg, 0, 128, 255))
# rs.all only resets the underline effect from now on.
rs.set_rule('bold_dim', Rule(Render.sgr, 24))
a = ef.italic + 'This is not italic any more, but underlined' + rs.underl
b = fg.red + 'This is not red any more, but green.' + rs.fg
c = fg.blue + 'This is not blue any more, but red' + rs.fg
def dynamic_attribute_customization_with_multiple_rules():
my_color_name1 = 'teal_b'
my_color_name2 = 'green_i'
my_color_name3 = 'red_ul'
fg.set_rule(
my_color_name1, Rule(Render.eightbit_fg, 51), Rule(Render.sgr, 1)
)
fg.set_rule(my_color_name2, fg.green, ef.i)
fg.set_rule(my_color_name3, Rule(Render.sgr, 31), ef.underl)
a = fg.teal_b + 'This is custom teal and bold text.' + rs.all
b = fg.green_i + 'This is green italic text.' + rs.all
c = fg.red_ul + 'This is red and undelrined text.' + rs.all
print(a, b, c, sep='\n')