Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting width and height of an asciinema #234

Closed
jbenet opened this issue Feb 16, 2017 · 2 comments
Closed

getting width and height of an asciinema #234

jbenet opened this issue Feb 16, 2017 · 2 comments

Comments

@jbenet
Copy link

jbenet commented Feb 16, 2017

in https://github.com/jbenet/asciinema-selfhost/ i used to get the size with: https://github.com/jbenet/asciinema-selfhost/blob/f2f2bd8fed21b42ee59d5e7b46b5fd09f0285b1e/index.js#L60-L61 which was pretty terrible but seemed to work always.

I'm updating it. Now, using the new .json url (eg https://asciinema.org/a/91304.json) some asciinema json files have the width/height attributes, and some do not (eg https://asciinema.org/a/103367.json) (these were grabbed as examples randomly from public listing). Maybe all old versions of files need to be updated? Or if not, is there a better (robust) way to get the width/height always? Thanks!

@ku1ik
Copy link
Contributor

ku1ik commented Feb 16, 2017

The JSON files without width/height are produced by old (< 1.0.0) version of the player. asciinema.org still supports these clients but I plan to drop the support soon (these clients are 2-3 years old now).

You can do the following. Check what's the first character in the file.

If it's { - parse with JSON.parse and get width and height properties.

If it's [ - it's more tricky because it's a legacy format :) First parse with JSON.parse (and assign it to let's say data var), then get data[0][1]["lines"]. The result will be an object with line numbers as keys (count the keys to get the height). To get the width... First get first line (data[0][1]["lines"]["0"]), then extract all strings from it (the line is an array of 2-element arrays where strings are first element), concatenate them and the length of the string will be width of the terminal :) Alternatively you can just not support this old format.

@jbenet
Copy link
Author

jbenet commented Feb 16, 2017

thanks! i opted with not supporting it for now. and filed jbenet/asciinema-selfhost#4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants