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

(cli): enforce colored output #12270

Open
metametadata opened this issue Dec 29, 2020 · 5 comments
Open

(cli): enforce colored output #12270

metametadata opened this issue Dec 29, 2020 · 5 comments
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1 package/tools Related to AWS CDK Tools or CLI

Comments

@metametadata
Copy link

Introduce an arg for cdk CLI app to enforce colored output. There's no such feature yet, the user either can always disable colors (--no-color) or let the app detect the TTY and use colors depending on that (default).

Use Case

I call cdk programmatically from Clojure (using built-in Java ProcessBuilder) and want to get the colored output to sometimes print it myself.

The workarounds currently are to use pty4j or wrap calls with script so that cdk thinks it prints into TTY.

Proposed Solution

It can be a new arg, e.g. --always-color.

Or something like --color=[auto, always, never] similarly to git CLI. But this may require deprecating --no-color.


This is a 🚀 Feature Request

@metametadata metametadata added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Dec 29, 2020
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Dec 29, 2020
@rix0rrr rix0rrr added effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2 labels Jan 6, 2021
@rix0rrr rix0rrr removed their assignment Jun 3, 2021
@ryparker
Copy link
Contributor

ryparker commented Jun 3, 2021

Hey @metametadata 👋🏻

Thanks for suggesting this. I'm going to leave this issue as p2 which means that we are unable to work on this immediately. However we use +1s to help us prioritize our work, and as always we are happy to take contributions.

If anyone is interested in lending a hand this is a great first issue to tackle. A good place to start is by following the steps described in our contribution guidelines.

@ryparker ryparker removed the needs-triage This issue or PR still needs to be triaged. label Jun 3, 2021
@jk2l
Copy link

jk2l commented May 16, 2023

i went and search the codes and found reference of FORCE_COLOR in environment variable. it seem if you set this environment variable to "1" it will force ANSI out

p.s. CodeBuild still strip it off

@Shigerello
Copy link

It's can be irrelevant, but I found the following Node.js documentation about the environment variable FORCE_COLOR:

https://nodejs.org/docs/latest-v18.x/api/tty.html#writestreamgetcolordepthenv

To enforce a specific color support, use one of the below environment settings.

2 colors: FORCE_COLOR = 0 (Disables colors)
16 colors: FORCE_COLOR = 1
256 colors: FORCE_COLOR = 2
16,777,216 colors: FORCE_COLOR = 3
Disabling color support is also possible by using the NO_COLOR and NODE_DISABLE_COLORS environment variables.

@github-actions github-actions bot added p1 and removed p2 labels Jan 14, 2024
Copy link

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@jlscott3
Copy link

Background

The shutoff of coloring for non-tty output happens in cli.ts by setting environment variable FORCE_COLOR=0. CDK uses chalk for color output. Chalk uses the no-color option as well as the FORCE_COLOR environment variable. Per the chalk docs, FORCE_COLOR overrides other color support checks.

In CDK, setting FORCE_COLOR=1 overrides the --no-color cli option when outputting to a tty, and also provides color output in non-tty environments. For example:

> FORCE_COLOR=1 cdk diff --no-color

produces color output.

A quick test of non-tty output in zsh shows similar behavior there:

> (cdk diff) 2>&1 | cat

produces monochrome output, but

> (FORCE_COLOR=1 cdk diff) 2>&1 | cat

produces color output

Chalk recognizes 3 levels of color output and forces color support to truecolor (level 3) if environment variable COLORTERM=truecolor is set, regardless of whether FORCE_COLOR is set to 1, 2, or 3.

Proposal

Add an optional --force-color cli option to the CDK CLI. This option would require a value of 1, 2, or 3 to mirror chalk’s handling of color levels. Implementation would set environment variable FORCE_COLOR to the argument’s value regardless of tty status and would thus mimic the behavior of setting the FORCE_COLOR environment variable directly.

Proposed description for --force-color:

Forces color output in the console. Set to 1 for 16-color support, 2 for 256-color support, or 3 for truecolor support. Overrides --no-color if it is also specified.

This will also require updates to the CDK Developer Guide. I’m not clear on the process for updating those docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. good first issue Related to contributions. See CONTRIBUTING.md p1 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

6 participants