Package: asciifx
asciifxasciinemais a great tool for recording, viewing, and
sharing live terminal performances. But sometimes, a performance really needs to
be carefully scripted and its staging carefully controlled. That's when you turn
toasciifx.In particular, asciifx turns plain Python scripts intoversion 2
asciicastsof what might be a person executing the script line by line in an interactive
Python interpreter. It features semi-realistic keystroke dynamics as well as
pauses for reading interpreter output. Beyond this first use-case, asciifx has
well-defined internal interfaces that make extension straight-forward.An ExampleConsider this Python script to show off the libray that inspired this package,konsole:#[keypress-speed=0.6]#[off]importkonsolekonsole.config(use_color=True)#[on]konsole.info("fyi",detail=["for","your","information"])konsole.warning("beware")konsole.error("bad")konsole.critical("enough already!!!")quit()The comments may look likeRust
annotationsbut still
are valid Python. In the context of asciifx, they also are called pragmas and
control the performance.keypress-speedspeeds up simulated keypresses because
they just aren'tthatinteresting to watch.off/onprevent the import and
configuration of konsole from appearing in the final asciicast, though the two
statements are executed nonetheless.With that, we are ready to run asciifx:$python-masciifx--height13-ooutput.castinput.pyYou can watch the resulting asciicast with asciinema — or convert it to SVG withsvg-term-cli:PragmasTo be recognized by asciifx, a pragma must appear on a line, by itself. asciifx
supports the following pragmas:#[off]suspends rendering to asciicast events.#[on]restores the rendering of asciicast events.#[think-time=FLOAT]inserts a pause ofFLOATseconds after the next
interaction's interpreter prompt.#[speed=FLOAT]adjusts overall duration by multiplying all delays byFLOAT.#[keypress-speed=FLOAT]adjusts keypress duration by multiplying keypress delays
byFLOAT.Whereasthink-timetakes an absolute value in seconds,speedandkeypress-speedtake relative, multiplicative values. To make these semantics
obvious even to casual users,think-timeends withtime, whereasspeedandkeypress-speedend withspeed. Thespeedandkeypress-speedpragmas
multiply by their arguments instead of the inverse of their arguments because
that makes jumping through time trivial: Just setspeedorkeypress-speedto
zero! At the same time, beware that the combined impact ofspeedandkeypress-speedis multiplicative on the duration between keypresses.An Itch to Scratchasciifx exists because I had an itch to scratch: creating an animated screenshot
to show off konsole. Python's REPL is great for showing off an interface, since
it displays the result of each statement right after executing, andasciinemais great for recording such
interactions. The problem is that getting such a performance right pretty much
requires scripting everything beforehand. But if it's already scripted, it makes
little sense to type out the code again at a Python REPL.So I scoped out writing my own tool: Python'scode
modulehas all the REPL support
I'd need, nicely abstracted.asciicast
v2is
an eminently reasonable file format to target. All that was missing was a
suitable model for human keystroke dynamics. After a quick literature search,
even that model seemed within reach.Alas, turning scientific writing into executable code easily becomes an exercise
in frustration. There is ambiguous language in the definition of critical
metrics when perfectly well-defined terminology and metrics exist. (Yes, IKI is
the same as flight time shifted by hold time. No, "keypress event" is not an
abstract event related to pressing keys but an actual,deprecated JavaScript
event.)
There also are probability distributions that are surprisingly hostile to casual
human use. (No, μ and σ arenotthe mean and standard deviation of the
log-normal distribution. Yes, they are the customary parameters for that
distribution nonetheless. Converting mean and standard deviation to these
parameters is left as an exercise for the reader. 😈)© 2022Robert Grimm.Apache 2.0license.GitHub.