Skip to content

Commit

Permalink
factor out tail creation from bubble
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Nov 4, 2024
1 parent 2813228 commit ae04bae
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
25 changes: 20 additions & 5 deletions R/bubble.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Speech bubble
#' Thought/speech bubble/balloon
#'
#' @export
#' @param x (character) a character vector
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions man/bubble.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions man/dot-tail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae04bae

Please sign in to comment.