diff --git a/R/bubble.R b/R/bubble.R index 86d2e19..512f9e7 100644 --- a/R/bubble.R +++ b/R/bubble.R @@ -1,4 +1,4 @@ -#' Speech bubble +#' Thought/speech bubble/balloon #' #' @export #' @param x (character) a character vector @@ -32,13 +32,28 @@ bubble <- function(x, width = 60, thought_sym = "o") { quote[i] <- paste0("|", string_pad(x[i], n + 4, "left"), "|") } } - thought <- c( - string_pad(thought_sym, floor((n + 4) / 3), "left"), - string_pad(thought_sym, floor((n + 4) / 3) + 2, "left") - ) + thought <- .tail(n, thought_sym) c(empty_to_avoid_rlang_header, top, quote, bottom, thought) } +#' Make the tail part of a thought bubble +#' @keywords internal +#' @param max_char_length (numeric) length of the maximum line. this is used +#' to determine how much whitespace padding to add to the left of +#' `thought_sym` +#' @inheritParams bubble +#' @examplesIf interactive() +#' .tail(59) +#' cat(.tail(59), sep = "\n") +#' cat(.tail(11), sep = "\n") +#' cat(.tail(11, "%"), sep = "\n") +.tail <- function(max_char_length, thought_sym = "o") { + c( + string_pad(thought_sym, floor((max_char_length + 4) / 3), "left"), + string_pad(thought_sym, floor((max_char_length + 4) / 3) + 2, "left") + ) +} + string_pad <- function(string, n, side) { fmt <- switch(side, left = paste0("%", n, "s"), diff --git a/man/bubble.Rd b/man/bubble.Rd index 7d61d2b..075c842 100644 --- a/man/bubble.Rd +++ b/man/bubble.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/bubble.R \name{bubble} \alias{bubble} -\title{Speech bubble} +\title{Thought/speech bubble/balloon} \usage{ bubble(x, width = 60, thought_sym = "o") } @@ -19,7 +19,7 @@ default: "o"} character vector of length greater than the input \code{x} } \description{ -Speech bubble +Thought/speech bubble/balloon } \note{ modified from \url{https://github.com/schochastics/startifyR} diff --git a/man/dot-tail.Rd b/man/dot-tail.Rd new file mode 100644 index 0000000..1198c55 --- /dev/null +++ b/man/dot-tail.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/bubble.R +\name{.tail} +\alias{.tail} +\title{Make the tail part of a thought bubble} +\usage{ +.tail(max_char_length, thought_sym = "o") +} +\arguments{ +\item{max_char_length}{(numeric) length of the maximum line. this is used +to determine how much whitespace padding to add to the left of +\code{thought_sym}} + +\item{thought_sym}{(character) scalar character to use for the +speech bubble tail (see \url{https://en.wikipedia.org/wiki/Speech_balloon}). +default: "o"} +} +\description{ +Make the tail part of a thought bubble +} +\examples{ +\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +.tail(59) +cat(.tail(59), sep = "\n") +cat(.tail(11), sep = "\n") +cat(.tail(11, "\%"), sep = "\n") +\dontshow{\}) # examplesIf} +} +\keyword{internal}