fix: honor color profile when rendering table cells#369
Conversation
Use env.String(...) instead of the package-level termenv.String(...) so the detected color profile is carried into the Style. The package-level constructor hardcodes profile to ANSI, which causes empty SGR escape sequences (\x1b[;;m ... \x1b[0m) to wrap the usage bar when NO_COLOR is set and stdout is non-TTY. Fixes muesli#364 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The The deeper issue is that func NewBarRenderer(output *termenv.Output) *BarRenderer {
return &BarRenderer{out: output} // store Output, not just profile
}
func (r *BarRenderer) Render(v float64) string {
// r.out.String(...) always uses the correct profile
}This pattern (passing |
Summary
termenv.String(...), which hardcodes the Style's profile toANSI. WhenNO_COLORis set (or stdout is non-TTY),envisAsciiand theme colors collapse toNoColor{}— but because the Style still claimsANSI,Foreground(NoColor{}).Background(NoColor{})appends empty SGR slots and the renderer emits\x1b[;;m…\x1b[0maround the bar.env.String(...)carries the detected profile into the Style, soStyled()short-circuits and emits plain text underAscii. Behavior is unchanged for any non-Asciiprofile (the Style's profile is only consulted for theAsciishort-circuit; actual color codes come from eachColor.Sequence(...)).Fixes #364
🤖 Generated with Claude Code