Skip to content

Commit

Permalink
Add fallbacks for non-Unicode locales
Browse files Browse the repository at this point in the history
  • Loading branch information
gvelasq committed Apr 7, 2021
1 parent 02a338f commit 7c5d689
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/statascii.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,20 @@ wrap_tbl <- function(tbl, M = M, M1 = M1, width = getOption("width")) {
}

add_line <- function(n) {
tmp <- purrr::map_chr(n, ~paste0(rep(color_grey("\u2500"), . + 2L), collapse = ""))
paste0(color_grey("\u2500"), paste0(tmp, collapse = color_grey("\u253c")))
tmp <- purrr::map_chr(n, ~paste0(rep(color_grey(u2500), . + 2L), collapse = ""))
paste0(color_grey(u2500), paste0(tmp, collapse = color_grey(u253c)))
}

add_dash <- function(n) {
tmp <- purrr::map_chr(n, ~paste0(rep(color_grey("-"), . + 2L), collapse = ""))
paste0(color_grey("-"), paste0(tmp, collapse = color_grey("\u253c")))
paste0(color_grey("-"), paste0(tmp, collapse = color_grey(u253c)))
}

add_row_oneway <- function(x, n) {
row_content <- purrr::map2_chr(x, seq_along(x), ~sprintf(paste0("%", n[.y], "s"), .x))
paste0(
paste0(paste0(" ", row_content[1], " "), collapse = ""),
color_grey("\u2502"),
color_grey(u2502),
" ",
paste0(paste0(" ", row_content[-1], " "), collapse = " ")
)
Expand All @@ -223,9 +223,9 @@ add_row_twoway <- function(x, n) {
row_content <- purrr::map2_chr(x, seq_along(x), ~sprintf(paste0("%", n[.y], "s"), .x))
paste0(
paste0(paste0(" ", row_content[1], " "), collapse = ""),
color_grey("\u2502"),
color_grey(u2502),
paste0(paste0(" ", row_content[2:(length(row_content) - 1L)], " "), collapse = ""),
color_grey("\u2502"),
color_grey(u2502),
paste0(paste0(" ", row_content[length(row_content)], " "), collapse = " ")
)
}
10 changes: 10 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ color_grey <- function(x) {
color_red <- function(x) {
crayon::red(x)
}

if (l10n_info()[["UTF-8"]]) {
u2500 <- "\u2500"
u2502 <- "\u2502"
u253c <- "\u253c"
} else {
u2500 <- "-"
u2502 <- "|"
u253c <- "+"
}

0 comments on commit 7c5d689

Please sign in to comment.