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

[FEAT] - Terminal detection for colored/raw output #52

Open
Misterio77 opened this issue Feb 11, 2025 · 0 comments
Open

[FEAT] - Terminal detection for colored/raw output #52

Misterio77 opened this issue Feb 11, 2025 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@Misterio77
Copy link

Misterio77 commented Feb 11, 2025

Is your feature request related to a problem? Please describe.

As of the time of writing, the CLI defaults to formatting the output (i.e. with color escape codes), even when piped, which breaks tools such as jq.

I think the CLI should, by default, figure out whether it's in a terminal or being piped, and use colored output accordingly. This should be overridable by the user for both ways (force colored or force raw).

Describe the solution you'd like

I suggest following the usual GNU way and adding a --color argument.

--color can be set to always, never, or auto (the default). always ensures colored output, and never ensures raw output. auto will cause the CLI to emit formatted output only if the detected stdout is a terminal, otherwise raw output will be emitted instead.

If your CLI arg parser supports that, it'd be nice if passing --color by itself (e.g. as a boolean arg) works the same as passing --color=always.

The current --raw arg can be aliased to --color=never for backwards compatibility.

Describe alternatives you've considered

Other possible solutions might include:

  • Never color the output when a pipe is detected. I don't like this one because sometimes you want, for example, to pipe colored output to a pager (e.g. mgc --color always | less -r). The tty detection is not a perfect heuristic, so it being overridable is important.
  • Default to raw output, and add a --color boolean flag instead. This may breaking existing scripts that (for some insane reason) rely on colored output, and degrades the user experience when using the CLI interactively.

Additional context

@Misterio77 Misterio77 added the enhancement New feature or request label Feb 11, 2025
@publi0 publi0 assigned luizcavalcanti and unassigned lfpicoloto1 Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants