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

Output colored red in callr::r() #467

Closed
pwseo opened this issue May 21, 2022 · 5 comments
Closed

Output colored red in callr::r() #467

pwseo opened this issue May 21, 2022 · 5 comments

Comments

@pwseo
Copy link

pwseo commented May 21, 2022

When using cli:: functions inside a callr::r invocation, output is always colored red (first noticed this using W Landau's targets package).
I'm not really sure this is even cli's fault, but I'm not experienced enought to debug this on my own.

Here's a screenshot of the problem:
image

@gaborcsardi
Copy link
Member

cli uses message() which outputs to the standard error, and RStudio colours the standard error red.

When not using callr, cli figures out that it is in RStudio, so it outputs to the standard output to avoid this. But in the callr subprocess we have no way to tell if the output will be eventually in RStudio or not, so we cannot do that.

So there is not much we can do about this, apart from hoping that the red default will change.

@pwseo
Copy link
Author

pwseo commented May 28, 2022

Oh, I see. Thank you for the clarification. I have a follow-up question though: Is there a way to configure cli to use stdout instead of stderr, then?

@pwseo pwseo closed this as completed Jun 3, 2022
@gaborcsardi
Copy link
Member

cli uses base::message() for its messages. I don't know if it is possible to make message() print to stdout.

@wlandau
Copy link

wlandau commented Jun 16, 2022

cli uses message() which outputs to the standard error, and RStudio colours the standard error red.

I also see the red text executing callr::r(\() cli::cli_text("abc"), show = TRUE) in an R process launched in a regular terminal outside the RStudio IDE. Am I missing something?

@wlandau
Copy link

wlandau commented Jan 23, 2024

I can remove the red if I redirect stderr to stdout, but I lose other colors as well. In the reprex below, I expect the check mark to be green, but it is white (both in the terminal and in RStudio Desktop.) How do I preserve the colors I would see outside the callr process? options(cli.color = TRUE) does not seem to work on my end.

tmp <- callr::r(
  \() {
    options(cli.color = TRUE)
    cli::cli_alert_success('abc')
  },
  show = TRUE,
  stderr = "2>&1"
)
abc

I am using cli 3.6.2 and callr 3.7.3

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

No branches or pull requests

3 participants