Skip to content

Preserve the color theme of the parent process? #297

@wlandau

Description

@wlandau

Issue

From r-lib/cli#467, cli colors printed from inside callr are not preserved when forwarded to the main process.

Example:

out <- callr::r(
  \() {
     cli::ansi_palette_show()
  },
  show = TRUE
)

Image

Causes

  1. cli uses message(), which goes to standard error.
  2. The callr child process does not necessarily choose the same number of ANSI colors as the parent process.

Evidence of (2):

cli::num_ansi_colors()
#> [1] 256
callr::r(\() cli::num_ansi_colors())
#> [1] 1

Manual workarounds

  1. Redirect stderr to stdout.
  2. Inside the callr child process, set the cli.num_colors option to the correct number of colors.

Example:

out <- callr::r(
  \() {
     options(cli.num_colors = 256)
     cli::ansi_palette_show()
  },
  show = TRUE,
  stderr = "2>&1"
)

Image

Request

Is there a way to make cli colors "just work" (TM) using the defaults of both packages? I'm not sure what would need to change, but I do believe that aligning the child process colors with those of the parent would be the most intuitive and convenient default behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions