ttyrec

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2019 License: MIT Imports: 5 Imported by: 1

README

ttyrec

Go implementation of ttyrec (a tty recorder), including frame seeking and streaming

Documentation

Overview

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

Functions

This section is empty.

Types

type Decoder

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

Decoder for TTY recordings.

The decoder methods are not concurrency safe.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder for the provided Reader.

Example
package main

import (
	"os"
	"time"

	"maze.io/x/ttyrec"
)

func main() {
	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
	}
}
Output:

func (*Decoder) DecodeFrame

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

DecodeFrame decodes a single frame.

func (*Decoder) DecodeStream

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

DecodeStream returns a stream of frames.

func (*Decoder) Frame

func (d *Decoder) Frame() int

Frame returns the current frame number.

func (*Decoder) SeekToFrame

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

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

Encoder can write chunks of bytes in a ttyrec format.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder
Example
package main

import (
	"io"
	"os"

	"maze.io/x/ttyrec"
)

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

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

func (*Encoder) Write

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

type Frame

type Frame struct {
	Header
	Data []byte
}

Frame for a recording.

type Header struct {
	Time TimeVal
	Len  uint32
}

Header for a Frame.

func (*Header) ReadFrom

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

ReadFrom reads the header values from the provided Reader.

func (*Header) WriteTo

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

WriteTo writes the header values to the provided Writer.

type StopFunc

type StopFunc func()

StopFunc is used to interrupt a stream.

type TimeVal

type TimeVal struct {
	Seconds      int32
	MicroSeconds int32
}

TimeVal is a struct timeval.

func (*TimeVal) Set

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

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

func (TimeVal) Sub

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

Sub subtracts x from t, returning the difference.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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