-
Notifications
You must be signed in to change notification settings - Fork 235
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
feat: Style.Transform for altering strings at render time #232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me, this will make things much more flexible!
s := NewStyle().Transform(func(s string) string {
return strings.ToUpper(removeUnderline(prefix(strings.TrimSpace(s))))
}) but it could be nicer to have the following API: s := NewStyle().Transform(strings.TrimSpace, prefix, removeUnderline, strings.ToUpper) We can always merge this in to get and then do the multiple function later as that would not be / cause a breaking change to the API. |
@@ -408,6 +408,12 @@ func (s Style) GetFrameSize() (x, y int) { | |||
return s.GetHorizontalFrameSize(), s.GetVerticalFrameSize() | |||
} | |||
|
|||
// GetTransform returns the transform set on the style. If no transform is set | |||
// nil is returned. | |||
func (s Style) GetTransform() func(string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an UnsetTransform
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% — thanks for catching this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 9d6896c
Agreed; we can feel it out and add it if we feel we need it. Thanks, @maaslalani. |
Happy to play around with this before merging to provide some feedback in how it feels to work with in Glamour. Funny, Muesli and I were just talking about these features being missing from Lip Gloss for Glamour. I'm not quite there yet, so if you're in a rush to merge, then I can provide feedback at a later time. Otherwise happy to try it out over the next few weeks using this branch. |
That would be awesome, Bash. No hurry to merge over here. This actually came out of some discussions with Muesli during |
✨ Glossy Glamour ✨ |
Should we merge this? It will be quite useful for list enumerations where we pass an enumerator (i.e For example:
|
* feat: Style.Transform for altering strings at render time * feat: add `UnsetTransform` --------- Co-authored-by: Maas Lalani <maas@lalani.dev>
Just a note here for posterity's sake: this was merged so it can be used in the forthcoming |
So with this you can basically:
Some things to consider:
Transform
the best name for this?Closes #229.