Skip to content

Fix --color=always for piped output#38

Merged
martinemde merged 1 commit intomainfrom
martinemde/ukkkpzlkrttz
Jan 21, 2026
Merged

Fix --color=always for piped output#38
martinemde merged 1 commit intomainfrom
martinemde/ukkkpzlkrttz

Conversation

@martinemde
Copy link
Copy Markdown
Owner

Lipgloss and glamour have internal TTY detection that automatically strips ANSI color codes when stdout is piped, regardless of what the application code requests. This made --color=always ineffective.

The fix uses lipgloss.SetColorProfile() to configure the global color profile early, before any rendering:

  • "always": Uses termenv.EnvColorProfile() which detects terminal color capabilities from environment variables (COLORTERM, TERM) without checking if stdout is a TTY. This respects the terminal's actual color support while allowing colors through pipes.

  • "never": Forces termenv.Ascii to disable all colors globally.

  • "auto": Lets lipgloss use its default TTY-based detection.

For glamour markdown rendering, --color=always now also passes WithColorProfile(termenv.TrueColor) to force colors.

This simplification also removes the redundant applyColorToIcon and applyColorToStyle wrapper functions since the global profile now handles color stripping automatically.

Lipgloss and glamour have internal TTY detection that automatically
strips ANSI color codes when stdout is piped, regardless of what the
application code requests. This made --color=always ineffective.

The fix uses lipgloss.SetColorProfile() to configure the global color
profile early, before any rendering:

- "always": Uses termenv.EnvColorProfile() which detects terminal color
  capabilities from environment variables (COLORTERM, TERM) without
  checking if stdout is a TTY. This respects the terminal's actual color
  support while allowing colors through pipes.

- "never": Forces termenv.Ascii to disable all colors globally.

- "auto": Lets lipgloss use its default TTY-based detection.

For glamour markdown rendering, --color=always now also passes
WithColorProfile(termenv.EnvColorProfile()) to force colors.

This simplification also removes the redundant applyColorToIcon and
applyColorToStyle wrapper functions since the global profile now handles
color stripping automatically.
@martinemde martinemde enabled auto-merge (squash) January 21, 2026 03:55
@martinemde martinemde merged commit a856258 into main Jan 21, 2026
3 checks passed
@martinemde martinemde deleted the martinemde/ukkkpzlkrttz branch January 21, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant