Code Monkey home page Code Monkey logo

asciinema-vsync's Introduction

Asciinema Vsync

A tool for processing the JSON output of Asciinema in order to batch together its captured events (similar to how the vsync pulse is used to batch GUI changes). This helps reduce flicker of the final rendering when targeting formats like SVG or GIF.

Before After

The differences here are extremely subtle! You can occasionally see flickers in the "Before" image as it displays a partially-updated output which are not present in the "After".

The JSON input used to create those two images should further highlight the behavior of this tool:

Before:

{"version": 2, "width": 247, "height": 50, "timestamp": 1603340113, "env": {"SHELL": "/usr/local/bin/bash", "TERM": "xterm-256color"}}
[0.232306, "o", "Tests: 0 to"]
[0.232908, "o", "tal\u001b[K\r\nTime:  0s     \u001b[K\r\n"]
[0.294751, "o", "\u001b[F\u001b[F"]
[0.2948, "o", "\u001b[33;43"]
[0.294816, "o", "m"]
[0.295049, "o", "_\u001b[30mRU"]
[0.295122, "o", "NS \u001b[39;49m tests"]
[0.295202, "o", "/\u001b[1mlo"]
[0.295269, "o", "gin.kt\u001b[2"]
[0.295343, "o", "2m    "]
[0.295443, "o", "      \u001b"]
[0.29554, "o", "[K\r\n\u001b"]
[0.295652, "o", "[33;43m_"]
[0.295732, "o", "\u001b[30mRUNS "]
[0.295866, "o", "\u001b[39;49m tests"]
[0.29594, "o", "/\u001b[1msignup"]
[0.295958, "o", ".k"]
[0.295972, "o", "t\u001b"]
 

The output in this "Before" JSON is fragmented across multiple commands which occur fractions of a second apart. This is despite the fact that the originating program issued the output as large, single writes.

After:

{"version": 2, "width": 247, "height": 50, "timestamp": 1603340113, "env": {"SHELL": "/usr/local/bin/bash", "TERM": "xterm-256color"}}
[0.232306,"o","Tests: 0 total\u001b[K\r\nTime:  0s     \u001b[K\r\n"]
[0.294751,"o","\u001b[F\u001b[F\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mlogin.kt\u001b[22m          \u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1msignup.kt\u001b[22m         \u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mforgot-password.kt\u001b[22m\u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mreset-password.kt\u001b[22m \u001b[K\r\n                               \u001b[K\r\nTests: 4 total                 \u001b[K\r\nTime:  0s                      \u001b[K\r\n"]
[1.265236,"o","\u001b[F\u001b[F\u001b[F\u001b[F\u001b[F\u001b[F\u001b[F\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mlogin.kt\u001b[22m          \u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1msignup.kt\u001b[22m         \u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mforgot-password.kt\u001b[22m\u001b[K\r\n\u001b[33;43m_\u001b[30mRUNS \u001b[39;49m tests/\u001b[1mreset-password.kt\u001b[22m \u001b[K\r\n                               \u001b[K\r\nTests: 4 total                 \u001b[K\r\nTime:  1s                      \u001b[K\r\n"]
 

Once processed with this tool, the outputs which occur close together have been merged. The commands are now more reflective of the writes from the original program.

Additionally, SVGs produced by svg-term on the JSON output of this tool are significantly smaller than those on the raw JSON.

Usage

$ asciinema rec raw.json
$ asciinema-vsync raw.json vsync.json

$ svg-term --in vsync.json --out demo.svg  # Just an example

See src/test/fixtures/ for example input and expected outputs.

Install

Mac OS

$ brew install JakeWharton/repo/asciinema-vsync

Other

Download standalone JAR from latest release. On MacOS and Linux you can chmod +x and execute the .jar directly. On Windows use java -jar.

License

Copyright 2020 Jake Wharton

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

asciinema-vsync's People

Contributors

jakewharton avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.