-
Notifications
You must be signed in to change notification settings - Fork 87
fix: re-apply color after nested reset in RenderString #119
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -227,8 +227,13 @@ func RenderString(code string, str string) string { | |
| return ClearCode(str) | ||
| } | ||
|
|
||
| // return fmt.Sprintf(FullColorTpl, code, str) | ||
| return StartSet + code + "m" + str + ResetSet | ||
| open := StartSet + code + "m" | ||
| // If the string contains reset sequences, re-apply our color after each | ||
| // reset so that nested colored args don't break the outer color. | ||
| if strings.Contains(str, ResetSet) { | ||
| str = strings.ReplaceAll(str, ResetSet, ResetSet+open) | ||
| } | ||
| return open + str + ResetSet | ||
|
Comment on lines
+230
to
+236
|
||
| } | ||
|
|
||
| // ClearCode clear color codes. | ||
|
|
||
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.
The new reset-handling behavior in RenderString isn’t covered by tests. Please add a unit test exercising a nested colored string (i.e., input
strcontainingResetSet) and asserting that the outercodeis re-applied after the inner reset, matching the issue #67 repro.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.
@copilot apply changes based on this feedback