Documentation
¶
Index ¶
Constants ¶
const FormatVersion = 2
Variables ¶
var ( ErrUnexpectedVersion = fmt.Errorf("unexpected asciicast version") ErrSmallTerminal = fmt.Errorf("terminal too small for frames") )
var ErrNotTerminal = fmt.Errorf("stdin is not terminal")
Functions ¶
This section is empty.
Types ¶
type Frame ¶
type Frame struct { // Time in seconds since record start. Time float64 // Type of frame. Type FrameType // Data contains frame data. Data []byte }
Frame represents asciinema-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) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type FrameSource ¶
type FrameSource interface { // Header returns asciinema-v2 header. Header() Header // Next advances to next available frame. It must return false if error occurs or there is no more frames. Next() bool // Frame returns current frame. It becomes unusable after Next call. Frame() Frame // Err returns error if it happens during iteration. Err() error }
FrameSource describes frames source.
type FrameUnmarshalError ¶
FrameUnmarshalError returned if frame conversion to struct failed.
func (*FrameUnmarshalError) Error ¶
func (e *FrameUnmarshalError) Error() string
type Header ¶
type Header struct { // Version is a format version. Must be 2. Version int `json:"version"` // With is a captured terminal width. Width int `json:"width"` // Height is a captured terminal height. Height int `json:"height"` }
Header represents asciinema-v2 header (first line). It doesn't include unneeded fields.
type OSTerminal ¶
type OSTerminal struct {
// contains filtered or unexported fields
}
OSTerminal represents terminal on operating system.
func NewOSTerminal ¶
func NewOSTerminal() (*OSTerminal, error)
NewOSTerminal constructs OSTerminal from stdin. It returns ErrNotTerminal if stdin is not terminal.
func NewOSTerminalFromFile ¶
func NewOSTerminalFromFile(file *os.File) (*OSTerminal, error)
NewOSTerminalFromFile constructs OSTerminal from file. It returns ErrNotTerminal if file is not terminal.
func (*OSTerminal) Close ¶
func (t *OSTerminal) Close() error
Close closes terminal (stop control loop). It doesn't close underlying file.
func (*OSTerminal) Control ¶
func (t *OSTerminal) Control(control PlaybackControl)
func (*OSTerminal) Dimensions ¶
func (t *OSTerminal) Dimensions() (width, height int)
func (*OSTerminal) Restore ¶
func (t *OSTerminal) Restore() error
func (*OSTerminal) ToRaw ¶
func (t *OSTerminal) ToRaw() error
type Option ¶
type Option func(*options)
Option for Player.
func WithIgnoreSizeCheck ¶
func WithIgnoreSizeCheck() Option
WithIgnoreSizeCheck turns off check that terminal can fit frames.
func WithMaxWait ¶
WithMaxWait sets minimal delay between frames. Zero or negative value are ignored.
type PlaybackControl ¶
type PlaybackControl interface { // Pause pauses playback. If playback already paused it will continue. Pause() // Stop interrupts playback. Must be called once. Stop() // contains filtered or unexported methods }
PlaybackControl describes playback control methods for Terminal.
type Player ¶
type Player struct {
// contains filtered or unexported fields
}
func NewPlayer ¶
func NewPlayer(frameSource FrameSource, terminal Terminal, opts ...Option) (*Player, error)
func (*Player) Pause ¶
func (p *Player) Pause()
Pause pauses playback. If playback already paused it will continue.
type StreamFrameSource ¶
type StreamFrameSource struct {
// contains filtered or unexported fields
}
StreamFrameSource reads frames from io.Reader.
func NewStreamFrameSource ¶
func NewStreamFrameSource(reader io.Reader) (*StreamFrameSource, error)
NewStreamFrameSource constructs StreamFrameSource. It reads Header from input stream.
func (*StreamFrameSource) Err ¶
func (s *StreamFrameSource) Err() error
Err returns error if it happens during iteration.
func (*StreamFrameSource) Frame ¶
func (s *StreamFrameSource) Frame() Frame
Frame returns current frame. It becomes unusable after Next call.
func (*StreamFrameSource) Header ¶
func (s *StreamFrameSource) Header() Header
Header returns asciinema-v2 header.
func (*StreamFrameSource) Next ¶
func (s *StreamFrameSource) Next() bool
Next advances to next available frame. It must return false if error occurs or there is no more frames.
type Terminal ¶
type Terminal interface { io.WriteCloser // Dimensions returns terminal window size. Dimensions() (width, height int) // ToRaw puts terminal to raw mode. Implementation must store previous terminal state. ToRaw() error // Restore puts terminal into state stored in ToRaw. Restore() error // Control starts "event loop" where Terminal may call methods of PlaybackControl. Method blocks until Close. Control(PlaybackControl) }
Terminal is interface for terminal interaction.