-
Notifications
You must be signed in to change notification settings - Fork 233
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 ranges #458
feat: style ranges #458
Conversation
Extracted from charmbracelet/gum#789 , this allows to style ranges of a given string without breaking its current styles. The resulting ansi sequences aren't that beautiful (as there might be many styles+reset with nothing in them), but it works. We can optimize this later I think.
ranges.go
Outdated
// StyleRanges allows to, given a string, style a range of it differently. | ||
// The function will take into account existing styles. | ||
// See [StyleRanges] to style multipe ranges in the same string. | ||
func StyleRange(s string, start, end int, style Style) 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.
Instead, maybe we could do StyleRanges(s, NewRange(start, end, style))
where func StyleRanges(s string, ranges ...Range) 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.
yeah sounds good to me as well :)
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.
Yeah, great call @aymanbagabas. Part of me thinks it should be singular, though, just so users don't think it must take multiple values 🤔. But maybe I'm overthinking it.
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.
fwiw I'm more inclined into using plural, as it indicates one or more, whereas singular indicates only one...
Extracted from charmbracelet/gum#789 , this allows to style ranges of a given string without breaking its current styles.
The resulting ansi sequences aren't that beautiful (as there might be many styles+reset with nothing in them), but it works. We can optimize this later I think.
Also: maybe better waiting for lipgloss v2 and do it there instead. This does not handle renderers for example.