@@ -102,24 +102,21 @@ cli_fmt <- function(expr, collapse = FALSE, strip_newline = FALSE) {
102
102
# ' @param .envir Environment to evaluate the expressions in.
103
103
# ' @param collapse Whether to collapse the result if it has multiple
104
104
# ' 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 .
107
107
# ' @return Character scalar, the formatted string.
108
108
# '
109
109
# ' @export
110
110
# ' @examples
111
111
# ' format_inline("A message for {.emph later}, thanks {.fn format_inline}.")
112
112
113
113
format_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 ) {
119
115
opts <- options(cli.width = Inf )
120
116
on.exit(options(opts ), add = TRUE )
117
+ fun <- if (keep_whitespace ) cli_inline else cli_text
121
118
cli_fmt(
122
- cli_text( str , .envir = .envir ),
119
+ fun( ... , .envir = .envir ),
123
120
collapse = collapse ,
124
121
strip_newline = TRUE
125
122
)
@@ -208,6 +205,15 @@ cli_text <- function(..., .envir = parent.frame()) {
208
205
cli__message(" text" , list (text = glue_cmd(... , .envir = .envir , .call = sys.call())))
209
206
}
210
207
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
+
211
217
# ' CLI verbatim text
212
218
# '
213
219
# ' It is not wrapped, but printed as is. Long lines will overflow.
0 commit comments