Giter Club home page Giter Club logo

cast2gif's Introduction

Cast2Gif

A pure Python ANSI terminal emulator that can render AsciiCast terminal recordings to an animated GIF or screenshot.

Cast2Gif can also generate its own recordings directly, without requiring asciinema to be installed (see the --exec option).

For example, to generate a PNG screenshot of the output of the ls command, run

cast2gif --screenshot --output ls.png  --exec  "ls"

Quickstart

In the same directory as this README, run:

pip3 install .

This will automatically install the cast2gif executable in your path.

Usage

usage: cast2gif [-h] [-v] [--exec ...] [--hide-prompt] [--ps1 PS1] [-o OUTPUT]
                [--force] [--screenshot] [--font FONT] [-s FONT_SIZE]
                [--fps FPS] [--idle-time-limit IDLE_TIME_LIMIT] [--loop LOOP]
                [--quiet] [--width WIDTH] [--height HEIGHT] [--auto-size]
                [ASCIICAST]

Converts AsciiCast terminal recordings to animated GIFs

positional arguments:
  ASCIICAST             The AsciiCast v2 file to convert, or '-' for STDIN
                        (the default)

options:
  -h, --help            show this help message and exit
  -v, --version         Print version information and exit
  --exec ..., -c ...    Instead of parsing an AsciiCast v2 file, run the
                        command immediately after `--exec` and use its output
  --hide-prompt         By default, when using the `--exec` argument to run a
                        command, the command prompt is included before the
                        command output; this argument hides the prompt and
                        only includes the output
  --ps1 PS1             The PS1 command prompt to use in conjuction with the
                        `--exec` output (default="${PS1}", if it is set,
                        otherwise "$ " in green)
  -o OUTPUT, --output OUTPUT
                        The path for the output GIF file, or '-' for STDOUT
                        (default is the input filename plus '.gif', or STDOUT
                        if the input file is STDIN)
  --force               Overwrite the output file even if it already exists
  --screenshot, -sc     Render a screenshot rather than an animated gif
  --font FONT           Path to a TrueType font for rendering; defaults to
                        SourceCodePro; this argument can be supplied multiple
                        times, with additional fonts used in the event that
                        one is missing a required glyph
  -s FONT_SIZE, --font-size FONT_SIZE
                        Font size (default=12)
  --fps FPS             Speficy the number of frames per second in the output
                        GIF; by default, an optimal FPS is calculated
  --idle-time-limit IDLE_TIME_LIMIT
                        The maximum amount of idle time that can occur between
                        terminal events; by default this is read from the
                        AsciiCast input, or set to zero if none is specified
                        in the input; if provided, this option will override
                        whatever is specified in the input
  --loop LOOP           The number of times the GIF should loop, or zero if it
                        should loop forever (default=0)
  --quiet               Suppress all logging and status printouts
  --width WIDTH         Override the output width
  --height HEIGHT       Override the output height
  --auto-size           Override the output dimensions to be wide enough to
                        fit every line; if specified, this overrides the
                        `--width` option

License

Cast2Gif is licensed and distributed under the AGPLv3 license. Contact us if you’re looking for an exception to the terms.

Several fonts are distributed with Cast2Gif. They are licensed as follows:

cast2gif's People

Contributors

esultanik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cast2gif's Issues

Huge memory leak converting a file?

If you workaround issue #1 commenting the code that raises exceptions every time asciicast2gif finds unsupported escape characters using this patch:

diff --git a/asciicast2gif/asciicast.py b/asciicast2gif/asciicast.py
index 5a1b3be..1c49f7a 100644
--- a/asciicast2gif/asciicast.py
+++ b/asciicast2gif/asciicast.py
@@ -263,7 +263,7 @@ class ANSITerminal(Screen):
         elif char in '\030\031':
             self._state = ANSITerminal.TerminalState.OUTSIDE
         else:
-            raise Exception("Escape sequence ESC \\x%x is not currently supported!" % ord(char))
+            print("Escape sequence ESC \\x%x is not currently supported!" % ord(char))
 
     def _write_escbkt(self, char):
         esc_value = to_int(self._esc, 1)
@@ -308,13 +308,13 @@ class ANSITerminal(Screen):
                 # we don't need to handle bracketed paste mode
                 pass
             else:
-                raise Exception("ESC[%sh escape is currently unsupported!" % self._esc)
+                print("ESC[%sh escape is currently unsupported!" % self._esc)
         elif char == 'l':
             if self._esc == '?2004':
                 # we don't need to handle bracketed paste mode
                 pass
             else:
-                raise Exception("ESC[%sl escape is currently unsupported!" % self._esc)
+                print("ESC[%sl escape is currently unsupported!" % self._esc)
         elif char == 'm':
             self._write_esc_m()
         elif char == 's':
@@ -323,7 +323,7 @@ class ANSITerminal(Screen):
             if self._stored_pos is not None:
                 self.move_to(*self._stored_pos)
         elif char in 'STfinhl':
-            raise Exception("ESC[%s%s escape is currently unsupported!" % (self._esc, char))
+            print("ESC[%s%s escape is currently unsupported!" % (self._esc, char))
         else:
             matched = False
         if matched:

then converting this asciinema cast file will trigger very large memory allocations that will force you to kill the program (or you will have to restart your computer!)

Many escape characters currently unsupported!

If you try to convert this asciinema cast file using the latest revision of asciicast2gif, you will find unsupported escape characters:

$ asciicast2gif deepstate.cast 
[------------0.0%------------]Traceback (most recent call last):
  File "/home/g/.local/bin/asciicast2gif", line 11, in <module>
    load_entry_point('asciicast2gif==0.0.1', 'console_scripts', 'asciicast2gif')()
  File "/home/g/.local/lib/python3.6/site-packages/asciicast2gif-0.0.1-py3.6.egg/asciicast2gif/__main__.py", line 105, in main
    cast.render(output_stream, font, fps = args.fps, idle_time_limit = args.idle_time_limit, loop=args.loop, frame_callback = frame_callback)
  File "/home/g/.local/lib/python3.6/site-packages/asciicast2gif-0.0.1-py3.6.egg/asciicast2gif/asciicast.py", line 429, in render
    term.write(data)
  File "/home/g/.local/lib/python3.6/site-packages/asciicast2gif-0.0.1-py3.6.egg/asciicast2gif/asciicast.py", line 240, in write
    self.write(c)
  File "/home/g/.local/lib/python3.6/site-packages/asciicast2gif-0.0.1-py3.6.egg/asciicast2gif/asciicast.py", line 249, in write
    self._write_escbkt(char)
  File "/home/g/.local/lib/python3.6/site-packages/asciicast2gif-0.0.1-py3.6.egg/asciicast2gif/asciicast.py", line 311, in _write_escbkt
    raise Exception("ESC[%sh escape is currently unsupported!" % self._esc)
Exception: ESC[?1h escape is currently unsupported!

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.