diff --git a/R/cliapp-docs.R b/R/cliapp-docs.R index 586f5d39b..6e5e9549b 100644 --- a/R/cliapp-docs.R +++ b/R/cliapp-docs.R @@ -328,10 +328,16 @@ NULL #' * `transform`: A function to call on glue substitutions, before #' collapsing them. Note that `transform` is applied prior to #' implementing color via ANSI sequences. -#' * `vec_last`: The last separator when collapsing vectors. -#' * `vec_sep`: The separator to use when collapsing vectors. +#' * `vec_last`: The last separator when collapsing vectors. It may be a +#' function. +#' * `vec_after`: Added after vector elements. It may be a function. +#' * `vec_before`: Added before vector elements. It may be a function. +#' * `vec_sep`: The separator to use when collapsing vectors. It may be +#' a function. It may be a function. +#' * `vec_sep2`: The separator to use when collapsing a length 2 vector. +#' It may be a function. #' * `vec_trunc`: Vectors longer than this will be truncated. Defaults to -#' 100. +#' 100. It may be a function that returns the limit. #' #' More properties might be added later. If you think that a property is #' not applied properly to an element, please open an issue about it in diff --git a/R/inline.R b/R/inline.R index 290ba1989..72a517c2c 100644 --- a/R/inline.R +++ b/R/inline.R @@ -32,18 +32,24 @@ inline_generic <- function(app, x, style) { } inline_collapse <- function(x, style = list()) { - sep <- style[["vec_sep"]] %||% ", " + sep <- call_if_fun(style[["vec_sep"]]) %||% ", " if (length(x) >= 3) { - last <- style$vec_last %||% ", and " + last <- call_if_fun(style$vec_last) %||% ", and " } else { - last <- style$vec_sep2 %||% style$vec_last %||% " and " + last <- call_if_fun(style$vec_sep2) %||% + call_if_fun(style$vec_last) %||% + " and " } - trunc <- style$vec_trunc %||% 100L + trunc <- call_if_fun(style$vec_trunc) %||% 100L if (length(x) > trunc) { x <- c(x[1:trunc], cli::symbol$ellipsis) last <- sep } - glue::glue_collapse(as.character(x), sep = sep, last = last) + + before <- call_if_fun(style[["vec_before"]]) %||% "" + after <- call_if_fun(style[["vec_after"]]) %||% "" + ft <- paste0(before, as.character(x), after) + glue::glue_collapse(ft, sep = sep, last = last) } #' This glue transformer performs the inline styling of cli diff --git a/R/themes.R b/R/themes.R index 582a3458f..b72c25ae9 100644 --- a/R/themes.R +++ b/R/themes.R @@ -224,7 +224,14 @@ builtin_theme <- function(dark = getOption("cli_theme_dark", "auto")) { color = "green" ), span.or = list(vec_sep2 = " or ", vec_last = ", or "), - span.timestamp = list(before = "[", after = "]", color = "grey") + span.timestamp = list(before = "[", after = "]", color = "grey"), + + # bullet list + span.bullets = list( + vec_before = function() paste0(symbol$bullet, " "), + vec_sep = "\f", + vec_last = "\f" + ) ) } diff --git a/man/themes.Rd b/man/themes.Rd index 42edbf96e..53821709a 100644 --- a/man/themes.Rd +++ b/man/themes.Rd @@ -109,10 +109,16 @@ text. \item \code{transform}: A function to call on glue substitutions, before collapsing them. Note that \code{transform} is applied prior to implementing color via ANSI sequences. -\item \code{vec_last}: The last separator when collapsing vectors. -\item \code{vec_sep}: The separator to use when collapsing vectors. +\item \code{vec_last}: The last separator when collapsing vectors. It may be a +function. +\item \code{vec_after}: Added after vector elements. It may be a function. +\item \code{vec_before}: Added before vector elements. It may be a function. +\item \code{vec_sep}: The separator to use when collapsing vectors. It may be +a function. It may be a function. +\item \code{vec_sep2}: The separator to use when collapsing a length 2 vector. +It may be a function. \item \code{vec_trunc}: Vectors longer than this will be truncated. Defaults to -100. +100. It may be a function that returns the limit. } More properties might be added later. If you think that a property is