Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow option to retain ANSI color codes when output is piped #239

Open
damianpowell opened this issue May 26, 2022 · 1 comment
Open

Allow option to retain ANSI color codes when output is piped #239

damianpowell opened this issue May 26, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@damianpowell
Copy link
Contributor

In PowerShell Core (pwsh), the following command outputs human readable logs, in colour:

Get-Content .\upgrade-assistant.clef  | seqcli print

image

However, if I want to view this at the command line using something like less then the ANSI colour codes are stripped out:

Get-Content .\upgrade-assistant.clef  | seqcli print | less

image

I assume seqcli strips out ANSI control codes when the output is being piped or redirected in order to be friendly to consumers further down the pipe. It would be great if we could force seqcli print to emit the ANSI colour codes in some circumstances, particularly interactive console sessions. Perhaps a positive version of --no-color with an interactive-friendly shorthand version?

Get-Content .\upgrade-assistant.clef  | seqcli print --color | less

or

Get-Content .\upgrade-assistant.clef  | seqcli print -c | less

It would be great if this could be implemented in clef-tool too, but I understand where the activity is...

@nblumhardt
Copy link
Member

Thanks for the suggestion! Perhaps --force-color would make the behavior of the flag slightly clearer?

The print command works by pushing events through Serilog.Sinks.Console, which already accepts an applyThemeToRedirectedOutput flag.

Along with specifying this, --force-color would also have to specify an ANSI console theme (on Windows, Serilog.Sinks.Console doesn't use ANSI codes by default).

Open to a PR, if anyone's able to take a look.

@nblumhardt nblumhardt added enhancement New feature or request good first issue Good for newcomers labels May 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants