Muting
Caution
If you use sty for a library that is shared among other projects, I highly suggest not to mute the “global” register-objects (sty.fg, sty.bg, sty.ef, sty.rs) directly, because that might cause conflicts with other packages that share the same sty dependency.
If you want to mute sty’s register-objects in a library you should either:
Use the copy method to create copies of them, which you can mute safely.
Create custom register-classes and create new register-objects from them, which you can mute safely.
The mute
and unmute
methods
- Register.mute()[source]
Sometimes it is useful to disable the formatting for a register-object. You can do so by invoking this method.
- Return type
None
- Register.unmute()[source]
Use this method to unmute a previously muted register object.
- Return type
None
Example:
from sty import fg
fg.mute()
a = fg.red + "This red forground was muted." + fg.rs
b = fg(10) + "This green foreground was muted." + fg.rs
c = fg(100, 140, 180) + "This blue foreground was muted." + fg.rs
fg.unmute()
d = fg.red + "The mute switch is off, so this is red." + fg.rs
e = fg(10) + "The mute switch is off, so this is green." + fg.rs
f = fg(100, 140, 180) + "The mute switch is off, so this is blue." + fg.rs
print(a, b, c, d, e, f, sep="\n")
The mute
and unmute
batch functions
- sty.mute(*objects)[source]
Use this function to mute multiple register-objects at once.
- Parameters
objects (
Register
) – Pass multiple register-objects to the function.- Return type
None
- sty.unmute(*objects)[source]
Use this function to unmute multiple register-objects at once.
- Parameters
objects (
Register
) – Pass multiple register-objects to the function.- Return type
None
Example:
from sty import bg, ef, fg, mute, rs, unmute
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")