Skip to content

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

@Misterio77

Description

@Misterio77

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

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions