Skip to content

Commit

Permalink
Merge pull request #718 from rundel/issue#681
Browse files Browse the repository at this point in the history
Use `last` for length 2 vectors with `ansi_collapse()` when `sep2` not used
  • Loading branch information
gaborcsardi authored Aug 28, 2024
2 parents 2ddcc1a + d74cb7e commit 8d707ba
Show file tree
Hide file tree
Showing 40 changed files with 135 additions and 64 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
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.

4 changes: 2 additions & 2 deletions man/cli_progress_along.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_progress_bar.Rd

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

Loading

0 comments on commit 8d707ba

Please sign in to comment.