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 ¶
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 ¶
NewFileRecorder creates (truncating) the cast file at path with 0o600 permissions and returns a Recorder that closes the file on Close.
func NewRecorder ¶
NewRecorder wraps w and records writes as asciinema v2 output frames with the given terminal dimensions.
func (*Recorder) Close ¶
Close flushes buffered frames and closes the underlying file if the Recorder owns one.
func (*Recorder) Start ¶
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.