ttyrec: maze.io/x/ttyrec Index | Examples | Files

package ttyrec

import "maze.io/x/ttyrec"

Package ttyrec implements TTY recording, compatible with ttyrec(1)

Acknowledgements

This is an implementation of the original ttyrec(1) specification by Satoru Takabayashi, http://0xcc.net/ttyrec/

Index

Examples

Package Files

doc.go reader.go ttyrec.go writer.go

Variables

var ErrIllegalSeek = errors.New("ttyrec: seek to an invalid offset")

ErrIllegalSeek is returned if an illegal seek operation is requested, such as seeking to an out of bounds frame.

var ErrReadSeeker = errors.New("ttyrec: provided Reader does not implement io.ReadSeeker")

ErrReadSeeker is returned if the provided Reader does not provide the io.ReadSeeker interface.

type Decoder Uses

type Decoder struct {
    // contains filtered or unexported fields
}

Decoder for TTY recordings.

The decoder methods are not concurrency safe.

func NewDecoder Uses

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder for the provided Reader.

Code:

f, err := os.Open("ttyrecord")
if err != nil {
    panic(err)
}
defer f.Close()

d := ttyrec.NewDecoder(f)
stream, _ := d.DecodeStream()

var previous *ttyrec.Frame
for frame := range stream {
    if previous != nil {
        time.Sleep(frame.Time.Sub(previous.Time))
    }
    os.Stdout.Write(frame.Data)
    previous = frame
}

func (*Decoder) DecodeFrame Uses

func (d *Decoder) DecodeFrame() (*Frame, error)

DecodeFrame decodes a single frame.

func (*Decoder) DecodeStream Uses

func (d *Decoder) DecodeStream() (<-chan *Frame, StopFunc)

DecodeStream returns a stream of frames.

func (*Decoder) Frame Uses

func (d *Decoder) Frame() int

Frame returns the current frame number.

func (*Decoder) SeekToFrame Uses

func (d *Decoder) SeekToFrame(offset, whence int) error

SeekToFrame seeks to the specified frame offset. Whence can be any of the io.SeekStart (relative to first frame) or io.SeekCurrent (relative to current frame). io.SeekEnd is not supported.

type Encoder Uses

type Encoder struct {
    // contains filtered or unexported fields
}

Encoder can write chunks of bytes in a ttyrec format.

func NewEncoder Uses

func NewEncoder(w io.Writer) *Encoder

Code:

f, err := os.Create("ttyrecord")
if err != nil {
    panic(err)
}
defer f.Close()

e := ttyrec.NewEncoder(f)
io.Copy(e, os.Stdout)

func (*Encoder) Write Uses

func (e *Encoder) Write(p []byte) (int, error)

type Frame Uses

type Frame struct {
    Header
    Data []byte
}

Frame for a recording.

type Header struct {
    Time TimeVal
    Len  uint32
}

Header for a Frame.

func (*Header) ReadFrom Uses

func (h *Header) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads the header values from the provided Reader.

func (*Header) WriteTo Uses

func (h *Header) WriteTo(w io.Writer) (int64, error)

WriteTo writes the header values to the provided Writer.

type StopFunc Uses

type StopFunc func()

StopFunc is used to interrupt a stream.

type TimeVal Uses

type TimeVal struct {
    Seconds      int32
    MicroSeconds int32
}

TimeVal is a struct timeval.

func (*TimeVal) Set Uses

func (t *TimeVal) Set(d time.Duration)

Set the values based on the provided duration. Negative durations are ignored.

func (TimeVal) Sub Uses

func (t TimeVal) Sub(x TimeVal) time.Duration

Sub subtracts x from t, returning the difference.

Package ttyrec imports 5 packages (graph). Updated 2019-09-02. Refresh now. Tools for package owners.