What happened
Noticed while wiring TG.Cli into mcec (tig/mcec#252): piping or redirecting help output captures the escape sequences verbatim.
myapp --help > help.txt # help.txt is full of ESC[39m ESC[49m ...
myapp help | some-tool # same
MarkdownRenderer.RenderToAnsi deliberately skips the Console.OutputEncoding fixup when Console.IsOutputRedirected, but it still renders and writes ANSI. Anything that shells out to the CLI and reads stdout (scripts, CI logs, agents that were told to run myapp help) gets escape-littered text.
Suggestion
When Console.IsOutputRedirected is true (or NO_COLOR is set), degrade to plain text: either strip the escapes from the rendered output (a sanitizer pass exists already in TerminalEscapeSanitizer) or render the markdown without color attributes. --opencli/--json stay the machine-readable paths, but plain --help | less should not be garbage.
If the current behavior is intentional (keep colors through pipes for less -R style pagers), a --no-color global and a NO_COLOR env check would still be worth it, plus a line in the docs.
What happened
Noticed while wiring TG.Cli into mcec (tig/mcec#252): piping or redirecting help output captures the escape sequences verbatim.
MarkdownRenderer.RenderToAnsideliberately skips theConsole.OutputEncodingfixup whenConsole.IsOutputRedirected, but it still renders and writes ANSI. Anything that shells out to the CLI and reads stdout (scripts, CI logs, agents that were told to runmyapp help) gets escape-littered text.Suggestion
When
Console.IsOutputRedirectedis true (orNO_COLORis set), degrade to plain text: either strip the escapes from the rendered output (a sanitizer pass exists already inTerminalEscapeSanitizer) or render the markdown without color attributes.--opencli/--jsonstay the machine-readable paths, but plain--help | lessshould not be garbage.If the current behavior is intentional (keep colors through pipes for
less -Rstyle pagers), a--no-colorglobal and aNO_COLORenv check would still be worth it, plus a line in the docs.