{cli} output not captured by quarto slides #3957
Replies: 5 comments 14 replies
-
Try this from Danielle Navarro maybe? https://blog.djnavarro.net/posts/2021-04-18_pretty-little-clis/ |
Beta Was this translation helpful? Give feedback.
-
I am not completely sure to fully grasp the extent of what you want to achieve, but you should write a ---
format: revealjs
---
```{r}
#| echo: true
#| results: asis
options(crayon.enabled = TRUE)
library(knitr)
knit_print.myclass <- function(x, options) {
fansi::sgr_to_html(x = cli::style_bold("this should'nt work"), warn = FALSE, term.cap = "256")
}
registerS3method("knit_print", "myclass", knit_print.myclass)
(obj <- structure(list(1, 2, 3), class = "myclass"))
print(obj)
``` |
Beta Was this translation helpful? Give feedback.
-
@JosiahParry if I understand correctly you would like to have CLI output like colors showed in a knitted output ? cli is working with ANSI coloring and is made for terminal. Neither in R Markdown or Quarto you would get the formatting. I don't think it is a revealjs issue - it will not show any formatting in any format by default. Historically it was a crayon issue r-lib/crayon#24 (comment) To get ANSI formatting in HTML output, it would require specific handling, which the fansi package used by @mcanouil in his answer is doing (See vignette https://cran.r-project.org/web/packages/fansi/vignettes/sgr-in-rmd.html). Regarding why printing with ---
title: "this-dont-work"
format: revealjs
---
## define class with cli print
```{r}
#| echo: true
#| message: true
print.myclass <- function(x, ...) cli::cli_text(cli::style_bold("this shouldnt work"))
obj <- structure(list(1, 2, 3), class = "myclass")
obj
```
## change the print method
```{r}
#| echo: true
print.myclass <- function(x, ...) cat("this will work")
obj
``` Probably Hope it helps understand. |
Beta Was this translation helpful? Give feedback.
-
I wonder if Quarto should/could automatically do the equivalent for R users when it knows the final output format is html: ```{r setup, include = FALSE}
options(cli.num_colors = 256)
fansi::set_knit_hooks(knitr::knit_hooks)
``` Something like this would "just work" for most users. The equivalent functionality could alternatively be done as post-processing step, if injecting knitr hooks before evaluating code is not desirable. (This might require an update in if(fansi::has_sgr(x))
x <- fansi::sgr_to_html(fansi::html_esc(x)) |
Beta Was this translation helpful? Give feedback.
-
I think ideally, this would be implemented directly in quarto, so we could get cross-language support from one effort. However, I understand development time is limited, and My pragmatic suggestion is to inject |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Output from the cli package is not captured by reveal js slides.
Desired behavior: output from cli is captured and printed
Reprex:
Beta Was this translation helpful? Give feedback.
All reactions