capture

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-3-Clause Imports: 14 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 capture plays a scripted scenario against a painter-drawn scene and records every step as a frame of one animated, resolution-independent SVG (and, through the player page or the capture/webm subpackage, as an HTML page or a video of the same frames). It is the harness behind "agentscope capture": the scene and its steps are the caller's, the recording, the glyph outlines, the output formats and the safe file writing are here.

A capture is deterministic: the same scene and steps give the same bytes on every machine, whatever its time zone (see Options.Zone). This package pulls in no video encoder; capture/webm holds that.

Index

Constants

View Source
const (
	MinSize = 320
	MaxSize = 4096
)

Size bounds: a capture is a picture of a window, not an allocation attack.

View Source
const (
	FormatSVG  = "svg"
	FormatWebM = "webm"
	FormatHTML = "html"
)

Format names.

View Source
const DefaultSize = "1280x720"

DefaultSize is the captured window, in logical pixels, when none is given.

Variables

This section is empty.

Functions

func DefaultOutDir

func DefaultOutDir(app string) (string, error)

DefaultOutDir is the durable directory captures of app go to: under the user's config directory, never inside a repository.

func HTML

func HTML(r *Result, title, lang string) ([]byte, error)

HTML wraps a recording in the self-contained player page of this module: the same SVG, inlined, with play/pause, a seek bar and the keyboard controls. lang is the page chrome's language ("en" or "fr").

func InsideGitTree

func InsideGitTree(p string) (bool, error)

InsideGitTree reports whether p, or a directory above it, holds a .git.

func ParseSize

func ParseSize(s string) (w, h int, err error)

ParseSize reads "WIDTHxHEIGHT" within [MinSize, MaxSize].

func RefuseGitTree

func RefuseGitTree(out string) error

RefuseGitTree is the guard every writer shares: it refuses a path inside a git work tree, and a path it cannot place. A caller runs it before an expensive render, so the refusal costs nothing.

func ResolveFormat

func ResolveFormat(format, out string) (string, error)

ResolveFormat settles the output format from --format and the --out path. An empty format is inferred from the extension (.svg, .webm or .html) and is svg when the path has neither; a named format must not contradict a known extension.

func Size

func Size(w, h int) (int, int, error)

Size settles a window: both zero is DefaultSize, and each side must be within MinSize to MaxSize.

func WriteFile

func WriteFile(out string, data []byte) error

WriteFile writes data to out, refusing a path inside a git work tree. The directory is created when missing.

Types

type Options

type Options struct {
	// W and H are the window, in logical pixels, each MinSize to MaxSize. Both
	// zero means DefaultSize.
	W, H int
	// Title is the document's <title>.
	Title string
	// Zone is the location the process-wide time.Local is pinned to while the
	// steps run and the scene is drawn: a scene that writes times with
	// time.Local (or a library that does) then gives the same bytes on every
	// machine. nil means UTC. A live window never goes through Run and keeps
	// its own zone.
	Zone *time.Location
}

Options tune Run. The zero value is DefaultSize in UTC with no title.

type Result

type Result struct {
	SVG      []byte
	Frames   int           // frames recorded, one per step
	Duration time.Duration // the loop length
	Stats    svg.Stats     // the assembly: slots, pictures, shared subtrees, sizes
	Raster   int           // elements that embed a PNG; 0 means fully vector
	Doc      *svg.Document // the assembly, whose Frame(i) is the still of slot i
	Texts    []string      // every distinct string drawn: the outlines hide them from a text scan
	Observed []int         // what Run's observe returned after each step; nil without one
}

Result is one recorded scenario.

func Run

func Run[E any](setup func() (Scene, E), steps []Step[E], o Options, observe func(E) int) (*Result, error)

Run plays steps against the scene and state that setup returns: each step's Do runs, the scene is recorded as one frame with its text as glyph outlines, and the frame is held for the step's Hold. The frames are assembled into one animated SVG. o.W and o.H, settled by Size, are the window the scene must be built at. setup is called once, after the zone is pinned and the size validated, so a scene that reads time.Local while it is built is as reproducible as one that reads it while it draws. observe, when non-nil, is called after each Do and its value kept in Result.Observed (a language selector, a page number: whatever a caller wants to know about each frame). Run reads no clock, file or network.

type Scene

type Scene interface {
	DrawTo(p painter.Painter)
}

Scene is what a capture draws: a window that can paint itself, at its current state, onto any painter. The recorder it is handed also implements painter.FacePainter, so a scene that draws text through a face gets outlines.

type Step

type Step[E any] struct {
	Hold time.Duration
	Do   func(E)
}

Step is one beat of a scenario: Do changes the state E the scene shows, then the scene is recorded and held for Hold.

Directories

Path Synopsis
Package webm encodes a capture.Result as a VP8 WebM video of the same frames.
Package webm encodes a capture.Result as a VP8 WebM video of the same frames.

Jump to

Keyboard shortcuts

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