Skip to content

Disable ANSI when stdout or stderr is redirected#2047

Merged
patriksvensson merged 1 commit intospectreconsole:mainfrom
1PetarVujakovic:fix-ansi-redirect
Mar 14, 2026
Merged

Disable ANSI when stdout or stderr is redirected#2047
patriksvensson merged 1 commit intospectreconsole:mainfrom
1PetarVujakovic:fix-ansi-redirect

Conversation

@1PetarVujakovic
Copy link
Copy Markdown
Contributor

Fixes #1790

  • I have read the Contribution Guidelines
  • I have checked that there isn't already another pull request that solves the above issue
  • All newly added code is adequately covered by tests
  • All existing tests are still running without errors

Changes

Disable ANSI output when standard output or standard error is redirected while using "AnsiSupport.Detect".

Previously ANSI detection could still return true when output was redirected to a file, which caused escape sequences to be written to the file.

This change disables ANSI when:

  • standard output is redirected
  • standard error is redirected

Explicit "AnsiSupport.Yes" behaviour remains unchanged.

Unit tests were added to verify the behaviour.

@patriksvensson
Copy link
Copy Markdown
Contributor

@1PetarVujakovic No AI agent was used to write this code?

@1PetarVujakovic
Copy link
Copy Markdown
Contributor Author

@1PetarVujakovic No AI agent was used to write this code?

No, the code was written by me. I investigated the issue and implemented the change.

@patriksvensson patriksvensson merged commit 9eb0b0e into spectreconsole:main Mar 14, 2026
3 checks passed
@patriksvensson
Copy link
Copy Markdown
Contributor

Merged! Thank you for your contribution. Much appreciated! 👍

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.

Confusing behaviour around ANSI capability detection when redirecting output to file

2 participants