termrec

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package termrec records governed terminal sessions as asciinema v2 "cast" files and replays them. A cast file is a single JSON header line followed by one JSON array per output frame: [elapsedSeconds, "o", "data"].

The package is deliberately path-agnostic and depends only on the standard library so it can be teed into any terminal PTY stream via io.MultiWriter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Replay

func Replay(r io.Reader, w io.Writer, realtime bool) error

Replay parses a cast file from r and writes its output frames to w. When realtime is true, it sleeps between frames to honor their timestamps (each gap capped at maxGap); otherwise output frames are dumped back-to-back.

The header line is validated as asciinema v2 JSON. Only "o" (output) frames are replayed; input and other event types are ignored.

Types

type Recorder

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

Recorder implements io.Writer and captures every write as an asciinema v2 output frame. It is safe for concurrent use.

Recorder is designed to sit inside an io.MultiWriter(realConn, recorder) tee: Write always reports the full byte count and a nil error, even if frame encoding fails, so a recording problem can never corrupt or stall the real terminal stream.

func NewFileRecorder

func NewFileRecorder(path string, width, height int) (*Recorder, error)

NewFileRecorder creates (truncating) the cast file at path with 0o600 permissions and returns a Recorder that closes the file on Close.

func NewRecorder

func NewRecorder(w io.Writer, width, height int) *Recorder

NewRecorder wraps w and records writes as asciinema v2 output frames with the given terminal dimensions.

func (*Recorder) Close

func (r *Recorder) Close() error

Close flushes buffered frames and closes the underlying file if the Recorder owns one.

func (*Recorder) Start

func (r *Recorder) Start() error

Start writes the cast header if it has not been written yet, anchoring the recording clock. It is safe to call multiple times; only the first call has an effect. Write calls Start implicitly, so most callers never need it.

func (*Recorder) Write

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

Write records p as a single output frame and returns len(p), nil. Frame encoding errors are intentionally swallowed so the enclosing io.MultiWriter tee reports the same byte count for every writer and the real terminal stream is never disrupted.

Jump to

Keyboard shortcuts

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