Documentation
¶
Overview ¶
Package termrec records what a program writes to a terminal, saves it as an asciinema cast, and draws it as an animated GIF or a still.
Index ¶
- Constants
- Variables
- func Frame(data []byte, n int) (image.Image, error)
- func GIF(rec Recording) ([]byte, error)
- func IsCast(data []byte) bool
- func Still(rec Recording, n int) (image.Image, error)
- func StillText(rec Recording, n int) (string, error)
- func WriteCast(w io.Writer, rec Recording) error
- type Event
- type Recorder
- type Recording
- type Screen
Constants ¶
const ( MaxCols = 1000 MaxRows = 500 MaxEvents = 100_000 MaxOutput = 16 << 20 )
Limits on the casts ReadCast reads, so a file made to be huge can't make a report or the GUI allocate without bound. MaxCols and MaxRows match the front matter's own limits on terminal size.
Variables ¶
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 ¶
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 ¶
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 IsCast ¶ added in v1.4.0
IsCast reports whether data starts like an asciicast v2 file: a JSON object with "version": 2 on its first line.
func Still ¶ added in v1.4.0
Still draws frame n of rec, counting from 1, as GIF would show it. n <= 0, or past the end, is the last frame.
Types ¶
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is an io.Writer that records what is written to it.
func NewRecorder ¶
NewRecorder starts a recording of a cols by rows terminal.
type Recording ¶
Recording is a terminal session: the bytes written to the screen, and when.
func ReadCast ¶
ReadCast reads an asciicast v2 file. Events other than output are skipped. A cast wider than MaxCols, taller than MaxRows, or with more than MaxEvents writes or MaxOutput bytes of them is refused.
func (Recording) FullScreen ¶ added in v1.3.0
FullScreen reports whether rec switched to the terminal's alternate screen, as full-screen programs such as vim, less and top do.
func (Recording) Text ¶ added in v1.3.0
Text is what rec wrote, as plain text that reads the way the terminal showed it: escape sequences are dropped, a carriage return starts its line over, a backspace steps back and erasing to the end of the line erases. Trailing spaces and blank lines at the end are left off.
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.