File: logo.R

package info (click to toggle)
r-cran-tidyverse 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 688 kB
  • sloc: sh: 11; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

#' The tidyverse logo, using ASCII or Unicode characters
#'
#' Use [cli::ansi_strip()] to get rid of the colors.
#'
#' @param unicode Whether to use Unicode symbols. Default is `TRUE`
#'   on UTF-8 platforms.
#'
#' @md
#' @export
#' @examples
#' tidyverse_logo()

tidyverse_logo <- function(unicode = cli::is_utf8_output()) {
  logo <- c(
    "0 __  _    __   1    2           3  4 ",
    " / /_(_)__/ /_ ___  _____ _______ ___ ",
    "/ __/ / _  / // / |/ / -_) __(_-</ -_)",
    "\\__/_/\\_,_/\\_, /|___/\\__/_/ /___/\\__/ ",
    "     5  6 /___/      7      8       9 ")

  hexa <- c("*", ".", "o", "*", ".", "*", ".", "o", ".", "*")
  if (unicode) hexa <- c("*" = "\u2b22", "o" = "\u2b21", "." = ".")[hexa]

  cols <- c("red", "yellow", "green", "magenta", "cyan",
            "yellow", "green", "white", "magenta", "cyan")

  col_hexa <- purrr::map2(hexa, cols, ~ cli::make_ansi_style(.y)(.x))

  for (i in 0:9) {
    pat <- paste0("\\b", i, "\\b")
    logo <- sub(pat, col_hexa[[i + 1]], logo)
  }

  structure(cli::col_blue(logo), class = "tidyverse_logo")
}

#' @export

print.tidyverse_logo <- function(x, ...) {
  cat(x, ..., sep = "\n")
  invisible(x)
}