Replay

CI Stable Dev

Introduction

Let’s assume you have to record your screen to explain something about Julia topics e.g. how to use REPL, how to use your great package in Julia REPL etc… You are supposed to input your source code by hand line by line. Imagine that you type the following lines.

julia> 2+2
julia> print("")
julia> display([1])
julia> display([1 2; 3 4])
julia> @time 1+1
julia> using Pkg; Pkg.activate(".")
pkg> add Example
pkg> rm Example
pkg> st

Should we type them one by one using your fingers? We are too lazy to do. Don't worry! Our package Replay.jl saves your life!

Usage

$ git clone https://github.com/AtelierArith/Replay.jl.git
$ cd Replay.jl
$ cat ./examples/readme/app.jl
using Replay

repl_script = """
2+2
print("")
display([1])
display([1 2; 3 4])
@time 1+1
using Pkg; Pkg.activate(".")
]add Example
rm Example
st
$CTRL_C
"""

replay(repl_script, stdout, julia_project=@__DIR__, use_ghostwriter=true, cmd=`--color=yes`)
$ julia --project=@. -e 'using Pkg; Pkg.instantiate()'
$ julia --project=@. ./examples/readme/app.jl
$ # Below is optional
$ asciinema rec result.cast --command "julia --project=@. ./examples/readme/app.jl"
$ asciinema play result.cast

asciicast

You can redirect the output of the program into a file:

$ julia --project=@. ./examples/helloworld/app.jl > output.txt
$ cat output.txt

Tips: you can set replay(instructions; cmd=`--color=no`) as necessary.

$ julia examples/disable_color/app.jl > output.txt
$ cat output.txt

Record instructions using asciinema

  • asciinema is a free and open source solution for recording terminal sessions and sharing them on the web. It can be used in combination with Replay.jl with the following commands:
$ pip3 install asciinema # install `asciinema`
$ asciinema rec output.cast --command "julia examples/helloworld/app.jl"
$ asciinema play output.cast

See issue #23 to learn more.

Breaking Changes

v0.5.x

  • The type of the keyword argument cmd has been changed from String to Cmd.

v0.4.x

  • The keyword argument color of replay is removed. Use cmd="--color=yes" or cmd="--color=no" instead.

Restriction

  • Currently, Replay.jl does not work on Windows. Please use WSL2 instead, or help in issue #44.

Acknowledgements

Replay.jl is based on

The idea of how to replay julia session comes from

@hyrodium san provided an excellent logo for our package.

Appendix

Blog post

YouTube