Skip to content

Commit e2b368a

Browse files
committed
Create color tables at runtime
Not at install time. Closes #37
1 parent 6278386 commit e2b368a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

R/show.r

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ show_ansi_colors <- function(colors = num_colors()) {
1515
if (colors < 8) {
1616
cat("Colors are not supported")
1717
} else if (colors < 256) {
18-
cat(ansi_colors_8, sep = "")
18+
cat(ansi_colors_8(), sep = "")
1919
invisible(ansi_colors_8)
2020
} else {
21-
cat(ansi_colors_256, sep = "")
21+
cat(ansi_colors_256(), sep = "")
2222
invisible(ansi_colors_256)
2323
}
2424
}
2525

26-
ansi_colors_256_col <-
26+
ansi_colors_256_col <- function() {
2727
sapply(0:5, function(r) {
2828
sapply(0:5, function(g) {
2929
c(sapply(0:5, function(b) {
@@ -32,19 +32,24 @@ ansi_colors_256_col <-
3232
}), "\n")
3333
})
3434
})
35+
}
3536

36-
ansi_colors_256_grey <-
37+
ansi_colors_256_grey <- function() {
3738
sapply(0:23, function(g) {
3839
s <- paste0(" grey ", format(g, width = 2), " ")
3940
style(s, as = "grey",
4041
bg = make_style(grey(g / 23), grey = TRUE, bg = TRUE)) %+%
4142
(if ((g + 1) %% 6) "" else "\n")
4243
})
44+
}
4345

44-
ansi_colors_256 <- c(ansi_colors_256_col, "\n", ansi_colors_256_grey)
46+
ansi_colors_256 <- function() {
47+
c(ansi_colors_256_col(), "\n", ansi_colors_256_grey())
48+
}
4549

46-
ansi_colors_8 <-
50+
ansi_colors_8 <- function () {
4751
multicol(sapply(seq_along(builtin_styles), function(s) {
4852
st <- names(builtin_styles)[s]
4953
styled <- st %+% ": " %+% style("foobar", as = st) %+% " "
5054
}))
55+
}

0 commit comments

Comments
 (0)