How to use the sty.bg.rs 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 / getting_started.py View on Github external
from .. import Example
from random import randint

print("\n\nGETTING STARTED\n" + "=" * 80)

# ===== Start =====
Example("gettings started: sty all the strings")
from sty import fg, bg, ef, rs

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 custom colors:

from sty import Style, RgbFg

fg.orange = Style(RgbFg(255, 150, 50))

buf = fg.orange + 'Yay, Im orange.' + fg.rs

print(foo, bar, baz, qux, qui, buf, sep='\n')
# ===== End =====

# ===== Start =====
github feluxe / sty / tests / charts.py View on Github external
def sgr_bg(names):

    items = [bg(name) + ' ' + name.ljust(12) + bg.rs for name in names]
    items.insert(8, rs.bg + '\n')
    items.insert(16 + 1, rs.fg + '\n')
    line = '\nSGR_BG:\n-------\n' + ''.join(items)

    return line
github feluxe / sty / tests / docs / customizing.py View on Github external
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'


# 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
github feluxe / sty / tests / docs / muting.py View on Github external
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 FlameOfIgnis / github-year-draw / github-draw.py View on Github external
def preview():
	print(f"{warn} Preview?")
	if(waitConfirm()):
		for y in range(im.size[1]):
			for x in range(im.size[0]):
				#print(f"{x=}{y=}")
				c = monochromize(pix[y][x])

				#double scale to introduce the flat lose.
				c = scaleIntensity(c,255,intensity)
				c = scaleIntensity(c,intensity,255)
				c = monochromize(pix[y][x])
				c = bg(c,c,c)
				print(c + " ", end='')
			print(bg.rs)