Skip to content

Commit

Permalink
Use dev cli
Browse files Browse the repository at this point in the history
For xxhash, needed by dependency scanning.
  • Loading branch information
gaborcsardi committed Nov 8, 2024
1 parent 3005221 commit f498104
Show file tree
Hide file tree
Showing 35 changed files with 7,271 additions and 79 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Config/build/extra-sources: configure*
Config/needs/dependencies:
callr,
desc,
cli,
r-lib/cli,
curl,
filelock,
jsonlite,
Expand Down
14 changes: 6 additions & 8 deletions src/library/cli/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: cli
Title: Helpers for Developing Command Line Interfaces
Version: 3.6.2
Version: 3.6.3.9000
Authors@R: c(
person("Gábor", "Csárdi", , "csardi.gabor@gmail.com", role = c("aut", "cre")),
person("Hadley", "Wickham", role = "ctb"),
Expand All @@ -21,22 +21,20 @@ BugReports: https://github.com/r-lib/cli/issues
Depends: R (>= 3.4)
Imports: utils
Suggests: callr, covr, crayon, digest, glue (>= 1.6.0), grDevices,
htmltools, htmlwidgets, knitr, methods, mockery, processx, ps
(>= 1.3.4.9000), rlang (>= 1.0.2.9003), rmarkdown, rprojroot,
rstudioapi, testthat, tibble, whoami, withr
htmltools, htmlwidgets, knitr, methods, processx, ps (>=
1.3.4.9000), rlang (>= 1.0.2.9003), rmarkdown, rprojroot,
rstudioapi, testthat (>= 3.2.0), tibble, whoami, withr
Config/Needs/website: r-lib/asciicast, bench, brio, cpp11, decor, desc,
fansi, prettyunits, sessioninfo, tidyverse/tidytemplate,
usethis, vctrs
Config/testthat/edition: 3
Encoding: UTF-8
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
NeedsCompilation: yes
Packaged: 2023-12-10 22:38:10 UTC; gaborcsardi
Packaged: 2024-11-08 08:17:43 UTC; gaborcsardi
Author: Gábor Csárdi [aut, cre],
Hadley Wickham [ctb],
Kirill Müller [ctb],
Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>),
Posit Software, PBC [cph, fnd]
Maintainer: Gábor Csárdi <csardi.gabor@gmail.com>
Repository: CRAN
Date/Publication: 2023-12-11 07:40:13 UTC
8 changes: 8 additions & 0 deletions src/library/cli/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,27 @@ export(hash_emoji)
export(hash_file_md5)
export(hash_file_sha1)
export(hash_file_sha256)
export(hash_file_xxhash)
export(hash_file_xxhash64)
export(hash_md5)
export(hash_obj_animal)
export(hash_obj_emoji)
export(hash_obj_md5)
export(hash_obj_sha1)
export(hash_obj_sha256)
export(hash_obj_xxhash)
export(hash_obj_xxhash64)
export(hash_raw_animal)
export(hash_raw_emoji)
export(hash_raw_md5)
export(hash_raw_sha1)
export(hash_raw_sha256)
export(hash_raw_xxhash)
export(hash_raw_xxhash64)
export(hash_sha1)
export(hash_sha256)
export(hash_xxhash)
export(hash_xxhash64)
export(is_ansi_tty)
export(is_dynamic_tty)
export(is_utf8_output)
Expand Down
30 changes: 30 additions & 0 deletions src/library/cli/NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# cli (development version)

* `cli_progress_bar()` now accepts `total` = Inf or -Inf which mimics the behavior of when `total` is NA.

* `num_ansi_colors()` now does not warn in Emacs if the `INSIDE_EMACS`
environment variable is not a proper version number (@rundel, #689).

* `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).

* `ansi_collapse()` is now correct for length-1 vectors with style "head"
if width is specified (@rundel, #590).

* New `hash_xxhash()` etc. functions to calculate the xxHash of strings,
raw vectors, objects, files.

# cli 3.6.3

* cli now builds on ARM Windows.

* "Solarized Dark" is now the default syntax highlighting theme in
terminals.

* The `{.obj_type_friendly}` inline style now only shows the first class
name (#669 @olivroy).

* Syntax highlighting now does not fail in RStudio if the rstudioapi
package is not installed (#697).

# cli 3.6.2

* `ansi_collapse(x, trunc = 1, style = "head")` now indeed shows one
Expand Down
2 changes: 1 addition & 1 deletion src/library/cli/R/aaa-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ tail_na <- function(x, n = 1) {
}

dedent <- function(x, n = 2) {
first_n_char <- strsplit(ansi_substr(x, 1, n), "")[[1]]
first_n_char <- strsplit(ansi_substr(x, 1, n), "", fixed = TRUE)[[1]]
n_space <- cumsum(first_n_char == " ")
d_n_space <- diff(c(0, n_space))
first_not_space <- utils::head(c(which(d_n_space == 0), n + 1), 1)
Expand Down
11 changes: 8 additions & 3 deletions src/library/cli/R/aab-rstudio-detect.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ rstudio <- local({
args = commandArgs(),
search = search()
)
d$ver <- if (d$api) asNamespace("rstudioapi")$getVersion()
d$desktop <- if (d$api) asNamespace("rstudioapi")$versionInfo()$mode

if (d$api) {
ns <- asNamespace("rstudioapi")
d$ver <- if (d$api) ns$getVersion()
new_api <- package_version(getNamespaceVersion(ns)) >= "0.17.0"
d$desktop <- if (new_api) ns$getMode() else ns$versionInfo()$mode
}

d
}
Expand Down Expand Up @@ -164,7 +169,7 @@ rstudio <- local({
"rstudio_build_pane"

} else if (new$envs[["RSTUDIOAPI_IPC_REQUESTS_FILE"]] != "" &&
grepl("rstudio", new$envs[["XPC_SERVICE_NAME"]])) {
grepl("rstudio", new$envs[["XPC_SERVICE_NAME"]], fixed = TRUE)) {
# RStudio job, XPC_SERVICE_NAME=0 in the subprocess of a job
# process. Hopefully this is reliable.
"rstudio_job"
Expand Down
4 changes: 2 additions & 2 deletions src/library/cli/R/ansi-hyperlink.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ abs_path1 <- function(x) {
# -- {.fun} ---------------------------------------------------------------

make_link_fun <- function(txt) {
tolink <- grepl("::", txt)
tolink <- grepl("::", txt, fixed = TRUE)
linked <- grepl("\007|\033\\\\", txt)
todo <- tolink & !linked
if (!any(todo)) return(txt)
Expand Down Expand Up @@ -409,7 +409,7 @@ ansi_hyperlink_types <- function() {
vignette = FALSE
)

} else if (rs$hyperlink) {
} else if (isTRUE(rs$hyperlink)) {
list(
href = TRUE,
run = structure(run, type = "rstudio"),
Expand Down
2 changes: 1 addition & 1 deletion src/library/cli/R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ is_border_style <- function(x) {
}

is_padding_or_margin <- function(x) {
is.numeric(x) && length(x) %in% c(1, 4) && all(!is.na(x)) &&
is.numeric(x) && length(x) %in% c(1, 4) && !anyNA(x) &&
all(as.integer(x) == x)
}

Expand Down
5 changes: 3 additions & 2 deletions src/library/cli/R/cliapp-docs.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
#' * `run` is an R expression, that is potentially clickable if the terminal
#' supports ANSI hyperlinks to runnable code (e.g. RStudio).
#' It supports link text. See [links] for more information about cli hyperlinks.
#' * `str` for a double quoted string escaped by [base::encodeString()].#' * `strong` for strong importance.
#' * `str` for a double quoted string escaped by [base::encodeString()].
#' * `strong` for strong importance.
#' * `topic` is a help page of a _topic_.
#' If the terminal supports ANSI hyperlinks to help pages (e.g. RStudio),
#' then cli creates a clickable link. It supports link text.
Expand Down Expand Up @@ -543,7 +544,7 @@ NULL
#' convert relative paths, and paths starting with `~` to aboslute path.
#'
#' ```{asciicast links-file-1}
#' cli_text("... edit your {.file ~/.Rprofile} file.}")
#' cli_text("... edit your {.file ~/.Rprofile} file.")
#' ```
#'
#' ## Link text
Expand Down
6 changes: 3 additions & 3 deletions src/library/cli/R/cliapp.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ clii_alert <- function(app, type, text, id, class, wrap) {
style <- app$get_current_style()
before <- call_if_fun(style$before) %||% ""
after <- call_if_fun(style$after) %||% ""
before <- gsub(" ", "\u00a0", before)
after <- gsub(" ", "\u00a0", after)
before <- gsub(" ", "\u00a0", before, fixed = TRUE)
after <- gsub(" ", "\u00a0", after, fixed = TRUE)
text[1] <- paste0(before, text[1])
text[length(text)] <- paste0(text[length(text)], after)
if (is.function(style$fmt)) text <- style$fmt(text)
Expand All @@ -277,7 +277,7 @@ clii_bullets <- function(app, text, id, class) {
length(nms) <- length(text)
nms[is.na(nms) | nms == ""] <- "empty"
nms[nms == " "] <- "space"
nms <- gsub(" ", "-", nms)
nms <- gsub(" ", "-", nms, fixed = TRUE)
# cls is vectorized here (!)
cls <- paste0("bullet memo-item bullet-", nms, " memo-item=", nms)

Expand Down
2 changes: 1 addition & 1 deletion src/library/cli/R/friendly-type.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ friendly_type <- function(x, value = TRUE, length = FALSE) {
} else {
"a"
}
return(paste0(prop, " {.cls {class(x)}} object"))
return(paste0(prop, " {.cls {class(x)[1]}} object"))
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/library/cli/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 Expand Up @@ -158,7 +159,7 @@ collapse_head <- function(x, sep, sep2, last, trunc, width, ellipsis) {
# special cases that do not need trimming
if (lnx == 0L) {
return("")
} else if (any(is.na(x))) {
} else if (anyNA(x)) {
return(NA_character_)
}

Expand Down Expand Up @@ -187,7 +188,9 @@ collapse_head <- function(x, sep, sep2, last, trunc, width, ellipsis) {
nlast <- if (lnx > 2L) 1L else 0L
wtot <- sum(wx) + nsep * wsep + nsep2 * wsep2 + nlast * wlast
if (wtot <= width) {
if (lnx == 2L) {
if (lnx == 1L) {
return(x)
} else if (lnx == 2L) {
return(paste0(x, collapse = sep2))
} else {
return(paste0(
Expand Down
115 changes: 113 additions & 2 deletions src/library/cli/R/hash.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ hash_emoji1 <- function(x, size = 3) {

hash_emoji1_transform <- function(md5, size) {
md513 <- substr(md5, 1, 13)
mdint <- as.integer(as.hexmode(strsplit(md513, "")[[1]]))
mdint <- as.integer(as.hexmode(strsplit(md513, "", fixed = TRUE)[[1]]))
hash <- sum(mdint * 16^(0:12))

base <- nrow(emojis)
Expand Down Expand Up @@ -444,7 +444,7 @@ hash_animal1 <- function(x, n_adj = 2) {

hash_animal1_transform <- function(md5, n_adj) {
md513 <- substr(md5, 1, 13)
mdint <- as.integer(as.hexmode(strsplit(md513, "")[[1]]))
mdint <- as.integer(as.hexmode(strsplit(md513, "", fixed = TRUE)[[1]]))
hash <- sum(mdint * 16^(0:12))

len_ani <- length(gfycat_animals)
Expand Down Expand Up @@ -498,3 +498,114 @@ hash_obj_animal <- function(x, n_adj = 2, serialize_version = 2) {
sr <- serialize(x, NULL, version = serialize_version)[-(1:14)]
hash_raw_animal(sr, n_adj = n_adj)
}

#' xxHash
#'
#' Extremely fast hash algorithm.
#'
#' @param x Character vector. If not a character vector, then
#' [as.character()] is used to try to coerce it into one. `NA` entries
#' will have an `NA` hash.
#' @return `hash_xxhash()` returns a character vector of hexadecimal
#' xxHash hashes.
#'
#' @family hash functions
#'
#' @export
#' @examples
#' hash_xxhash(c("foo", NA, "bar", ""))

hash_xxhash <- function(x) {
if (!is.character(x)) x <- as.character(x)
na <- is.na(x)
x[na] <- NA_character_
x[!na] <- .Call(clic_xxhash, x[!na])
x
}

#' @export
#' @rdname hash_xxhash
#' @details `hash_raw_xxhash()` calculates the xxHash hash of the bytes
#' of a raw vector.
#' @return `hash_raw_xxhash()` returns a character scalar.

hash_raw_xxhash <- function(x) {
stopifnot(is.raw(x))
.Call(clic_xxhash_raw, x)
}

#' @export
#' @rdname hash_xxhash
#' @param serialize_version Workspace format version to use, see
#' [base::serialize()].
#' @details `hash_obj_xxhash()` calculates the xxHash hash of an R
#' object. The object is serialized into a binary vector first.
#' @return `hash_obj_xxhash()` returns a character scalar.

hash_obj_xxhash <- function(x, serialize_version = 2) {
sr <- serialize(x, NULL, version = serialize_version)[-(1:14)]
hash_raw_xxhash(sr)
}

#' @export
#' @rdname hash_xxhash
#' @param paths Character vector of file names.
#' @details `hash_file_xxhash()` calculates the xxHash hash of one or
#' more files.
#'
#' @return `hash_file_xxhash()` returns a character vector of xxHash
#' hashes.

hash_file_xxhash <- function(paths) {
if (!is.character(paths)) paths <- as.character(paths)
paths <- normalizePath(paths, mustWork = FALSE)
if (is_windows()) {
paths <- enc2utf8(paths)
} else {
paths <- enc2native(paths)
}
.Call(clic_xxhash_file, paths)
}

#' @export
#' @rdname hash_xxhash
#' @details The `64` functions caculate the 64 bit variant
#' of xxHash. Otherwise they work the same.

hash_xxhash64 <- function(x) {
if (!is.character(x)) x <- as.character(x)
na <- is.na(x)
x[na] <- NA_character_
x[!na] <- .Call(clic_xxhash64, x[!na])
x
}

#' @export
#' @rdname hash_xxhash

hash_raw_xxhash64 <- function(x) {
stopifnot(is.raw(x))
.Call(clic_xxhash64_raw, x)
}

#' @export
#' @rdname hash_xxhash

hash_obj_xxhash64 <- function(x, serialize_version = 2) {
sr <- serialize(x, NULL, version = serialize_version)[-(1:14)]
hash_raw_xxhash64(sr)
}

#' @export
#' @rdname hash_xxhash

hash_file_xxhash64 <- function(paths) {
if (!is.character(paths)) paths <- as.character(paths)
paths <- normalizePath(paths, mustWork = FALSE)
if (is_windows()) {
paths <- enc2utf8(paths)
} else {
paths <- enc2native(paths)
}
.Call(clic_xxhash64_file, paths)
}
4 changes: 2 additions & 2 deletions src/library/cli/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
Loading

0 comments on commit f498104

Please sign in to comment.