~hrbrmstr/forcequotes

9bcc7afc4b6c3c4a6ed5a34ae0ecbbc06c54c092 — hrbrmstr 4 years ago 125a079 master
enabled changing of foreground color in console function
3 files changed, 13 insertions(+), 4 deletions(-)

M R/quote-console.R
M R/random-quote.R
M man/quote_console.Rd
M R/quote-console.R => R/quote-console.R +7 -2
@@ 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"

M R/random-quote.R => R/random-quote.R +3 -1
@@ 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(

M man/quote_console.Rd => man/quote_console.Rd +3 -1
@@ 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