Skip to content
Permalink
Browse files
Create color tables at runtime
Not at install time. Closes #37
  • Loading branch information
gaborcsardi committed Sep 13, 2017
1 parent 6278386 commit e2b368ac27331d82154f85299f18efbc36227caa
Showing 1 changed file with 11 additions and 6 deletions.
@@ -15,15 +15,15 @@ show_ansi_colors <- function(colors = num_colors()) {
if (colors < 8) {
cat("Colors are not supported")
} else if (colors < 256) {
cat(ansi_colors_8, sep = "")
cat(ansi_colors_8(), sep = "")
invisible(ansi_colors_8)
} else {
cat(ansi_colors_256, sep = "")
cat(ansi_colors_256(), sep = "")
invisible(ansi_colors_256)
}
}

ansi_colors_256_col <-
ansi_colors_256_col <- function() {
sapply(0:5, function(r) {
sapply(0:5, function(g) {
c(sapply(0:5, function(b) {
@@ -32,19 +32,24 @@ ansi_colors_256_col <-
}), "\n")
})
})
}

ansi_colors_256_grey <-
ansi_colors_256_grey <- function() {
sapply(0:23, function(g) {
s <- paste0(" grey ", format(g, width = 2), " ")
style(s, as = "grey",
bg = make_style(grey(g / 23), grey = TRUE, bg = TRUE)) %+%
(if ((g + 1) %% 6) "" else "\n")
})
}

ansi_colors_256 <- c(ansi_colors_256_col, "\n", ansi_colors_256_grey)
ansi_colors_256 <- function() {
c(ansi_colors_256_col(), "\n", ansi_colors_256_grey())
}

ansi_colors_8 <-
ansi_colors_8 <- function () {
multicol(sapply(seq_along(builtin_styles), function(s) {
st <- names(builtin_styles)[s]
styled <- st %+% ": " %+% style("foobar", as = st) %+% " "
}))
}

0 comments on commit e2b368a

Please sign in to comment.