Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copilot AI Apr 15, 2026

Copy link

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 str containing ResetSet) and asserting that the outer code is re-applied after the inner reset, matching the issue #67 repro.

Copilot generated this review using guidance from repository custom instructions.

Copy link
Copy Markdown
Member

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

Comment on lines +230 to +236

Copilot AI Apr 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix only applies to RenderString. Callers that use RenderCode/RenderWithSpaces (e.g., Color.Render/Color.Sprint) will still produce output where an inner \x1b[0m reset terminates the outer color. Consider extracting this reset-reapply logic into a shared helper and using it from RenderCode/RenderWithSpaces too (or explicitly documenting the differing behavior).

Copilot uses AI. Check for mistakes.
}

// ClearCode clear color codes.
Expand Down
Loading