From 9bcc7afc4b6c3c4a6ed5a34ae0ecbbc06c54c092 Mon Sep 17 00:00:00 2001 From: hrbrmstr Date: Sat, 12 Jan 2019 16:02:52 -0500 Subject: [PATCH] enabled changing of foreground color in console function --- R/quote-console.R | 9 +++++++-- R/random-quote.R | 4 +++- man/quote_console.Rd | 4 +++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/R/quote-console.R b/R/quote-console.R index bf9a323..fdfd479 100644 --- a/R/quote-console.R +++ b/R/quote-console.R @@ -2,15 +2,20 @@ #' #' @md #' @param faction faction (see [random_quote()]) +#' @param foreground should the foreground text be in black or white (defaults to `white`). #' @export -quote_console <- function(faction = NULL) { +quote_console <- function(faction = NULL, foreground = c("white", "black")) { + + foreground <- match.arg(foreground[1], c("white", "black")) x <- random_quote(faction) cw <- cli::cli_sitrep()$console_width + q <- strwrap(x$starWarsQuote, width = cw) + cli::boxx( - label = crayon::white(strwrap(x$starWarsQuote, width = cw)), + label = switch(foreground, white = crayon::white(q), black = crayon::black(q)), width = cw, float = "center", border_col = "gold1" diff --git a/R/random-quote.R b/R/random-quote.R index 70bd1cf..ae12706 100644 --- a/R/random-quote.R +++ b/R/random-quote.R @@ -13,7 +13,9 @@ random_quote <- function(faction = NULL) { if (!is.null(faction)) { faction <- as.integer(faction[1]) - stopifnot(faction %in% 0L:4L) + if ((faction < 0) || (faction > 4)) { + stop("'faction' must be 0:4") + } } httr::GET( diff --git a/man/quote_console.Rd b/man/quote_console.Rd index 537a8ce..f40a10c 100644 --- a/man/quote_console.Rd +++ b/man/quote_console.Rd @@ -4,10 +4,12 @@ \alias{quote_console} \title{Get a random Star Wars quote and display it stylishly to the console} \usage{ -quote_console(faction = NULL) +quote_console(faction = NULL, foreground = c("white", "black")) } \arguments{ \item{faction}{faction (see \code{\link[=random_quote]{random_quote()}})} + +\item{foreground}{should the foreground text be in black or white (defaults to \code{white}).} } \description{ Get a random Star Wars quote and display it stylishly to the console -- 2.38.4