Exporting / Copying
as_dict
method
Example:
from sty import fg as fg_obj
fg = fg_obj.as_dict()
a = fg["red"] + "I have a red fg." + fg["rs"]
print(a)
as_namedtuple
method
Example:
from sty import fg as fg_obj
fg = fg_obj.as_namedtuple()
a = fg.yellow + "I have a yellow fg." + fg.rs
print(a)
copy
method
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).
Example:
from sty import RgbFg, Style, fg
fg_copy = fg.copy()
fg_no_copy = fg
fg.orange = Style(RgbFg(255, 200, 35))
# 'fg' and 'fg_no_copy' point to the same instance, therefore both can access 'orange':
assert hasattr(fg, "orange") == True
assert hasattr(fg_no_copy, "orange") == True
# fg_copy is not effected by the changes made to the global 'fg' register-object.
assert hasattr(fg_copy, "orange") == False