cast

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package cast contains the essential structures for dealing with an asciinema cast of the v2 format.

The current implementation is based on the V2 format as of July 2nd, 2018.

From 1, asciicast v2 file is a newline-delimited JSON file where:

  • first line contains header (initial terminal size, timestamp and other meta-data), encoded as JSON object; and
  • all following lines form an event stream, each line representing a separate event, encoded as 3-element JSON array.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(writer io.Writer, cast *Cast) (err error)

Encode writes the encoding of `Cast` into the writer passed as an argument.

ps.: this method **will not** validate whether the cast is a valid V2 cast or not. Make sure you call `Validate` before.

func Validate

func Validate(cast *Cast) (isValid bool, err error)

Validate makes sure that the supplied cast is valid.

func ValidateEvent

func ValidateEvent(event *Event) (isValid bool, err error)

ValidateEvent checks whether the provided `Event` is properly formed.

func ValidateEventStream

func ValidateEventStream(eventStream []*Event) (isValid bool, err error)

ValidateEventStream makes sure that a given set of events (event stream) is valid.

A valid stream must: - be ordered by time; and - have valid events.

func ValidateHeader

func ValidateHeader(header *Header) (isValid bool, err error)

ValidateHeader verifies whether the provided `cast` header structure is valid or not based on the asciinema cast v2 protocol.

Types

type Cast

type Cast struct {
	// Header presents the recording metadata.
	Header Header

	// EventStream contains all the events that were generated during
	// the recording.
	EventStream []*Event
}

Cast represents the whole asciinema session.

func Decode

func Decode(reader io.Reader) (cast *Cast, err error)

Decode reads the whole contents of the reader passed as argument, validates whether the stream contains a valid asciinema cast and then unmarshals it into a cast struct.

type Event

type Event struct {
	// Time indicates when this event happened, represented as the number
	// of seconds since the beginning of the recording session.
	Time float64

	// Type represents the type of the data that's been recorded.
	//
	// Two types are possible:
	// - "o": data written to stdout; and
	// - "i": data read from stdin.
	Type string

	// Data represents the data recorded from the terminal.
	Data string
}

Event represents terminal inputs that get recorded by asciinema.

type Header struct {
	// Version represents the version of the current ascii cast format
	// (must be `2`).
	//
	// This field is required for a valid header.
	Version uint8 `json:"version"`

	// With is the initial terminal width (number of columns).
	//
	// This field is required for a valid header.
	Width uint `json:"width"`

	// Height is the initial terminal height (number of rows).
	//
	// This field is required for a valid header.
	Height uint `json:"height"`

	// Timestamp is the unix timestamp of the beginning of the
	// recording session.
	Timestamp uint `json:"timestamp,omitempty"`

	// Command corresponds to the name of the command that was
	// recorded.
	Command []string `json:"command,omitempty"`

	// Theme describes the color theme of the recorded terminal.
	Theme struct {
		// Fg corresponds to the normal text color (foreground).
		Fg string `json:"fg,omitempty"`

		// Bg corresponds to the normal background color.
		Bg string `json:"bg,omitempty"`

		// Palette specifies a list of 8 or 16 colors separated by
		// colon character to apply a theme to the session
		Palette string `json:"palette,omitempty"`
	} `json:"theme,omitempty"`

	// Title corresponds to the title of the cast.
	Title string `json:"title,omitempty"`

	// IdleTimeLimit specifies the maximum amount of idleness between
	// one command and another.
	IdleTimeLimit float64 `json:"idle_time_limit,omitempty"`

	// Env specifies a map of environment variables captured by the
	// asciinema command.
	//
	// ps.: the official asciinema client only captures `SHELL` and `TERM`.
	Env map[string]string `json:"env,omitempty"`
}

Header represents the asciicast header - a JSON-encoded object containing recording meta-data.

Jump to

Keyboard shortcuts

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