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

BREAKING CHANGES #5

Closed
feluxe opened this issue Apr 27, 2018 · 6 comments
Closed

BREAKING CHANGES #5

feluxe opened this issue Apr 27, 2018 · 6 comments

Comments

@feluxe
Copy link
Owner

feluxe commented Apr 27, 2018

Subscribe to this in order to get notifications for breaking changes.

Repository owner locked and limited conversation to collaborators Apr 27, 2018
@feluxe
Copy link
Owner Author

feluxe commented Apr 27, 2018

Breaking Changes in 1.0.0-beta.6

New effect names

These effects were renamed:

faint is now dim
conceal is now hidden
reverse is now inverse
blink_fast is now blink
underline is now underl

Drop blink_fast

Blink fast doesn't seem to be supported by most modern terminals. It was dropped for a cleaner api and possible unwanted side-effects.

Merge resetters for bold and dim

Fixes: #3

It turns out that most terminal use the same reset sequence for both bold and dim. That means rs.bold and rs.dim have to be merged into rs.bold_dim and rs.dim_bold. This sucks, but since that's how terminals do it, I don't see a better way to solve this in sty.

That measn rs.bold, rs.b, rs.dim (formaly rs.faint) were dropped in favor of rs.bold_dim and rs.dim_bold.

@feluxe feluxe closed this as completed Apr 27, 2018
@feluxe
Copy link
Owner Author

feluxe commented Aug 22, 2018

Breaking Changes in 1.0.0-beta.7

Beta 7 comes with a lot of changes in the Customization API.

I think this post is only relevant if you use the Customization API.

Render-functions moved

The default render functions moved from sty.renderer to sty.renderfunc.

Changes within the customization API

Before Beta 7 new rules were assigned like this:

from sty import fg

# Direct attribute assignment
fg.orange = ('rgb', (255, 150, 50))

# Attribute assignment via method
fg.set('my_color', 'eightbit', 51) 

Since Beta 7 you do it like this:

from sty import fg, Rule, Render

# Direct attribute assignment
fg.orange = Rule(Render.rgb_fg, 255, 150, 50)

# Attribute assignment via method
fg.set_rule('my_color', Rule(Render.eightbit_fg, 51))

As you see there are a couple of changes.

set method renamed to set_rule

fg.set(.. is now fg.set_rule(...

The Rule type

As you see in the example above, we now use the Rule type to set new styling/formatting rules for attributes. This makes for a cleaner Base class and a more structured API.

The Render enum
As you see in the example above, there is a new Render enum, which provides the renderer names. That means you can select a renderer via the Render enum:

Rule(Render.rgb_fg, 10, 20, 30)

The old style of selecting renderers by string still works as well:

Rule('rgb_fg', 10, 20, 30)

New register-class definition

Before Beta 7 you could extend the default register classes like this:

from sty.register import FgRegister

# Extend default Fg register.
class MyFgRegister(FgRegister):

    # Set a custom render-function
    def custom_rgb_fg(self, *args):
        return my_custom_rgb_fg_func(*args)

    # Set render-function for rgb call. 
    def _rgb_call(self, *args):
        return my_custom_rgb_fg_func(*args)

    black = ('sgr', 31)
    red = ('sgr', 34)
    orange = ('custom_rgb_fg', (255, 128, 0))
    # ...

In Beta 7 you do it like this:

import sty
from sty import FgRegister, Rule, Render

# Extend the enum with the name of your new render-funtion.
class Render(sty.Render):
    custom_rgb_fg = 'custom_rgb_fg'


# Extend default Fg register.
class MyFgRegister(FgRegister):

    # Set a custom render-function
    def __init__(self):
        super().__init__() # Call super to apply render-functions from parent FgRegister.
        self.set_renderer(Render.custom_rgb_fg, my_custom_rgb_fg)

    # Set render-function for rgb call. 
    rgb_call = Rule(Render.rgb_fg)

    black = Rule(Render.sgr, 31)
    red = Rule(Render.sgr, 34)
    orange = Rule(Render.custom_rgb_bg, 255, 128, 0)
    # ...

As you see in the example above, they way we assign render-functions and the way we set render-functions for the special call methods has changed.

I suggest adding the name of the new renderer to the Render enum as shown above.

@feluxe
Copy link
Owner Author

feluxe commented Jan 23, 2019

Breaking Changes in 1.0.0-beta.9

The customization API was rewritten. Please refer to the docs: https://feluxe.github.io/sty/docs/customizing.html

@feluxe
Copy link
Owner Author

feluxe commented May 16, 2019

Breaking Changes in 1.0.0-beta.10

sty's minimal required version increased from 3.5 to 3.6.

@feluxe
Copy link
Owner Author

feluxe commented May 16, 2019

Breaking Changes in 1.0.0-beta.11

The refactoring of the Base class let to one simple change in the customization interface.

When you create a register class, you now have to call super().__init__(), inside the __init__() method:

class FgRegister(Base):

    yellow: str
    red: str
    # ...

    def __init__(self):

        super().__init__() # <--- This is necessary now.

        self.set_renderfunc(Sgr, renderfunc.sgr)
        self.set_renderfunc(EightbitFg, renderfunc.eightbit_fg)
        # ...

@feluxe
Copy link
Owner Author

feluxe commented Sep 10, 2019

Further changes will be posted to the releases page:

https://github.com/feluxe/sty/releases

You can use the watch button to get updates on Changes and Breaking Changes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant