Asciinema: Playing casts inside Jupyter?

Created on 27 Mar 2018  ·  10Comments  ·  Source: asciinema/asciinema

I wonder how much effort it would be to play casts directly inside Jupyter cells? This _might_ need wrapping the text output in some thin HTML envelope, but maybe that's not even needed.

I've raised an issue originally on asciinema-player here: https://github.com/asciinema/asciinema-player/issues/85, but maybe here is a good place, too, if we could show casts directly without the whole asciinema-player machinary.

Most helpful comment

Hi @deeplook, you can insert the embed code in your Jupyter notebook and insert the asciinema cast directly in your Jupyter Notebook

from IPython.display import HTML
HTML("""<script src="https://asciinema.org/a/1wkyfecyj2qa4t9gm4bank61y.js" id="asciicast-1wkyfecyj2qa4t9gm4bank61y" async></script>""")

image

The magical function %%html is also working
image

See this video: https://www.useloom.com/share/e606957f1aa0431399c30c1b95cb5207

All 10 comments

Hi @deeplook, you can insert the embed code in your Jupyter notebook and insert the asciinema cast directly in your Jupyter Notebook

from IPython.display import HTML
HTML("""<script src="https://asciinema.org/a/1wkyfecyj2qa4t9gm4bank61y.js" id="asciicast-1wkyfecyj2qa4t9gm4bank61y" async></script>""")

image

The magical function %%html is also working
image

See this video: https://www.useloom.com/share/e606957f1aa0431399c30c1b95cb5207

@zodiacfireworks Thanks! It's surely wonderful to be able to run remote screencasts hosted on asciinema.org.

Rereading my question I admit it's not so evident, but I thought more of running a local screencast either in a "normal" Jupyter cell with asciinama-player. I had tried using asciinama-player on local casts, but in vain. Doing this with the familiar asciinama-player interface for local files would be very nice, too.

But, ermmm... I've just tried the most unlikely thing to do, and to my big surprise this works! I've simply typed ! /my/path/asciinema play demo.cast in a code cell! And, frankly, I didn't expect this to work, but it seems like it does! The output is shown as usual, respecting timing info and ANSI escape codes. But it "ignores" the recorded values for the terminal's width and height, taking the full cell width and not doing any vertical windowing. But hey, this is amazing!

Should we close it then? ;)

We could if there would also be a well-defined way of adding the asciinema-player bits to Jupyter to make it run local casts, too. I've tried that at the beginning, but no luck.

Ah, so we're talking 3 ways of embedding the player here:

  1. via subcommand: ! /my/path/asciinema play demo.cast
  2. via embed <script>: HTML("""<script src="https://asciinema.org/a/1wkyfecyj2qa4t9gm4bank61y.js" ...
  3. via local copy of asciinema-player.js + local .cast file

I think first 2 have been solved already, right?

@deeplook you refering to 3.?

@sickill Correct. I assume that (2) would also work for any other site which has asciinema-player installed.

It would actually help to catch-up with TermRecord, where I can simple point to a self-contained HTML file, like shown here:

from IPython.display import IFrame
IFrame('http://theonewolf.github.io/TermRecord/hello-static.html', 800, 300)

Does TermRecord's file contain everything inline? Just single html file with no js/data files?

I have no clue, as it's just something friends have told me about. One must assume the HTML contains JS/CSS...

I assume it would be easy to add an option to asciinema-player to generate self-contained HTML blobs, including CSS/JS and the data.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dlintw picture dlintw  ·  11Comments

TyrfingMjolnir picture TyrfingMjolnir  ·  7Comments

laughedelic picture laughedelic  ·  7Comments

pfalcon picture pfalcon  ·  4Comments

omaraboumrad picture omaraboumrad  ·  10Comments