Skip to content

Commit

Permalink
Merge branch 'main' into f-data-decides-width
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Apr 22, 2022
2 parents 16e614f + ac134a2 commit 8a88dba
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
15 changes: 5 additions & 10 deletions R/ctl_pillar_component.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,11 @@ pillar_get_min_width <- function(x) {
}

pillar_format_parts_2 <- function(x, width, is_focus = FALSE) {
formatted <- map(x, function(.x) format(.x[[1L]], width = min(width, get_width(.x))))

# FIXME: Support missing type component
flat_focus_pos <- integer()
if (is_focus) {
type_idx <- which(names(x) == "type")
if (length(type_idx) > 0) {
formatted[[type_idx]] <- crayon_underline(formatted[[type_idx]])
}
}
formatted <- map(x, function(.x) format(
.x[[1L]],
width = min(width, get_width(.x)),
is_focus = is_focus
))

align <- attr(formatted[["data"]], "align", exact = TRUE) %||% "left"

Expand Down
24 changes: 2 additions & 22 deletions R/tick.R
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
format_title <- function(x, width) {
out <- align(str_trunc(x, width))

# HACK: Abbreviating text inbetween ticks
ticked <- grepl("^`", x)
if (!any(ticked)) {
return(out)
}

ticked[which(get_extent(x[ticked]) <= width)] <- FALSE
if (!any(ticked)) {
return(out)
}

x_ticked <- x[ticked]
rx <- "^`(.*)(`[^`]*)$"
match <- gsub(rx, "\\1", x[ticked])
rest <- gsub(rx, "\\2", x[ticked])

short <- str_trunc(match, width + get_extent(match) - get_extent(x_ticked))
out[ticked] <- align(paste0("`", short, rest))
out
format_title <- function(x, width, footnote = FALSE) {
align(str_trunc(x, width, if (footnote) "untick_footnote" else "untick"))
}

tick_names_if_needed <- function(x) {
Expand Down
8 changes: 6 additions & 2 deletions R/type.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ get_pillar_type <- function(x) {
}

#' @export
format.pillar_type <- function(x, width = NULL, ...) {
format_type_sum(x[[1]], width)
format.pillar_type <- function(x, width = NULL, ..., is_focus = FALSE) {
out <- format_type_sum(x[[1]], width)
if (is_focus) {
out <- crayon_underline(out)
}
out
}

format_full_pillar_type <- function(x) {
Expand Down
23 changes: 23 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ str_add_ellipsis <- function(x, str_width, width, shorten) {
abbr <- substr2_ctl(x, 1, width - 1, type = "width")
paste0(abbr, get_ellipsis())
},
untick = str_add_ellipsis_untick(x, str_width, width),
untick_footnote = str_add_ellipsis_untick(x, str_width, width, footnote = TRUE),
front = {
abbr <- substr2_ctl(x, str_width - width + 2, str_width, type = "width")
paste0(get_ellipsis(), abbr)
Expand All @@ -60,6 +62,27 @@ str_add_ellipsis <- function(x, str_width, width, shorten) {
)
}

str_add_ellipsis_untick <- function(x, str_width, width, footnote = FALSE) {
if (footnote) {
width <- width - 1L
}

rx <- "^(.*[^`])(`?)$"
match <- gsub(rx, "\\1", x)
rest <- gsub(rx, "\\2", x)

short <- substr2_ctl(match, 1, width - 1L + get_extent(match) - str_width, type = "width")
abbr <- paste0(short, get_ellipsis(), rest)

if (footnote) {
# Placeholder, regular title can't end with this string,
# we can use this to detect a footnote
abbr <- paste0(abbr, "\u02df")
}

abbr
}

paste_with_space_if_needed <- function(x, y) {
if (y == "") {
x
Expand Down

0 comments on commit 8a88dba

Please sign in to comment.