Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def eightbit(kind):
func = fg if kind == 'fg' else bg
title = '8bit_FG' if kind == 'fg' else '8bit_BG'
items = [func(num) + str(num).ljust(3) for num in range(0, 255)]
items.insert(16, rs.all + '\n')
items.insert(51 + 2, rs.all + '\n')
items.insert(87 + 3, rs.all + '\n')
items.insert(123 + 4, rs.all + '\n')
items.insert(159 + 5, rs.all + '\n')
items.insert(195 + 6, rs.all + '\n')
items.insert(231 + 7, rs.all + '\n')
line = '\n' + title + '\n-------\n ' + ' '.join(items) + rs.all
return line
sgr(37) +'37 ?????' + rs.all,
sgr(38) +'38 ?????' + rs.all,
sgr(39) +'39 ?????' + rs.all,
sgr(40) +'40 ?????' + rs.all,
sgr(41) +'41 ?????' + rs.all,
sgr(42) +'42 ?????' + rs.all,
sgr(43) +'43 ?????' + rs.all,
sgr(44) +'44 ?????' + rs.all,
sgr(45) +'45 ?????' + rs.all,
sgr(46) +'46 ?????' + rs.all,
sgr(47) +'47 ?????' + rs.all,
sgr(48) +'48 ?????' + rs.all,
sgr(49) +'49 ?????' + rs.all,
sgr(50) +'50 ?????' + rs.all,
sgr(51) +'51 ?????' + rs.all,
sgr(52) +'52 ?????' + rs.all,
sgr(53) +'53 ?????' + rs.all,
sgr(54) +'54 ?????' + rs.all,
sgr(55) +'55 ?????' + rs.all,
sgr(56) +'56 ?????' + rs.all,
sgr(57) +'57 ?????' + rs.all,
sgr(58) +'58 ?????' + rs.all,
sgr(59) +'59 ?????' + rs.all,
sgr(60) +'60 ?????' + rs.all,
sgr(61) +'61 ?????' + rs.all,
sgr(62) +'62 ?????' + rs.all,
sgr(63) +'63 ?????' + rs.all,
sgr(64) +'64 ?????' + rs.all,
sgr(65) +'65 ?????' + rs.all,
sgr(66) +'66 ?????' + rs.all,
sgr(67) +'67 ?????' + rs.all,
sgr(68) +'68 ?????' + rs.all,
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.
class MyFgRegister(FgRegister):
def __init__(self):
super().__init__()
a = fg.li_blue + 'I have a light blue foreground.' + rs.fg
b = bg.cyan + 'I have a cyan background' + rs.bg
c = fg.da_red + bg.li_red + 'I have a dark red fg and light red bg.' + rs.all
d = fg('yellow') + 'I have yellow fg.' + rs.fg
print(a, b, c, d, sep='\n')
# ===== End =====
# ===== Start =====
Example("coloring by 8bit number")
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 =====
# ===== End =====
# ===== Start =====
Example("gettings started: select 8bit and 24bit directly")
# select an 8bit color directly.
a = fg(196) + 'This is red text' + rs.fg
# select a 24bit rgb color directly.
b = bg(50, 255, 50) + 'Text with green bg' + rs.bg
print(a, b, sep='\n')
# ===== End =====
# ===== Start =====
Example("hello world")
my_string = fg.black + bg.white + ef.bold + 'Hello world!' + rs.all
print(my_string)
# ===== End =====
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] + " ")
sum_str += " "
removed_str += str(sum_word[0])
removed_str += " "
return sum_str, removed_str, token_removed_ct, html_str
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
def b(self):
if terminal_colors() == 0:
return self.copy(self._body)
text = self._body
text = sty.ef.bold + text + sty.rs.all
return self.copy(text)