Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environments & Feature Sets #16

Open
feluxe opened this issue Feb 1, 2019 · 0 comments
Open

Environments & Feature Sets #16

feluxe opened this issue Feb 1, 2019 · 0 comments

Comments

@feluxe
Copy link
Owner

feluxe commented Feb 1, 2019

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

@feluxe feluxe added enhancement New feature or request planning Planning phase labels Feb 1, 2019
@feluxe feluxe changed the title Environments Environments & Feature Sets Feb 1, 2019
@feluxe feluxe added experiment and removed planning Planning phase labels Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant