R/utils.R

msg <- function(..., startup = FALSE) {
  if (startup) {
    if (!isTRUE(getOption("pearsonverse.quiet"))) {
      packageStartupMessage(text_col(...))
    }
  } else {
    message(text_col(...))
  }
}

text_col <- function(x) {
  # If RStudio not available, messages already printed in black
  if (!rstudioapi::isAvailable()) {
    return(x)
  }

  if (!rstudioapi::hasFun("getThemeInfo")) {
    return(x)
  }

  theme <- rstudioapi::getThemeInfo()

  if (isTRUE(theme$dark)) crayon::white(x) else crayon::black(x)

}
pearsonplc/pearsonverse documentation built on May 30, 2019, 3:45 p.m.