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

Detection of ANSI color support in console has chhanged? #5445

Open
strengejacke opened this issue Nov 21, 2024 · 4 comments
Open

Detection of ANSI color support in console has chhanged? #5445

strengejacke opened this issue Nov 21, 2024 · 4 comments
Labels
info needed Waiting on information

Comments

@strengejacke
Copy link

strengejacke commented Nov 21, 2024

This example used to work

Following setup

Positron Version: 2024.11.0 (system setup) build 140
Code - OSS Version: 1.93.0
Commit: e0d844b031f95acbf89f234a2cce2af9b6721f6c
Date: 2024-10-31T14:14:22.699Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.22631

Reprex

insight::print_color("test", "green")

Result (as expected)

Image

New Positron version

Positron Version: 2024.12.0 (system setup) build 41
Code - OSS Version: 1.93.0
Commit: 39536c265d6828a68291984d0d359170316d055e
Date: 2024-11-18T02:47:00.983Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.22631

Result (not expected)

Image

I think it's because this code no longer works properly with the latest Positron version:

insight:::.supports_color()
#> [1] FALSE

Created on 2024-11-21 with reprex v2.1.1

.rstudio_with_ansi_support <- function() {
  if (Sys.getenv("RSTUDIO", "") == "") {
    return(FALSE)
  }

  cols <- Sys.getenv("RSTUDIO_CONSOLE_COLOR", "")
  if (cols != "" && !is.na(as.numeric(cols))) {
    return(TRUE)
  }

  requireNamespace("rstudioapi", quietly = TRUE) &&
    rstudioapi::isAvailable() &&
    rstudioapi::hasFun("getConsoleHasColor")
}


.supports_color <- function() {
  enabled <- getOption("crayon.enabled")
  if (!is.null(enabled)) {
    return(isTRUE(enabled))
  }
  if (.rstudio_with_ansi_support() && sink.number() == 0) {
    return(TRUE)
  }
  if (!isatty(stdout())) {
    return(FALSE)
  }
  if (Sys.info()["sysname"] == "windows") {
    if (Sys.getenv("ConEmuANSI") == "ON") {
      return(TRUE)
    }
    if (Sys.getenv("CMDER_ROOT") != "") {
      return(TRUE)
    }
    return(FALSE)
  }
  if ("COLORTERM" %in% names(Sys.getenv())) {
    return(TRUE)
  }
  if (Sys.getenv("TERM") == "dumb") {
    return(FALSE)
  }
  grepl("^screen|^xterm|^vt100|color|ansi|cygwin|linux", Sys.getenv("TERM"),
    ignore.case = TRUE, perl = TRUE
  )
}

Could be that this is no bug, but Positron just changed its "identification"?

@juliasilge
Copy link
Contributor

Interesting! When I use Positron 2024.11.0 (Universal) build 140 on a Mac, I don't see the green:

Image

Do you mind reinstalling 2024.11.0 build 140 and finding out exactly how .rstudio_with_ansi_support() is returning true? We would never expect Sys.getenv("RSTUDIO") to return 1. You can use Sys.getenv("POSITRON") though!

@juliasilge juliasilge added the info needed Waiting on information label Nov 21, 2024
@strengejacke
Copy link
Author

Positron Version: 2024.12.0 (system setup) build 41
Code - OSS Version: 1.93.0
Commit: 39536c265d6828a68291984d0d359170316d055e
Date: 2024-11-18T02:47:00.983Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.26100
Sys.getenv("RSTUDIO", "") == ""
#> [1] TRUE

Sys.getenv("RSTUDIO_CONSOLE_COLOR", "")
#> [1] ""

requireNamespace("rstudioapi", quietly = TRUE) &&
  rstudioapi::isAvailable() &&
  rstudioapi::hasFun("getConsoleHasColor")
#> [1] FALSE

getOption("crayon.enabled")
#> [1] FALSE

sink.number() == 0
#> [1] FALSE

isatty(stdout())
#> [1] FALSE

Sys.getenv("ConEmuANSI") == "ON"
#> [1] FALSE

Sys.getenv("CMDER_ROOT")
#> [1] ""

"COLORTERM" %in% names(Sys.getenv())
#> [1] TRUE

Sys.getenv("TERM") == "dumb"
#> [1] FALSE

grepl("^screen|^xterm|^vt100|color|ansi|cygwin|linux", Sys.getenv("TERM"))
#> [1] FALSE

Created on 2024-11-22 with reprex v2.1.1

Positron Version: 2024.11.0 (system setup) build 140
Code - OSS Version: 1.93.0
Commit: e0d844b031f95acbf89f234a2cce2af9b6721f6c
Date: 2024-10-31T14:14:22.699Z
Electron: 30.4.0
Chromium: 124.0.6367.243
Node.js: 20.15.1
V8: 12.4.254.20-electron.0
OS: Windows_NT x64 10.0.26100
Sys.getenv("RSTUDIO", "") == ""
#> [1] TRUE

Sys.getenv("RSTUDIO_CONSOLE_COLOR", "")
#> [1] ""

requireNamespace("rstudioapi", quietly = TRUE) &&
  rstudioapi::isAvailable() &&
  rstudioapi::hasFun("getConsoleHasColor")
#> [1] FALSE

getOption("crayon.enabled")
#> [1] FALSE

sink.number() == 0
#> [1] FALSE

isatty(stdout())
#> [1] FALSE

Sys.getenv("ConEmuANSI") == "ON"
#> [1] FALSE

Sys.getenv("CMDER_ROOT")
#> [1] ""

"COLORTERM" %in% names(Sys.getenv())
#> [1] TRUE

Sys.getenv("TERM") == "dumb"
#> [1] FALSE

grepl("^screen|^xterm|^vt100|color|ansi|cygwin|linux", Sys.getenv("TERM"))
#> [1] FALSE

Created on 2024-11-22 with reprex v2.1.1

@strengejacke
Copy link
Author

hm, I don't see any differences...

@strengejacke
Copy link
Author

Ok, adding Sys.getenv("POSITRON") solves the problem, so this issue could be closed. I'm still a bit confused why the return values of the above code are the same for both Positron versions, but in the latest, text is not colored, in the previous version, it is. I must be missing something here.

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

No branches or pull requests

2 participants