Skip to content

Commit

Permalink
Merge branch 'main' into issue#590
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi authored Aug 28, 2024
2 parents 80cd96f + b14d61b commit 0b1a014
Show file tree
Hide file tree
Showing 43 changed files with 280 additions and 69 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ Config/Needs/website:
vctrs
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# cli (development version)

* `ansi_collapse()` and inline collapsing now uses `last` as the separator
(without the serial comma) for two-element vectors if `sep2` is not
given (@rundel, #681).

# cli 3.6.3

* cli now builds on ARM Windows.
Expand Down
5 changes: 3 additions & 2 deletions R/glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ drop_null <- function(x) {
#' to collapse.
#' @param sep Separator. A character string.
#' @param sep2 Separator for the special case that `x` contains only two
#' elements. A character string.
#' elements. A character string. Defaults to the value of `last` without the
#' serial comma.
#' @param last Last separator, if there is no truncation. E.g. use
#' `", and "` for the [serial
#' comma](https://en.wikipedia.org/wiki/Serial_comma). A character string.
Expand Down Expand Up @@ -112,7 +113,7 @@ drop_null <- function(x) {
#' # head style
#' ansi_collapse(letters, trunc = 5, style = "head")

ansi_collapse <- function(x, sep = ", ", sep2 = " and ", last = ", and ",
ansi_collapse <- function(x, sep = ", ", sep2 = sub("^,", "", last), last = ", and ",
trunc = Inf, width = Inf, ellipsis = symbol$ellipsis,
style = c("both-ends", "head")) {

Expand Down
4 changes: 2 additions & 2 deletions R/inline.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ inline_generic <- function(app, x, style) {
}

inline_collapse <- function(x, style = list()) {
sep <- style[["vec-sep"]] %||% style[["vec_sep"]] %||% ", "
sep2 <- style[["vec-sep2"]] %||% style[["vec_sep2"]] %||% " and "
last <- style[["vec-last"]] %||% style[["vec_last"]] %||% ", and "
sep <- style[["vec-sep"]] %||% style[["vec_sep"]] %||% ", "
sep2 <- style[["vec-sep2"]] %||% style[["vec_sep2"]] %||% sub("^,", "", last)

trunc <- style[["vec-trunc"]] %||% style[["vec_trunc"]] %||% 20L
col_style <- style[["vec-trunc-style"]] %||% "both-ends"
Expand Down
17 changes: 12 additions & 5 deletions R/pluralize.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ NULL
make_quantity <- function(object) {
val <- if (is.numeric(object)) {
stopifnot(length(object) == 1)
as.integer(object)

if (is.finite(object))
as.integer(object)
else
object
} else {
length(object)
}
Expand Down Expand Up @@ -87,13 +91,16 @@ process_plural <- function(qty, code) {
parts <- strsplit(str_tail(code), "/", fixed = TRUE)[[1]]
if (last_character(code) == "/") parts <- c(parts, "")
if (length(parts) == 1) {
if (qty != 1) parts[1] else ""
if (is.finite(qty) & qty == 1) "" else parts[1]
} else if (length(parts) == 2) {
if (qty == 1) parts[1] else parts[2]
if (is.finite(qty) & qty == 1)
parts[1]
else
parts[2]
} else if (length(parts) == 3) {
if (qty == 0) {
if (is.finite(qty) & qty == 0) {
parts[1]
} else if (qty == 1) {
} else if (is.finite(qty) & qty == 1) {
parts[2]
} else {
parts[3]
Expand Down
2 changes: 1 addition & 1 deletion man/ansi_align.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/ansi_collapse.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_columns.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_nchar.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_strsplit.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_strtrim.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_strwrap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/ansi_toupper.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/ansi_trimws.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_abort.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_alert.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_blockquote.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cli_bullets.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cli_bullets_raw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_dl.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_h1.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_li.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/cli_ol.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/cli_process_start.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0b1a014

Please sign in to comment.