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

fix(cli/tools): colors do not properly detect not tty #13782

Conversation

antoniomuso
Copy link
Contributor

I don't test this for now, because I don't know where to put these kinds of tests.

fix #12224

@CLAassistant
Copy link

CLAassistant commented Feb 27, 2022

CLA assistant check
All committers have signed the CLA.

@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from 04c0506 to 7948bcb Compare February 27, 2022 08:21
@antoniomuso antoniomuso marked this pull request as draft February 27, 2022 08:36
@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from 7948bcb to 924dc71 Compare February 27, 2022 08:58
@antoniomuso antoniomuso marked this pull request as ready for review February 27, 2022 09:05
@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from 924dc71 to 4d52e65 Compare February 27, 2022 09:08
@kt3k
Copy link
Member

kt3k commented Feb 27, 2022

I think overriding use_color (NO_COLOR) based on tty is not a good idea. Because we override it, we also need a new env var FORCE_COLOR here, and having two env vars both controlling color is confusing.

@antoniomuso
Copy link
Contributor Author

antoniomuso commented Feb 27, 2022

Do you think it is better to have different functions use_color and is_tty and check directly in the main? Or do you think it is better to add a new variable in bootstrap options called is_tty?

@kt3k
Copy link
Member

kt3k commented Feb 27, 2022

Do you think it is better to have different functions use_color and is_tty and check directly in the main? Or do you think it is better to add a new variable in bootstrap options called is_tty?

I think we need both. First check IS_TTY and store its value (you already did it), and expose it as is_tty function. The main module checks is_tty function and pass it as bootstrap option next to noColor option (You need to extend BootstrapOptions struct). Finally set the no color option of console module to noColor || !isTty in runtime/js/99_main.js script ref:

colors.setNoColor(noColor);

@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from 4d52e65 to 8c0084d Compare February 27, 2022 10:18
@kt3k
Copy link
Member

kt3k commented Feb 27, 2022

BTW you can test this behavior by passing stdout: "piped" options to Deno.run command.

const p = Deno.run({
  cmd: [
    Deno.execPath(),
    "eval",
    "console.log(1)",
  ],
  stdout: "piped",
});
const output = await p.output();

This should make is_tty = false

pid,
ppid,
unstableFlag,
cpuCount,
} = runtimeOptions;

colors.setNoColor(noColor);
colors.setNoColor(noColor || !isTty);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch 3 times, most recently from 1d8598b to bb2ddb8 Compare February 27, 2022 10:57
@antoniomuso
Copy link
Contributor Author

I put the test, I don't know if it is the right place. Let me know!

@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from bb2ddb8 to 84b9ba9 Compare February 27, 2022 11:17
@antoniomuso antoniomuso requested a review from kt3k February 27, 2022 11:19
@antoniomuso
Copy link
Contributor Author

antoniomuso commented Feb 27, 2022

I don't know if ci / test release ubuntu-20.04-xl fail because I miss to add in test { permissions: { run: true } }

@antoniomuso antoniomuso force-pushed the fix/colors-not-do-not-properly-detect-not-tty branch from 84b9ba9 to d100dd6 Compare February 27, 2022 12:35
@kt3k
Copy link
Member

kt3k commented Feb 28, 2022

The test case looks good to me. Nice work!

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

console.* methods do not properly detect non-tty output and still add colors to output
3 participants