termrec

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package termrec records what a program writes to a terminal, saves it as an asciinema cast, and plays it back as an animated GIF.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("nothing was written to the terminal")

ErrEmpty is returned by GIF for a recording with nothing in it.

Functions

func Frame

func Frame(data []byte, n int) (image.Image, error)

Frame returns frame n of an animated GIF as it looks on screen, counting from 1. n <= 0, or past the end, is the last frame.

func GIF

func GIF(rec Recording) ([]byte, error)

GIF plays rec through a terminal emulator and returns the screens it shows as a looping animated GIF. A frame is drawn at most every 100ms, and only the rows that changed are stored. Rows the session never reached are left off.

func WriteCast

func WriteCast(w io.Writer, rec Recording) error

WriteCast writes rec in asciinema's asciicast v2 format: a JSON header line, then one [seconds, "o", text] line per write. A UTF-8 character split across writes is kept whole in the later one, since each line must be valid text.

Types

type Event

type Event struct {
	At   time.Duration
	Data []byte
}

Event is one write to the screen, At after the recording started.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder is an io.Writer that records what is written to it.

func NewRecorder

func NewRecorder(cols, rows int) *Recorder

NewRecorder starts a recording of a cols by rows terminal.

func (*Recorder) Recording

func (r *Recorder) Recording() Recording

Recording returns what has been recorded so far.

func (*Recorder) Write

func (r *Recorder) Write(p []byte) (int, error)

type Recording

type Recording struct {
	Cols, Rows int
	Start      time.Time // zero if unknown
	Events     []Event
}

Recording is a terminal session: the bytes written to the screen, and when.

func ReadCast

func ReadCast(r io.Reader) (Recording, error)

ReadCast reads an asciicast v2 file. Events other than output are skipped.

type Screen

type Screen struct {
	// contains filtered or unexported fields
}

Screen is a terminal emulator to write a program's output to, for reading what it shows.

func NewScreen

func NewScreen(cols, rows int) *Screen

NewScreen returns a blank cols by rows screen.

func (*Screen) Text

func (s *Screen) Text() string

Text returns what the screen shows, one line per row, without trailing spaces.

func (*Screen) Write

func (s *Screen) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL