Documentation
¶
Index ¶
- Constants
- Variables
- func BuildGrid(path string) (*cellbuf.Buffer, error)
- func CommandSlug(args []string) string
- func NormalizeRecording(path string, replacements map[string]string) error
- func Play(path string, out io.Writer) error
- func RandomID(n int) string
- func ReadEvents(path string) (Header, []Event, error)
- func Render(input string, opts *RenderOptions) error
- func RenderASCII(input, output string) error
- func RenderHTML(input, output string) error
- func RenderJPEG(input, output string) error
- func RenderMarkerScreenshots(castPath string) error
- func RenderMarkerScreenshotsAt(castPath, basePath string) error
- func RenderPNG(input, output string) error
- func ResolvePath(opts *Options, started time.Time) (string, error)
- func RunSession(ctx context.Context, opts *SessionOptions) error
- func ValidateDeclaration(path string, plan *castplan.Plan) (string, error)
- func ValidateKey(key string) error
- type Event
- type ExecOptions
- type ExecResult
- type Header
- type Options
- type Recorder
- func (r *Recorder) Close() error
- func (r *Recorder) Discard() error
- func (r *Recorder) Event(stream, content string) error
- func (r *Recorder) Path() string
- func (r *Recorder) Record(stream, content string)
- func (r *Recorder) Resize(width, height int) error
- func (r *Recorder) ValidateBeforeCommit(validate func(string) error) error
- func (r *Recorder) Width() int
- func (r *Recorder) WithPlaybackDuration(duration time.Duration, run func() error) (err error)
- type RenderOptions
- type SessionAction
- type SessionOptions
- type Tape
- type TapeDirective
- type TapeDirectiveKind
- type TapeError
- type TapeFileReader
- type Term
Constants ¶
const ( // DefaultWidth is the fallback terminal width for cast recordings. DefaultWidth = 120 // DefaultHeight is the fallback terminal height for cast recordings. DefaultHeight = 36 )
const ( // ShellInitClean skips the user's shell rc/profile files so a recording gets a predictable prompt and no plugins. ShellInitClean = "clean" // ShellInitUser runs the shell's normal interactive startup files. ShellInitUser = "user" )
Variables ¶
var ( // ErrEmptyCastFile indicates that a cast file had no header line. ErrEmptyCastFile = errUtils.ErrEmptyCastFile // ErrRenderOutputExists indicates that a render target already exists. ErrRenderOutputExists = errUtils.ErrRenderOutputExists // ErrMissingAgg is retained for backwards compatibility. Animated rendering // now installs agg through the Atmos toolchain instead of returning this error. ErrMissingAgg = errUtils.ErrMissingAgg // ErrMissingFFmpeg is retained for backwards compatibility. MP4 rendering // now installs FFmpeg through the Atmos toolchain instead of returning this error. ErrMissingFFmpeg = errUtils.ErrMissingFFmpeg )
var ( // ErrUnknownSessionAction indicates an unsupported scripted session action type. ErrUnknownSessionAction = errUtils.ErrUnknownSessionAction // ErrWaitTimeout indicates that a wait action did not observe the expected output before its deadline. ErrWaitTimeout = errUtils.ErrWaitTimeout // ErrUnsupportedCastKey indicates that a key action requested an unknown key sequence. ErrUnsupportedCastKey = errUtils.ErrUnsupportedCastKey // ErrScreenshotActionRequiresPath indicates a "screenshot" session action had no output path. ErrScreenshotActionRequiresPath = errUtils.ErrScreenshotActionRequiresPath // ErrSimulateActionMissingCallback indicates a "simulate" action was built without its Fn callback set. ErrSimulateActionMissingCallback = errUtils.ErrSimulateActionMissingCallback )
var ( ErrTapeParseFailed = errUtils.ErrTapeParseFailed ErrUnsupportedTapeDirective = errUtils.ErrUnsupportedTapeDirective ErrTapeSourceNotFound = errUtils.ErrTapeSourceNotFound ErrTapeSourceCycle = errUtils.ErrTapeSourceCycle )
Tape errors, aliased from the shared sentinel set so callers outside this package can match them with errors.Is without importing errors/errors.go.
var ErrCastOutputExists = errUtils.ErrCastOutputExists
ErrCastOutputExists indicates that a requested cast output path already exists.
var ErrMissingExecCommand = errUtils.ErrMissingExecCommand
ErrMissingExecCommand indicates that ExecRecord was called without a command.
var ErrScreenshotRenderFailed = errUtils.ErrScreenshotRenderFailed
ErrScreenshotRenderFailed indicates a marker screenshot could not be rendered or written to disk.
Functions ¶
func BuildGrid ¶
BuildGrid replays a cast file's output events into a styled terminal cell grid. The grid preserves the full scrollback (it grows past the recorded terminal height) so renderers can emit complete command output, matching how the legacy aha-based screengrab pipeline converted entire streams.
func CommandSlug ¶
CommandSlug converts command arguments into a filesystem-safe cast filename slug.
func NormalizeRecording ¶
NormalizeRecording replaces literal output values in a staged recording, including matches split across events. It retains event ordering, timing, and metadata.
func ReadEvents ¶
ReadEvents reads an asciicast file header and event stream.
func Render ¶
func Render(input string, opts *RenderOptions) error
Render generates requested media outputs from an asciicast file.
func RenderASCII ¶
RenderASCII writes the final terminal content of a cast file as plain text with no ANSI escape sequences. The output is a durable, diffable artifact suitable for committing to git and for machine consumption (e.g. Atmos Pro).
func RenderHTML ¶
RenderHTML writes the final terminal content of a cast file as an HTML fragment of inline-styled spans, one line per text line. The fragment is consumed by the website Screengrab component via dangerouslySetInnerHTML inside a <pre>, so no wrapper element and no background colors are emitted (backgrounds broke light/dark themes with the legacy aha pipeline).
func RenderJPEG ¶
RenderJPEG writes the final terminal content of a cast file as a JPEG image.
func RenderMarkerScreenshots ¶
RenderMarkerScreenshots scans a finished cast recording for "m" marker events (written by session/step "screenshot" actions via pkg/io.RecordMarker) and rasterizes a PNG of the terminal's cell-grid state as of each marker's timestamp, writing it to the path carried in the marker's content. It is a no-op if the recording has no marker events.
func RenderMarkerScreenshotsAt ¶
RenderMarkerScreenshotsAt resolves relative screenshot paths against the invocation directory.
func ResolvePath ¶
ResolvePath returns the cast output path for the supplied options and start time.
func RunSession ¶
func RunSession(ctx context.Context, opts *SessionOptions) error
RunSession executes scripted session actions against an interactive shell. A context deadline bounds the entire session, including shell completion. Without one, teardown uses a bounded fallback after submitting EOF. Startup quiet is a recording heuristic, not proof that the shell has finished initializing.
func ValidateDeclaration ¶
ValidateDeclaration verifies saved recording evidence without executing or rendering anything. The returned text contains raw output for caller-supplied policies such as color checks.
func ValidateKey ¶
ValidateKey checks a named terminal key before a recording starts.
Types ¶
type ExecOptions ¶
type ExecOptions struct {
// Command is the argv to run; Command[0] is resolved via PATH.
Command []string
// Dir is the working directory for the command (empty = inherit).
Dir string
// Env is the full environment for the command (nil = inherit).
Env []string
// Path is the output .cast file path.
Path string
// Width and Height size the recorded terminal (0 = defaults).
Width int
Height int
// Title is an optional cast title.
Title string
}
ExecOptions configures a one-shot, non-interactive command recording. Unlike RunSession, no PTY is allocated: callers force color output through environment variables (e.g. ATMOS_FORCE_COLOR/CLICOLOR_FORCE) instead.
type ExecResult ¶
type ExecResult struct {
// ExitCode is the command's exit status (0 on success).
ExitCode int
}
ExecResult reports the outcome of a recorded command.
func ExecRecord ¶
func ExecRecord(ctx context.Context, opts *ExecOptions) (*ExecResult, error)
ExecRecord runs a command and records its stdout and stderr as asciicast output events. It returns the command's exit code in ExecResult; a non-zero exit is not an error (callers decide how to treat command failures).
type Header ¶
type Header struct {
Version int `json:"version"`
Width int `json:"width,omitempty"`
Height int `json:"height,omitempty"`
Term *Term `json:"term,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Title string `json:"title,omitempty"`
Command string `json:"command,omitempty"`
Env map[string]string `json:"env,omitempty"`
}
Header is the asciicast header written as the first line of a recording. Atmos writes v3 headers, but keeps the v2 width/height fields for legacy reads.
type Options ¶
type Options struct {
Path string
BasePath string
Name string
Title string
Command []string
Width int
Height int
RecordIn bool
Explicit bool
Overwrite bool
Env map[string]string
Now func() time.Time
Executable string
OutputRate time.Duration
}
Options configures an asciicast recorder.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder writes asciicast v3 header and event records to a file.
Events stream into a temporary file next to the final path; Close commits the recording by moving the temp file into place, and Discard drops it without ever touching the final path. A failed recording therefore never replaces a previously committed cast.
func (*Recorder) Close ¶
Close commits the recording: it flushes and closes the temp cast file and moves it into place at the final path. After a Discard it is a no-op.
func (*Recorder) Discard ¶
Discard closes the recording and removes the temp cast file without ever touching the final path. It is safe on an already-closed recorder.
func (*Recorder) Record ¶
Record writes stream content as an asciicast event, applying input-recording rules.
func (*Recorder) ValidateBeforeCommit ¶
ValidateBeforeCommit checks a flushed temporary recording and commits only on success.
func (*Recorder) WithPlaybackDuration ¶
WithPlaybackDuration scales all recorded events produced by run into duration. Live output is unchanged. Groups cannot overlap or nest; only the active group's events are buffered, and subsequent recording resumes at its new end time.
type RenderOptions ¶
type RenderOptions struct {
GIF string
MP4 string
HTML string
ASCII string
PNG string
JPEG string
// Overwrite replaces existing output files instead of failing with ErrRenderOutputExists.
Overwrite bool
// OverwriteFormats permits replacement only for the named formats (gif, mp4, html, ascii, png, jpeg).
OverwriteFormats map[string]bool
}
RenderOptions selects the render outputs to generate from a cast file.
type SessionAction ¶
type SessionAction struct {
Type string
Text string
Regex string
Key string
Duration string
Timeout string
Rate string
Interval string
Repeat int
Path string // Output path for a "screenshot" action.
Actions []SessionAction
// Fn runs a caller-supplied action (Type == "simulate") in place, letting
// a session mix in the same styled, non-interactive narration steps
// mode: steps uses (see pkg/runner/step's simulate rendering) instead of
// typing raw, unstyled keystrokes for comment/narration lines. asciicast
// deliberately has no styling logic of its own; the caller renders and
// writes the styled bytes itself, and this callback is how a session
// action list carries that back out to it in order.
Fn func() error
}
SessionAction describes one scripted action to perform in an interactive cast session.
type SessionOptions ¶
type SessionOptions struct {
Shell string
// ShellInit selects how the session shell initializes: "clean" (default; skip the
// user's rc/profile files), "user" (the shell's normal interactive startup files), or a
// path to an rc file the shell sources instead of the user's files.
ShellInit string
Dir string
Env map[string]string
Width int
Height int
WriteRate time.Duration
KeyInterval time.Duration
Actions []SessionAction
Recorder *Recorder
// BeforeActions can wait for externally observed shell readiness before action deadlines start.
// Its predicate reports whether captured output contains text without consuming it.
// It must return on context cancellation; a failure stops and reaps the shell.
BeforeActions func(context.Context, func(string) bool) error
// ScopedWaits consumes matched output between waits for declarative recordings.
ScopedWaits bool
// Observe runs after an action and its output have reached the recorder. It runs
// with the session output lock held, so PTY output that arrives meanwhile is
// recorded after anything Observe records (such as a checkpoint marker) rather
// than inside the span a scoped wait just consumed. Observe must therefore be
// quick and must not wait for session output or call back into the session.
Observe func(int, *SessionAction) error
}
SessionOptions configures a scripted shell session used to generate cast output.
type Tape ¶
type Tape struct {
Directives []TapeDirective
}
Tape is a fully parsed (and Source-inlined) VHS-dialect script.
func ParseTape ¶
func ParseTape(source, file, baseDir string, fr TapeFileReader) (*Tape, error)
ParseTape lexes and parses source as a VHS-dialect tape and recursively inlines any Source directives, resolving relative Source paths against baseDir (the directory of the file source came from, or the caller's chosen base directory for an inline tape with no originating file). The file parameter is used purely for error messages and is not read from disk; pass "" for an inline tape block.
func ParseTapeFile ¶
func ParseTapeFile(path, baseDir string, fr TapeFileReader) (*Tape, error)
ParseTapeFile reads path from disk via fr and parses it as a VHS-dialect tape. Source directives (at any nesting depth) resolve relative to baseDir, matching real VHS: `vhs script.tape` resolves every Source in the script relative to vhs's own invocation CWD, not relative to whichever file a nested Source happened to be read from -- see ParseTape.
type TapeDirective ¶
type TapeDirective struct {
Kind TapeDirectiveKind
File string // Originating file path; "" for an inline tape with no Source ancestry.
Line int // 1-based line number where the directive starts, for error messages.
Key string // Set key name, keypress name (enter/down/ctrl+c/...), or Env variable name.
Value string // Set value / Type text / Output|Source|Require|Screenshot path / Env value / Copy text.
Duration string // Sleep duration.
Repeat int // Keypress repeat count; 0 means "once" (not repeated).
Regex string // Wait regex pattern, without the surrounding slashes.
Speed string // VHS "@<duration>" modifier on Type (per-character typing delay) or a keypress (delay between repeats); "" when absent.
Timeout string // VHS "@<duration>" modifier on Wait/Wait+Screen/Wait+Line (per-Wait timeout); "" when absent.
}
TapeDirective is one parsed VHS-dialect directive. Not every field is used by every Kind; see the parser's consume* functions for which fields a given Kind populates.
type TapeDirectiveKind ¶
type TapeDirectiveKind int
TapeDirectiveKind identifies one recognized VHS-dialect directive kind.
const ( TapeSet TapeDirectiveKind = iota TapeOutput TapeRequire TapeSource TapeHide TapeShow TapeType TapeSleep TapeKey TapeWait TapeScreenshot TapeCopy TapePaste TapeEnv )
Recognized tape directive kinds. Wait+Screen and Wait+Line are parsed but intentionally not distinguished from a bare Wait at the AST level: Atmos's session engine polls a captured output buffer rather than literally emulating VHS's per-frame screen capture, so all three resolve to the same runtime behavior; the distinction only matters as authoring guidance (see the atmos-vhs skill's "Wait vs Wait+Screen" section).
type TapeError ¶
TapeError carries file/line context for a tape parse or Source-resolution failure, so a reported error always names the offending directive.
type TapeFileReader ¶
TapeFileReader resolves and reads a tape file referenced by a Source directive. Production callers use an adapter over pkg/filesystem.FileSystem; tests inject an in-memory fake.