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

Number of colors with active sink #366

Closed
gaborcsardi opened this issue Oct 26, 2021 · 2 comments
Closed

Number of colors with active sink #366

gaborcsardi opened this issue Oct 26, 2021 · 2 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@gaborcsardi
Copy link
Member

r-lib/crayon#120 also affects cli, not very surprisingly.

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Oct 26, 2021
@gaborcsardi
Copy link
Member Author

Reprex:

sink(tmp <- tempfile())
cat(crayon::red("This is bad"), "\n")
cat(cli::col_red("Also bad"), "\n")
sink()
readLines(tmp)

@DavorJ
Copy link

DavorJ commented Jan 4, 2024

If one uses sink() to split the stream, then there are two or more connections (of which one is usually a file that doesn't support ANSI sequences). In that case the cli::num_ansi_colors defaults to 1, ignoring all ANSI sequences supported by the terminal. In such case the user should probably choose the behavior with R_CLI_NUM_COLORS, but it is not documented. Hence the following suggestion:

?cli::num_ansi_colors mentions: "If you want to turn off ANSI colors, set the NO_COLOR environment variable to a non-empty value."

I would add there: "On the other hand, if you want to enforce a specific number of ANSI colors, set the R_CLI_NUM_COLORS environment variable."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants