Exporting / Copying¶
Export color register as dict.
- Return type
from sty import fg as fg_obj fg = fg_obj.as_dict() a = fg['red'] + "I have a red fg." + fg['rs'] print(a)
Export color register as namedtuple.
from sty import fg as fg_obj fg = fg_obj.as_namedtuple() a = fg.yellow + "I have a yellow fg." + fg.rs print(a)
The copy method allows you to create deep copies of register-objects. This can be very useful in case you don’t want to mess with sty’s global register-classes (sty.fg., sty.bg, sty.ef, sty.rs).
Make a deepcopy of a register-object.
from sty import fg as fg_a, RgbFg, FgRegister fg_b = fg_a fg_c = fg_a.copy() fg_a.set_style('orange', RgbFg(240, 100, 100)) a = fg_a.orange + "I have an orange fg." + fg.rs b = fg_b.orange + "I have an orange fg too." + fg.rs print(a, b, sep="\n") try: msg = "But I have no orange fg, because I'm an earlier copy." fg_c.orange + msg + fg.rs except AttributeError: print(msg)