@@ -102,24 +102,21 @@ cli_fmt <- function(expr, collapse = FALSE, strip_newline = FALSE) {
102102# ' @param .envir Environment to evaluate the expressions in.
103103# ' @param collapse Whether to collapse the result if it has multiple
104104# ' lines, e.g. because of `\f` characters.
105- # ' @param keep_newlines Whether to keep newlines in the result, or treat
106- # ' them as regular space characters .
105+ # ' @param keep_whitespace Whether to keep all whitepace (spaces, newlines
106+ # ' and form feeds) as is in the input .
107107# ' @return Character scalar, the formatted string.
108108# '
109109# ' @export
110110# ' @examples
111111# ' format_inline("A message for {.emph later}, thanks {.fn format_inline}.")
112112
113113format_inline <- function (... , .envir = parent.frame(), collapse = TRUE ,
114- keep_newlines = TRUE ) {
115- str <- paste0(unlist(list (... ), use.names = FALSE ), collapse = " " )
116- if (keep_newlines ) {
117- str <- gsub(" \n " , " \f " , str , fixed = TRUE )
118- }
114+ keep_whitespace = TRUE ) {
119115 opts <- options(cli.width = Inf )
120116 on.exit(options(opts ), add = TRUE )
117+ fun <- if (keep_whitespace ) cli_inline else cli_text
121118 cli_fmt(
122- cli_text( str , .envir = .envir ),
119+ fun( ... , .envir = .envir ),
123120 collapse = collapse ,
124121 strip_newline = TRUE
125122 )
@@ -208,6 +205,15 @@ cli_text <- function(..., .envir = parent.frame()) {
208205 cli__message(" text" , list (text = glue_cmd(... , .envir = .envir , .call = sys.call())))
209206}
210207
208+ cli_inline <- function (... , .envir = parent.frame()) {
209+ cli__message(
210+ " inline_text" ,
211+ list (
212+ text = glue_cmd(... , .envir = .envir , .call = sys.call(), .trim = FALSE )
213+ )
214+ )
215+ }
216+
211217# ' CLI verbatim text
212218# '
213219# ' It is not wrapped, but printed as is. Long lines will overflow.
0 commit comments