From ac7a025c1db531793a5374dd3b3542a1da2c21f9 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 28 Apr 2024 16:38:01 +1000 Subject: [PATCH] refactor default colour selection --- R/core.R | 3 +- R/hl-diff.R | 128 ++++++++++++++---------------- R/hl-grep.R | 60 +++++++++----- R/utils.R | 17 ++++ README.Rmd | 41 ++++++++-- README.md | 34 ++------ man/figures/example-hlgrep-1.svg | 8 ++ man/figures/example-hlgrep-2.svg | 18 +++++ man/figures/example-strdiff-3.svg | 2 +- man/figures/example-strdiff-4.svg | 12 +++ man/figures/example1.svg | 2 +- man/figures/example2.svg | 2 +- man/hl_diff.Rd | 15 ++-- man/hl_grep.Rd | 13 +-- 14 files changed, 215 insertions(+), 140 deletions(-) create mode 100644 man/figures/example-hlgrep-1.svg create mode 100644 man/figures/example-hlgrep-2.svg create mode 100644 man/figures/example-strdiff-4.svg diff --git a/R/core.R b/R/core.R index 788a03b..2e27064 100644 --- a/R/core.R +++ b/R/core.R @@ -179,7 +179,7 @@ as.character.emphatic <- function(x, ..., mode = 'ansi') { # Build full options by combining global and local options #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ opt <- attr(x, 'options', exact = TRUE) %||% list() - opt <- modifyList(hl_opts(), opt) + opt <- modify_list(hl_opts(), opt) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # format the data as character matrix @@ -567,7 +567,6 @@ calc_contrasting_text <- function(fill, text_contrast, dark_mode) { # i.e. this will use the default console colouring #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (text_contrast == 1) { - # retain original colours contrast_colour[fill_not_set] <- '' } diff --git a/R/hl-diff.R b/R/hl-diff.R index b05ad9a..d03cc10 100644 --- a/R/hl-diff.R +++ b/R/hl-diff.R @@ -1,6 +1,4 @@ - - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #' Colour the differences between character representations of objects #' @@ -13,13 +11,15 @@ #' #' @param x,y each argument is a single string. vectors of strings not currently #' supported. -#' @param bg,fg named list of colours for substitutions, insertions and +#' @param fill named list of colours for substitutions, insertions and #' deletions with names 'sub', 'ins' and 'del'. If set to NULL (the -#' default) then colours will be chosen automatically depending on the -#' \code{dark_mode} argument +#' default) then default colours will be used. +#' @param text named list of colours for the text for 'sub', 'ins' and 'del' +#' operations. If \code{NULL}, then colours which contrast with \code{fill} will +#' be chosen automatically #' @param ... further arguments passed to \code{adist()} #' @inheritParams coerce_to_string -#' @param sep what to output on the line separating the two objects. Default: NULL +#' @param sep character string of the line separating the two objects. Default: \code{NULL} #' for no separation. Use the empty string to insert an empty line. #' @inheritParams hl_grep #' @@ -32,43 +32,51 @@ #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ hl_diff <- function(x, y, coerce = "default", - bg = NULL, fg = NULL, - opts = hl_opts(), - sep = NULL, + fill = NULL, + text = NULL, + opts = hl_opts(), + sep = NULL, ...) { + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Default colours + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + fill_default_dark <- list(sub = 'dodgerblue' , ins = 'darkgreen', del = 'firebrick' ) + fill_default_light <- list(sub = 'dodgerblue1', ins = 'darkgreen', del = 'firebrick3') - if (is.null(bg)) { - if (opts$dark_mode) { - bg <- list(sub = 'dodgerblue', ins = 'darkgreen', del = 'firebrick') - } else { - bg <- list(sub = 'dodgerblue1', ins = 'darkgreen', del = 'firebrick3') - } + text_default_dark <- list(sub = 'white', ins = 'white', del = 'white') + text_default_light <- list(sub = 'black', ins = 'black', del = 'black') + + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Work hard to ensure we have a full complement of colours for both + # 'fill' and 'text'. and 'text' colours are chosen as contrasting if + # they are not specified + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if (opts$dark_mode) { + fill <- modify_list(fill_default_dark, fill) + } else { + fill <- modify_list(fill_default_light, fill) } - if (is.null(fg)) { - if (opts$dark_mode) { - fg <- list(sub = 'white', ins = 'white', del = 'white') - } else { - fg <- list(sub = 'black', ins = 'black', del = 'black') - } + + if (is.null(text)) { + text <- list( + sub = calc_contrasting_text(fill$sub, text_contrast = opts$text_contrast, dark_mode = opts$dark_mode), + ins = calc_contrasting_text(fill$ins, text_contrast = opts$text_contrast, dark_mode = opts$dark_mode), + del = calc_contrasting_text(fill$del, text_contrast = opts$text_contrast, dark_mode = opts$dark_mode) + ) + } + + if (opts$dark_mode) { + text <- modify_list(text_default_dark, text) + } else { + text <- modify_list(text_default_light, text) } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Coerce #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # if (!is.character(x)) { - x <- coerce_to_string(x, coerce) - # } else { - # x <- capture.output(x) - # x <- paste(x, collapse = "\n") - # } - - # if (!is.character(y)) { - y <- coerce_to_string(y, coerce) - # } else { - # y <- capture.output(y) - # y <- paste(y, collapse = "\n") - # } + x <- coerce_to_string(x, coerce) + y <- coerce_to_string(y, coerce) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Sanity check @@ -90,7 +98,6 @@ hl_diff <- function(x, y, lev <- attr(lev, 'trafos')[1] lev <- strsplit(lev, '')[[1]] - #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Adjust input strings to account for deletions and insertions #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -134,12 +141,17 @@ hl_diff <- function(x, y, ybits <- ifelse(xcr2, paste0(ybits, "\n"), ybits) - - rl <- base::rle(lev) - N <- length(rl$values) - end <- cumsum(rl$lengths) + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Find the beginning and end of each run of the same edit + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + rl <- base::rle(lev) + N <- length(rl$values) + end <- cumsum(rl$lengths) begin <- c(0, head(end, -1) + 1) + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Break apart string into these "same edit operation" chunks + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ xv <- character(N) yv <- character(N) for (i in seq(N)) { @@ -147,12 +159,17 @@ hl_diff <- function(x, y, yv[i] <- paste(ybits[begin[i]:end[i]], collapse = "") } - xtext <- c(S = fg$sub, I = fg$ins, D = fg$del, M = NA)[rl$values] - xfill <- c(S = bg$sub, I = bg$ins, D = bg$del, M = NA)[rl$values] - ytext <- c(S = fg$sub, I = fg$ins, D = fg$del, M = NA)[rl$values] - yfill <- c(S = bg$sub, I = bg$ins, D = bg$del, M = NA)[rl$values] - + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Construct a vector of colours for each chunk + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + xtext <- c(S = text$sub, I = text$ins, D = text$del, M = NA)[rl$values] + xfill <- c(S = fill$sub, I = fill$ins, D = fill$del, M = NA)[rl$values] + ytext <- c(S = text$sub, I = text$ins, D = text$del, M = NA)[rl$values] + yfill <- c(S = fill$sub, I = fill$ins, D = fill$del, M = NA)[rl$values] + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Create the 'emphatic' object + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (is.null(sep)) { structure( list( @@ -176,26 +193,3 @@ hl_diff <- function(x, y, } - -if (FALSE) { - x <- "abcdx" - y <- "abcd\nef" - lev <- utils::adist(x, y, counts = TRUE) - hl_diff(x, y) - - coerce = "default" - bg = NULL - fg = NULL - opts = hl_opts() - - hl_diff(head(mtcars, 2), head(mtcars, 3), sep = " ") - - - x <- "hi\nhi aa" - y <- "hi\nhi bb" - lev <- utils::adist(x, y, counts = TRUE) - hl_diff(x, y, sep = "----------------") -} - - - diff --git a/R/hl-grep.R b/R/hl-grep.R index dde90a0..48b595c 100644 --- a/R/hl-grep.R +++ b/R/hl-grep.R @@ -12,6 +12,10 @@ #' #' @param x character string #' @param pattern regular expression string. Note: don't get too fancy here +#' @param fill solid colour for background. If \code{NULL} (the default), +#' then a colour will be selected based upon \code{opts$dark_mode} +#' @param text text colour. If \code{NULL} (the default), then a colour +#' will be seleted which contrasts with the \code{fill} colour. #' @param ... extra args passed to \code{gsub} #' @param perl logical. use perl style regex. default: TRUE #' @inheritParams coerce_to_string @@ -25,36 +29,50 @@ hl_grep <- function(x, pattern, coerce = "default", opts = hl_opts(), - fg = NULL, - bg = NULL, + fill = NULL, + text = NULL, ..., perl = TRUE) { - x <- coerce_to_string(x, coerce) + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Choose colours + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + if (is.null(fill)) { + fill <- ifelse(opts$dark_mode, "#f0e60f", "#0F19F0") + } + if (is.null(text)) { + text <- calc_contrasting_text( + fill, + text_contrast = opts$text_contrast, + dark_mode = opts$dark_mode + ) + } + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Coerge to string + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + x <- coerce_to_string(x, coerce) if (length(x) > 1) { x <- deparse(x) } - if (is.null(fg)) { - fg <- ifelse(opts$dark_mode, "black", "yellow") - } - if (is.null(bg)) { - bg <- ifelse(opts$dark_mode, "yellow", "black") - } - - - # matches <- gregexpr(pattern, x)[[1]] - matches <- gregexpr(pattern, x, ..., perl = perl)[[1]] - matches - + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Where are the matches? Where do they start and finish? + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + matches <- gregexpr(pattern, x, ..., perl = perl)[[1]] match_starts <- matches; attributes(match_starts) <- NULL match_ends <- match_starts + attr(matches, "match.length") - 1 + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Early exit if there are no matches for this string + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if (match_starts[1] == -1) { return(x) # no matches found } - # add some fake matches outside the string. + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # add some dummy matches outside the string to make the logic for + # colouring easier + #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ match_starts <- c(-Inf, match_starts, nchar(x) + 1) match_ends <- c( 0, match_ends , Inf) @@ -71,8 +89,8 @@ hl_grep <- function(x, } # Drop the first segment which is known to be out of bounds - starts <- starts[-1] # tail(starts, -1) - ends <- ends [-1] # tail(ends , -1) + starts <- starts[-1] + ends <- ends [-1] # Drop any redundant segments keep <- ends >= starts @@ -92,8 +110,8 @@ hl_grep <- function(x, #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Determine text colour and fill for each segment #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - text <- ifelse(is_match, fg, NA_character_) - fill <- ifelse(is_match, bg, NA_character_) + text_grep <- ifelse(is_match, text, NA_character_) + fill_grep <- ifelse(is_match, fill, NA_character_) #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Build emphatic structure: raw vector + text + fill @@ -101,7 +119,7 @@ hl_grep <- function(x, res <- structure( bits, class = c('emphatic', 'compact'), - text = t(as.matrix(text)), fill = t(as.matrix(fill)) + text = t(as.matrix(text_grep)), fill = t(as.matrix(fill_grep)) ) attr(res, 'options') <- opts diff --git a/R/utils.R b/R/utils.R index 3e1248e..c162888 100644 --- a/R/utils.R +++ b/R/utils.R @@ -99,6 +99,23 @@ coerce_to_string <- function(x, coerce) { } +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#' Update a list +#' +#' @param current,new current list and new list. 'new' may be NULL +#' +#' @return updated list +#' @noRd +#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +modify_list <- function (current, new) { + + for (i in names(new)) { + current[[i]] <- new[[i]] + } + + current +} + if (FALSE) { chunked_indices(4, 6) diff --git a/README.Rmd b/README.Rmd index 1b2d991..fb70f32 100644 --- a/README.Rmd +++ b/README.Rmd @@ -110,7 +110,7 @@ mtcars |> mtcars |> head(15) |> hl(c('red', 'white', 'blue')) |> - as_svg(600, 400) |> + as_svg(650, 350) |> cat(file = "man/figures/example1.svg") ``` @@ -152,7 +152,7 @@ mtcars |> show_legend = TRUE ) |> hl('hotpink', rows = hp == min(hp), cols = hp:carb) |> - as_svg(600, 400) |> + as_svg(650, 380) |> cat(file = "man/figures/example2.svg") ``` @@ -163,8 +163,8 @@ mtcars |> ## `hl_diff()` highlight difference between two objects The Levenshtein edit distance is calculated between the string representation -of two objects and these edits are then coloured for insert, -delete and substitute. +of two objects and these edits are then coloured 🟢 = insert, 🔴 = delete, +🔵 = substitute. ```{r eval = FALSE} @@ -191,10 +191,17 @@ to a string representation. Coercion to a string is controlled by the In this example, the difference between the `mean()` and `median()` function definitions is highlighted. -```{r} +```{r eval=FALSE} hl_diff(mean, median, coerce = 'print', sep = " ") ``` +```{r echo=FALSE} +hl_diff(mean, median, coerce = 'print', sep = " ") |> + as_svg(600, 200) |> + cat(file = "man/figures/example-strdiff-4.svg") +``` + + ## `hl_grep()` highlight regular expression matches in objects @@ -204,7 +211,7 @@ objects coerced into a string representation. #### Highlight regular expression matches in a character string -```{r} +```{r eval = FALSE} gettysburg <- c( "Four score and seven years ago our fathers brought forth on", "this continent, a new nation, conceived in Liberty, and dedicated to the", @@ -213,6 +220,19 @@ gettysburg <- c( hl_grep(gettysburg, "men.*equal") ``` +```{r echo = FALSE} +gettysburg <- c( + "Four score and seven years ago our fathers brought forth on", + "this continent, a new nation, conceived in Liberty, and dedicated to the", + "proposition that all men are created equal." +) +hl_grep(gettysburg, "men.*equal") |> + as_svg(600, 80) |> + cat(file = "man/figures/example-hlgrep-1.svg") +``` + + + #### Highlight regular expression matches within an object Other R objects (functions, lists, data.frames, etc) can also be highlighted @@ -221,10 +241,17 @@ controlled by the `coerce` argument. In this example, the function body for `mode()` is searched for the word `switch`: -```{r} +```{r eval = FALSE} hl_grep(mode, 'switch') ``` +```{r echo = FALSE} +hl_grep(mode, 'switch') |> + as_svg(600, 250) |> + cat(file = "man/figures/example-hlgrep-2.svg") +``` + + ## Options diff --git a/README.md b/README.md index baf8527..12111c7 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,8 @@ mtcars |> ## `hl_diff()` highlight difference between two objects The Levenshtein edit distance is calculated between the string -representation of two objects and these edits are then coloured for -insert, -delete and -substitute. +representation of two objects and these edits are then coloured 🟢 = +insert, 🔴 = delete, 🔵 = substitute. ``` r x <- "Paris in the the spring?" @@ -109,13 +107,7 @@ function definitions is highlighted. hl_diff(mean, median, coerce = 'print', sep = " ") ``` -
function (x               , ...) 
-UseMethod("me  an")
-16ab498 >
-b a se>

function (x, na.rm = FALSE, ...) -UseMethod("median") -0 a97c40> -stats >
+ ## `hl_grep()` highlight regular expression matches in objects @@ -133,13 +125,11 @@ gettysburg <- c( hl_grep(gettysburg, "men.*equal") ``` -
[1] "Four score and seven years ago our fathers brought forth on"             
-[2] "this continent, a new nation, conceived in Liberty, and dedicated to the"
-[3] "proposition that all men are created equal."                             
+ #### Highlight regular expression matches within an object -Objects such as functions, lists, data.frames and lists can also be +Other R objects (functions, lists, data.frames, etc) can also be highlighted with regular expressions. How an object is coerced into string representation is controlled by the `coerce` argument. @@ -150,19 +140,7 @@ In this example, the function body for `mode()` is searched for the word hl_grep(mode, 'switch') ``` -
function (x) 
-{
-    if (is.expression(x)) 
-        return("expression")
-    if (is.call(x)) 
-        return(switch(deparse(x[[1L]])[1L], `(` = "(", "call"))
-    if (is.name(x)) 
-        "name"
-    else switch(tx <- typeof(x), double = , integer = "numeric", 
-        closure = , builtin = , special = "function", tx)
-}
-
-
+ ## Options diff --git a/man/figures/example-hlgrep-1.svg b/man/figures/example-hlgrep-1.svg new file mode 100644 index 0000000..0986d84 --- /dev/null +++ b/man/figures/example-hlgrep-1.svg @@ -0,0 +1,8 @@ + + +
[1] "Four score and seven years ago our fathers brought forth on"             
+[2] "this continent, a new nation, conceived in Liberty, and dedicated to the"
+[3] "proposition that all men are created equal."                             
+
+
+ \ No newline at end of file diff --git a/man/figures/example-hlgrep-2.svg b/man/figures/example-hlgrep-2.svg new file mode 100644 index 0000000..289cf2d --- /dev/null +++ b/man/figures/example-hlgrep-2.svg @@ -0,0 +1,18 @@ + + +
function (x) 
+{
+    if (is.expression(x)) 
+        return("expression")
+    if (is.call(x)) 
+        return(switch(deparse(x[[1L]])[1L], `(` = "(", "call"))
+    if (is.name(x)) 
+        "name"
+    else switch(tx <- typeof(x), double = , integer = "numeric", 
+        closure = , builtin = , special = "function", tx)
+}
+
+
+
+
+ \ No newline at end of file diff --git a/man/figures/example-strdiff-3.svg b/man/figures/example-strdiff-3.svg index c276d13..7f06a9b 100644 --- a/man/figures/example-strdiff-3.svg +++ b/man/figures/example-strdiff-3.svg @@ -1,6 +1,6 @@ -
[1] "    Paris in the the spring?"
[1] "Not Paris in the spring!"
+
[1] "    Paris in the the spring?"
[1] "Not Paris in the spring!"
\ No newline at end of file diff --git a/man/figures/example-strdiff-4.svg b/man/figures/example-strdiff-4.svg new file mode 100644 index 0000000..49bdcd1 --- /dev/null +++ b/man/figures/example-strdiff-4.svg @@ -0,0 +1,12 @@ + + +
function (x               , ...) 
+UseMethod("me  an")
+07eed698>
+b a se>

function (x, na.rm = FALSE, ...) +UseMethod("median") +1419c440> +stats >
+
+
+ \ No newline at end of file diff --git a/man/figures/example1.svg b/man/figures/example1.svg index 40b997d..f325801 100644 --- a/man/figures/example1.svg +++ b/man/figures/example1.svg @@ -1,4 +1,4 @@ - +
                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
 Mazda RX4            21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
diff --git a/man/figures/example2.svg b/man/figures/example2.svg
index ed1c17a..de2e577 100644
--- a/man/figures/example2.svg
+++ b/man/figures/example2.svg
@@ -1,4 +1,4 @@
-
+
       
       
                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb
 Mazda RX4            21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
diff --git a/man/hl_diff.Rd b/man/hl_diff.Rd
index 0788c4d..8ffa031 100644
--- a/man/hl_diff.Rd
+++ b/man/hl_diff.Rd
@@ -8,8 +8,8 @@ hl_diff(
   x,
   y,
   coerce = "default",
-  bg = NULL,
-  fg = NULL,
+  fill = NULL,
+  text = NULL,
   opts = hl_opts(),
   sep = NULL,
   ...
@@ -32,14 +32,17 @@ supported.}
           \code{str(x)}}
 }}
 
-\item{bg, fg}{named list of colours for substitutions, insertions and
+\item{fill}{named list of colours for substitutions, insertions and
 deletions with names 'sub', 'ins' and 'del'.  If set to NULL (the
-default) then colours will be chosen automatically depending on the
-\code{dark_mode} argument}
+default) then default colours will be used.}
+
+\item{text}{named list of colours for the text for 'sub', 'ins' and 'del'
+operations. If \code{NULL}, then colours which contrast with \code{fill} will
+be chosen automatically}
 
 \item{opts}{create options list}
 
-\item{sep}{what to output on the line separating the two objects. Default: NULL
+\item{sep}{character string of the  line separating the two objects. Default: \code{NULL}
 for no separation. Use the empty string to insert an empty line.}
 
 \item{...}{further arguments passed to \code{adist()}}
diff --git a/man/hl_grep.Rd b/man/hl_grep.Rd
index 5ba33c2..bcfd1d7 100644
--- a/man/hl_grep.Rd
+++ b/man/hl_grep.Rd
@@ -9,8 +9,8 @@ hl_grep(
   pattern,
   coerce = "default",
   opts = hl_opts(),
-  fg = NULL,
-  bg = NULL,
+  fill = NULL,
+  text = NULL,
   ...,
   perl = TRUE
 )
@@ -35,10 +35,11 @@ hl_grep(
 
 \item{opts}{create options list}
 
-\item{bg, fg}{named list of colours for substitutions, insertions and
-deletions with names 'sub', 'ins' and 'del'.  If set to NULL (the
-default) then colours will be chosen automatically depending on the
-\code{dark_mode} argument}
+\item{fill}{solid colour for background.  If \code{NULL} (the default),
+then a colour will be selected based upon \code{opts$dark_mode}}
+
+\item{text}{text colour. If \code{NULL} (the default), then a colour
+will be seleted which contrasts with the \code{fill} colour.}
 
 \item{...}{extra args passed to \code{gsub}}