-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add and Expose Methods of easily Creating and Mutating ColoredString
's and Style
's for Users
#154
Add and Expose Methods of easily Creating and Mutating ColoredString
's and Style
's for Users
#154
Conversation
…Mut<Target = String>.
…ns from ColoredString into CopyColorize, and add StyleTemplate struct to assist with CopyColorize.
… values for the user.
…ing and StyleTemplate to derive.
…s as a guide for rustling users.
…'s. Also, add doc for Styles and improve tests.
… None' and generally improve ColorizedMut docs.
…cer and change the wording on the first section (renamed to "Creation")
Merge branch 'master' into JustAnotherCodemonkey/enable-coloredstring-inplace-modification
…olorize as they are now unnesecary, and modify docs to reflect the new idioms.
…lained in the ColoredString docs.
…wait for another PR tbh).
I think we could leave the Since you are exposing Probably should mark |
…ngelog to reflect this. Also, mark ColoredString as non_exhaustive.
You got it. I kept |
The changes to |
Wait I don't understand. How so? |
The addition of the two (non-default) methods is a breaking change. |
Ah I now see. I didn't consider that we'd be considering that users would be implementing |
Unfortunately, it is still a breaking change, no matter how small the impact might be. |
…be back in some form in the future).
Ok I basically just removed those from the PR. I'd really like a method that could do the |
Yeah, go with another PR which merges targeting the Please note that |
Just need to fix the formatting |
I saw that! Very exciting imo. I really like the idea that initially sparked the PR of being able to use |
If you'd like, you are welcome to open a PR with the changes for |
Don't know what to do about these last 2 tests I don't think it has anything to do with my PR...? |
I think it may be a bug in the windows terminal environment code |
I know this is a lot but most of it is either long documentation or impls for
Style
orStyles
. I can easily downgrade certain parts if necessary or split them off into separate PRs as I am starting to think to do with one feature in particular.Changes
The changes are all laid out in the changelog and I'd highly recommend looking at that as it will make it vastly easier to understand what the code is and is trying to do. If you see the point in all the changes listed, feel free to skip the Motivation section.
Motivation
This all started when I was trying to make an adventure game and wanted to have a function that took a Vec of
ColoredString
's and would return an iterator of newColoredString
's that were each a single character of their respectiveColoredString
and would maintain the coloring and style. Should be easy. The problem: I quickly realized that there are several things that cannot be done easily or at all in colored as it stands. This PR addresses a whole bunch of them with a cluster of solutions that open the door wide in terms of possibilities. Here are some of the problems:ColoredString
's. They deref tostr
and thus you can makeString
's off of them, however, 1. there is no way of doing this in-place, which would be important for performance and 2. this means you now need to re-create foreground color, background color, and style from oneColoredString
to another and that last one, style, is exceptionally difficult as it stands. I mean maybe I'm just stupid but just try to copy the style of oneColoredString
to another.ColoredString
to another. This was kind of addressed in the previous bit but although you can get aStyle
from aColoredString
, you can't really use it other than to just check if any specific style switch is activated and compare them with==
.Style
's for the user. This kind of goes hand-in-hand with the previous point. Also,Style
does not implementDefault
which was preventing a deriving ofDefault
forColoredString
which was another PR (i.e. that one made a default for both).Style
's such as combining them or subtracting one from another.ColoredString
stored in its fields. Those fields are now exposed.There are likely other problems I had but can't remember atm. It's 3:45 AM in my time zone at time of writing.
Breaking Changes
There is one (1) breaking change and it's one of the features of this PR I'm willing to part with:
ColoredString
now derefs toString
instead ofstr
. Why this is breaking and also why it's very uncommon for it to actually break anything is explained in the changelog.Overall, I think I'm pretty satisfied with the changes. There might be one or two I've left out but they can happen in their own PRs. I think it would enable so much, especially performance-wise as the workarounds, when possible, are very ugly. I sure hope this one doesn't die on Capital Hill.