---
output: github_document
always_allow_html: yes
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)
```

# Using ascii casts in GitHub README files

GitHub READMEs do not allow custom JavaScript code, so we cannot use
HTML widgets in them. But they do allow SVG images, which can also be
animated. This is file is an example README. See the source Rmd file.

First we need to initialize the asciicast engine, as usual:

````
```{r echo = FALSE, results = "hide"}`r ''`
asciicast::init_knitr_engine()
```
````

```{r echo = FALSE, results = "hide"}
options(asciicast_theme = "asciinema")
asciicast::init_knitr_engine()
```

Now we are ready to include casts. The current default is to create a
snapshot of the screen after the code has run:

## Still screenshots

To include a snapshot instead of an animation, the `at` option must be
set to `"end"`, but that is the default currently:

````
```{asciicast, cache = TRUE}`r ''`
# This is an asciicast example
loadedNamespaces()
```
````

```{asciicast, cache = TRUE}
# This is an asciicast example
loadedNamespaces()
```

## Proper ASCII casts

To use animated casts instead of screen shots, we need to set the
`at` option to `all`. We also set `end_wait` to wait five second before
restarting the animation. By default asciicast creates animated SVG files:

````
```{asciicast, cache = TRUE}`r ''`
#' Rows: 10
#' End_wait: 5
#' At: all
# This is an asciicast example
loadedNamespaces()
```
````

```{asciicast, cache = TRUE}
#' At: all
#' End_wait: 5
# This is an asciicast example
loadedNamespaces()
```

## ANSI colors

asciicast supports 256 ANSI colors, and ANSI support is automatically
enabled in the asciicast subprocess:

````
```{asciicast, cache = TRUE}`r ''`
cli::ansi_palette_show()
```
````

```{asciicast, cache = TRUE}
cli::ansi_palette_show()
```
