Environments & Feature Sets
Environments & Feature Sets (Planning)
stycurrently supports features that don't work with some dated terminals, e.g. terminal.app (see #12, #14). There are other terminals that don't work with the common ANSI sequences, e.g. cmd, powershell. (see #2)
Feature Sets
If you are planning to support a wide range of terminals, it would be good if you could restrict sty to the features you are allowed to use.
With a del_styles_of_type function, you could, for example, remove rgb colors in order to support apple's terminal.app:
from sty import fg, RgbFg, RgbBg
fg.del_styles_of_type(RgbFg)
bg.del_styles_of_type(RgbBg)
This would remove attributes that use rgb colors from the default fg and bg register, restricting sty to the feature set of terminal.app.
If you don't want to support eightbit colors, you could use this:
from sty import fg, EightbitFg, EightbitBg
fg.del_styles_of_type(EightbitFg)
bg.del_styles_of_type(EightbitBg)
The code above would remove eightbit styles such as da_green, da_red, da_* from the default fg and bg register.
There could be a batch function to delete from multiple objects at once:
from sty import fg, EightbitFg, del_styles_of_type
custom_fg = fg.copy()
custom_fg.set_styles("orange", EightbitFg(214))
del_styles_of_type(EightbigFg, fg, custom_fg)
Environments
Configuration preset for common environments.
default Environment
The default environment enables you to use the full feature set of sty using the most common ANSI escape sequences. This is the environment which sty uses by default.
# Get default env register-objects.
ef, fg, bg, rs = sty.env.default()
# Or set default env globally (be careful with this).
sty.env.default(set_globally=True)
windows Environment
The windows environment uses windows specific ANSI sequences and allows only the features that work with cmd/powershell.
# Get windows compatible register-objects
ef, fg, bg, rs = sty.env.windows()
# Or set windows compatible register-objects globally (be careful with this).
sty.env.windows(set_globally=True)
In a real world app, you might call something like this in __init__.py of you application:
if platform.system() == 'Windows':
sty.env.windows(set_globally=True)
Or better add a style.py to you project and use this:
if platform.system() == 'Windows':
ef, fg, bg, rs = sty.env.windows()
Now you can import the registers from style.py, e.g.: from .style import ef, fg, bg, rs