Beispiel #1
0
def record_render_subcommand(process_args, still, template, geometry,
                             input_fileno, output_fileno, output_path,
                             min_frame_duration, max_frame_duration,
                             loop_delay):
    """Record and render the animation on the fly"""
    from termtosvg.term import get_terminal_size, TerminalMode, record, timed_frames

    logger.info('Recording started, enter "exit" command or Control-D to end')
    if geometry is None:
        columns, lines = get_terminal_size(output_fileno)
    else:
        columns, lines = geometry
    with TerminalMode(input_fileno):
        # Do not write anything to stdout (print, logger...) while in this
        # context manager if the output of the process is set to stdout. We
        # do not want two processes writing to the same terminal.
        asciicast_records = record(process_args, columns, lines, input_fileno,
                                   output_fileno)
        geometry, frames = timed_frames(asciicast_records, min_frame_duration,
                                        max_frame_duration, loop_delay)

        if still:
            termtosvg.anim.render_still_frames(frames, geometry, output_path,
                                               template)
            end_msg = 'Rendering ended, SVG frames are located at {}'
        else:
            termtosvg.anim.render_animation(frames, geometry, output_path,
                                            template)
            end_msg = 'Rendering ended, SVG animation is {}'

    logger.info(end_msg.format(output_path))
Beispiel #2
0
def record_subcommand(process_args, geometry, input_fileno, output_fileno,
                      cast_filename):
    """Save a terminal session as an asciicast recording"""
    from termtosvg.term import get_terminal_size, TerminalMode, record
    logger.info('Recording started, enter "exit" command or Control-D to end')
    if geometry is None:
        columns, lines = get_terminal_size(output_fileno)
    else:
        columns, lines = geometry
    with TerminalMode(input_fileno):
        # Do not write anything to stdout (print, logger...) while in this
        # context manager if the output of the process is set to stdout. We
        # do not want two processes writing to the same terminal.
        records = record(process_args, columns, lines, input_fileno,
                         output_fileno)
        with open(cast_filename, 'w') as cast_file:
            for record_ in records:
                print(record_.to_json_line(), file=cast_file)
    logger.info('Recording ended, cast file is {}'.format(cast_filename))