Skip to content

Commit

Permalink
Add bidi option
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Jul 27, 2021
1 parent f969054 commit 401c3cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
23 changes: 15 additions & 8 deletions R/ctl_colonnade.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ctl_colonnade <- function(x, has_row_id = TRUE, width = NULL, controller = new_t
flat_tiers <- map(flat_tiers, function(.x) c(rowid_formatted, .x))
}

out <- map(flat_tiers, format_colonnade_tier_2)
out <- map(flat_tiers, format_colonnade_tier_2, bidi = get_pillar_option_bidi())

extra_cols <- as.list(x)[seq2(length(pillars) + 1L, nc)]
new_colonnade_body(out, extra_cols = extra_cols)
Expand Down Expand Up @@ -81,19 +81,26 @@ pillar_format_tier <- function(pillars, widths, max_widths) {
}

# Reference: https://www.w3.org/International/questions/qa-bidi-unicode-controls
fsi <- function(...) paste0("\u2068", ..., "\u2069")
lro <- function(...) paste0("\u202d", ..., "\u202c")
fsi <- function(x) {
paste0("\u2068", x, "\u2069")
}

format_colonnade_tier_2 <- function(x) {
"!!!!!DEBUG format_colonnade_tier_2(`v(x)`)"
lro <- function(x) {
paste0("\u202d", x, "\u202c")
}

format_colonnade_tier_2 <- function(x, bidi = FALSE) {
if (length(x) == 0) {
return(character())
}

x <- map(x, fsi)
out <- exec(paste, !!!x)
lro(out)
if (bidi) {
x <- map(x, fsi)
out <- exec(paste, !!!x)
lro(out)
} else {
exec(paste, !!!x)
}
}

new_colonnade_body <- function(x, extra_cols) {
Expand Down
9 changes: 9 additions & 0 deletions R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,13 @@ pillar_options <- list2(
max_footer_lines = make_option_impl(
getOption("pillar.max_footer_lines", default = 7L)
),
#' - `bidi`: Set to `TRUE` for experimental support for bidirectional scripts.
#' Default: `FALSE`. When this option is set, "left right override"
#' and "first strong isolate"
#' [Unicode controls](https://www.w3.org/International/questions/qa-bidi-unicode-controls)
#' are inserted to ensure that text appears in its intended direction
#' and that the column headings correspond to the correct columns.
bidi = make_option_impl(
getOption("pillar.bidi", default = FALSE)
),
)

0 comments on commit 401c3cd

Please sign in to comment.