Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from sty import fg, bg, rs
a = fg(34) + 'I have a green foreground.' + rs.fg
b = bg(133) + 'I have a pink background' + rs.bg
c = fg(226) + bg(19) + 'I have a light yellow fg and dark blue bg.' + rs.all
print(a, b, c, sep='\n')
# ===== End =====
# ===== Start =====
Example("coloring by 24bit rgb number")
from sty import fg, bg, rs
a = fg(10, 255, 10) + 'I have a green foreground.' + rs.fg
b = bg(255, 150, 50) + 'I have an orange background' + rs.bg
c = fg(90, 90, 90) + bg(32, 32, 32) + 'Grey fg and dark grey bg.' + rs.all
print(a, b, c, sep='\n')
# ===== End =====
def sgr_fg(names):
items = [fg(name) + ' ' + name.ljust(12) for name in names]
items.insert(8, rs.fg + '\n')
items.insert(16 + 1, rs.fg + '\n')
line = '\nSGR_FG:\n-------\n' + ''.join(items) + rs.fg
return line
# ===== 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 =====
fg.my_red = Style(RgbFg(255, 0, 0))
a = fg.my_red + 'This text has red fg.' + fg.rs
print(a)
# ===== End =====
# ===== Start =====
Example("customizing the register-objects: compose")
from sty import fg, ef, rs, Style, RgbFg, Sgr
fg.blue_bold = Style(RgbFg(0, 100, 200), Sgr(1))
fg.green_italic = Style(fg.green, ef.i)
a = fg.blue_bold + 'This text has bold blue fg.' + rs.all
b = fg.green_italic + 'This text has italic green fg' + rs.all
print(a, b, sep='\n')
# ===== End =====
# ===== Start =====
Example("customizing the register-objects: set_style")
from sty import fg, RgbFg
fg.set_style('my_red', RgbFg(255, 0, 0))
a = fg.my_red + 'This text has red fg.' + fg.rs
print(a)
# ===== End =====
def m(self):
if terminal_colors() == 0:
return self.copy(self._body)
text = self._body
text = sty.ef.dim + text + sty.rs.all
return self.copy(text)
def enstyleNumBin(self, txt):
result = rs.all + bg.magenta + "b"
prev = ""
for c in txt[1:]:
if prev != c:
prev = c
result += rs.all
if c == "0":
result += fg.red
result += c
result += rs.all
return result