asciicast

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOutputFrame

func IsOutputFrame(frame *Frame) bool

IsOutputFrame determines that given frame is output type.

Types

type Asciicast

type Asciicast struct {
	Header Header
	Frames Frames
}

Asciicast represents asciicast v2 file. First line of file is Header JSON-object. It consists meta information: version, environment variables, terminal size, etc. Next lines is JSON-arrays (one per line) with frame delay, frame type and frame data (escaped string).

type Frame

type Frame struct {
	Time float64
	Type FrameType
	Data []byte
}

Frame represents asciicast v2 frame. This is JSON-array with fixed size of 3 elements: [0]: frame delay in seconds (float64), [1]: frame type, [2]: frame data (escaped string).

func (*Frame) Duration

func (f *Frame) Duration() time.Duration

Duration returns frame duration converted to time.Duration

func (*Frame) UnmarshalJSON

func (f *Frame) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler

type FrameType

type FrameType string

FrameType is a type of frame. Currently it is only input ("i") frames and output ("o") frames.

const (
	InputFrame  FrameType = "i"
	OutputFrame FrameType = "o"
)

type Frames

type Frames []Frame

Frames is a list of frame with additional functions.

func (Frames) AdjustSpeed

func (f Frames) AdjustSpeed(speed float64) Frames

AdjustSpeed allows to change time delay between. Speed value must be positive. If speed > 1 delay will be increased. If speed < 1 delay will be decreased.

func (Frames) CapRelativeTime

func (f Frames) CapRelativeTime(timeLimit float64) Frames

CapRelativeTime sets minimal delay for frames. Frame time must be relative.

func (Frames) Filter

func (f Frames) Filter(p func(frame *Frame) bool) Frames

Filter returns frame list with frames which satisfies given predicate.

func (Frames) ToAbsoluteTime

func (f Frames) ToAbsoluteTime() Frames

ToAbsoluteTime converts frame time to absolute values.

func (Frames) ToRelativeTime

func (f Frames) ToRelativeTime() Frames

ToRelativeTime converts frame time to relative values.

type Header struct {
	Env           map[string]string `json:"env"`
	Width         uint              `json:"width"`
	Height        uint              `json:"height"`
	Timestamp     uint64            `json:"timestamp"` // unix time
	Version       uint              `json:"version"`
	IdleTimeLimit float64           `json:"idle_time_limit"`
}

Header represents asciinema v2 file header

type Player

type Player interface {
	Play(asciicast *Asciicast, maxWait, speed float64) error
}

Player is an interface for playing asciicasts.

type TerminalPlayer

type TerminalPlayer struct {
	Terminal terminal.Terminal
}

TerminalPlayer is a asciicast to terminal player.

func NewTerminalPlayer

func NewTerminalPlayer() (TerminalPlayer, error)

NewTerminalPlayer initializes terminal and creates terminal asciicasts player.

func (*TerminalPlayer) Play

func (p *TerminalPlayer) Play(asciicast *Asciicast, maxWait time.Duration, speed float64) error

Play plays provided asciicast. On *nix systems it firstly puts terminal to raw mode (will be restored after finish). Playing is actually putting frame data to terminal without escaping. Player can be interrupted by hitting Ctrl-C. Player can be paused and unpaused by hitting space key. If player paused you can switch to next frame by pressing tab key.

Jump to

Keyboard shortcuts

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