-
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
base: master
Are you sure you want to change the base?
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.
@@ -6,6 +6,20 @@ import ( | |||
"github.com/charmbracelet/x/ansi" | |||
) | |||
|
|||
// 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. |
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.
Ugh why do I need to comment before making a code suggestion?
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.
// See [StyleRanges] to style multipe ranges in the same string. | |
// See [StyleRanges] to style multiple ranges in the same string. |
// 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
🤔
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.