marionebl / svg-term-cli

Share terminal sessions via SVG and CSS
MIT License
3.48k stars 116 forks source link

Support for asciicast 'idle_time_limit' #30

Open hjmallon opened 6 years ago

hjmallon commented 6 years ago

Asciicast version 2 files have a setting for 'idle_time_limit'. This is meant to compresses time differences bigger than the set amount. It is handy for making clean demos. svg-term-cli is not respecting that field currently.

marionebl commented 6 years ago

Jep, sounds like a good idea. Want to lend a hand?

hjmallon commented 6 years ago

It's as good an excuse as any to learn some more Javascript, I can have a poke around soon hopefully.

marionebl commented 6 years ago

It's as good an excuse as any to learn some more Javascript, I can have a poke around soon hopefully.

👍 That is very nice of you, thanks!

You'll want to have a look at the following lines that start the asciinema child process.

https://github.com/marionebl/svg-term-cli/blob/e22ca85ecc65286b309843d8072e273f1aa5eddd/src/cli.ts#L469-L475

They'll look something like:

 const result = await execa("asciinema", [ 
   "rec", 
   "-c", 
   cmd, 
   ...(options.title ? ["-t", options.title] : []), 
   ...(typeof options.maxWait === number ? ["--max-wait", options.maxWait] : [])
   tmp 
]); 

This changes also requires the addition of maxWait?: number; to RecordOptions.

asciinema expects --max-wait in seconds, while svg-term-cli uses milliseconds, so the record option will look like this:

record(cli.flags.command, {
  maxWait: typeof cli.flags.maxWait === "number" ? cli.flags.maxWait * 1000 : cli.flags.maxWait
})
hjmallon commented 6 years ago

I was actually talking about using a json file recorded by asciinema itself. But I see that tying it in here would be useful.

I reported a similar issue here: https://github.com/asciinema/asciicast2gif/issues/34 It was fixed by a commit (and new version bump) here: https://github.com/asciinema/asciinema-player/commit/5c922c8aa9dc4963fae01b71edd2a0542e922883

Maybe if https://github.com/marionebl/load-asciicast pulled it's submodule of asciiema-player up to v2.6.1 then at least the json might work.

This is all hearsay and suspicion as I have not got the build environment set up here yet, so pinch of salt required.

marionebl commented 6 years ago

Ok, that is interesting. Could you point to an asciicast that is affected?

hjmallon commented 6 years ago

Yep, here is one (that I added to the other issue) test.txt

hjmallon commented 6 years ago

Also I tried again today (reinstall from npm) and I assume that pulling the submodules up in the other repo has fixed this.

It works great now. Feel free to close this unless you want to keep it open for adding CLI support for this feature?

ku1ik commented 6 years ago

As long as you update load-asciicast library to use latest asciinema-player it will automatically handle idle_time_limit saved in the asciicast, and adjust timing properly. (asciicast/load ...) function also allows passing idle-time-limit value in case you want to override it / provide it from the command line.

Btw, I've set up a discussion forum for asciinema: https://discourse.asciinema.org/ , where I'd be happy to discuss this and any other asciinema/asciicast related topics 👋