Coder Social home page Coder Social logo

asciicast's Introduction

asciicast

Turn R scripts into terminal screencasts

Lifecycle: experimental Linux Build Status Windows Build status CRAN status

asciicast takes an R script and turns it into an asciinema cast. It can simulate typing, and records all terminal output in real time as it happens.

Features

  • Input is an R script, output is a v2 asciicast recording.
  • Record all terminal output in real time, as it happens.
  • Simulate typing in the commands, with a configurable, randomized speed.
  • Alternatively, whole comment blocks or expressions can just appear on the screen.
  • Convert casts to SVG images using svg-term. The package comes with its own svg-term bundle, no external dependencies are needed.
  • Render a single frame of a cast as an SVG image.
  • Configurable delay at the beginning, at the end and between paragraphs.
  • HTML widget, to be used in Rmarkdown documents, e.g. in vignettes.
  • Read casts from asciinema JSON files (version 2), or from https://asciinema.org directly.
  • Special knitr engine to create R markdown files with ascii casts. See the asciicast-demo vignette.
  • Create ascii casts in GitHub READMEs via animated SVG files. See an example in inst/examples or the README.Rmd source of the README file you are reading.

Limitations

  • asciicast does not work in Windows yet, because of a the lack of a pseudo terminal. Maybe you can try running it on Linux in Docker?
  • Recordings are currently real time, so if you “type in” a lot of code/text, that might take a while to record.
  • Only syntactically correct R script files can be recorded.
  • asciicast redefines option("error") currently, so if you want to set this option in your demo, that won’t work.

Installation

You can install the released version of asciicast from CRAN:

install.packages("asciicast")

Examples

See the inst/examples directory for these examples.

Hello world

The input script:


#' Rows: 10

print("Hello world!")

Asciicast demo in asciicast

Input script that uses asciicast itself:


#' Title: asciicast example recorded in asciicast
#' Cols: 80
#' Rows: 40
#' Empty_wait: 3
#' End_wait: 20

# <<
# An example for using asciicast, recorded in asciicast itself!

# First, save the R code you want to run, in a script file.
# The file can contain any code, including interactive code,
# as long as it is a syntactically valid R file.

# Second, perform the recording with the `record()` function.
# We are recording an example file now, that comes with the package.
# <<

src <- system.file("examples", "hello.R", package = "asciicast")
cast <- asciicast::record(src)

# <<
# `cast` is an `asciicast` object, which has some metadata and the
# recording itself:
# <<

cast

# <<
# You can write `cast` to a JSON file that can be played by any
# asciinema player. Or you can write it to an SVG file that can
# be embedded into a web page, or a GitHub README.
# <<

svg <- tempfile(fileext = ".svg")
asciicast::write_svg(cast, svg, window = TRUE)

Errors are recorded

Input script with errors:


#' Rows: 15

# Demonstrate that errors are handled well

library("not-this-really")

traceback()

1+1

Related tools

License

MIT @ RStudio

asciicast's People

Contributors

batpigandme avatar gaborcsardi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.