stream

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: BSD-3-Clause Imports: 20 Imported by: 1

README

stream

demo

tty(TtyStreams) -->   pty(PtyStreams)
In(Reader)      -->   In(Writer)
Out(Writer)     <--   Out(Reader)
In(Writer)      <--   ErrOut(Reader)

Documentation

Overview

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

from github.com/yubo/gotty/rec

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Copyright 2021 yubo. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	MsgInput     byte = '0' + iota // User input typically from a keyboard
	MsgOutput                      // Normal output to the terminal
	MsgErrOutput                   // Normal output to the terminal
	MsgResize                      // Notify that the browser size has been changed
	MsgPing
	MsgCtl
	MsgInfo
	MsgAction // custom Action
)
View Source
const (
	SampleTime = time.Second / 100 // 100Hz
)

Variables

View Source
var (
	MagicCode = []byte{0xff, 0xf1, 0xf2, 0xf3}
)

Functions

func CopyPtyStreams

func CopyPtyStreams(tty TtyStreams, pty PtyStreams) chan error

func CopyToPty

func CopyToPty(tty Tty, pty Pty) <-chan error

func EnvsToKv

func EnvsToKv(envs []string) map[string]string

func Nanotime

func Nanotime() int64

func NewEscapeProxy

func NewEscapeProxy(reader io.Reader, keys []byte) io.Reader

Types

type CloseFunc

type CloseFunc func() (err error)

func (CloseFunc) Close

func (f CloseFunc) Close() error

type CmdPty

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

func NewCmdPty

func NewCmdPty(cmd *exec.Cmd) (*CmdPty, error)

func (*CmdPty) Close

func (p *CmdPty) Close() error

func (*CmdPty) IsTerminal

func (p *CmdPty) IsTerminal() bool

func (*CmdPty) Resize

func (p *CmdPty) Resize(size *term.TerminalSize) error

func (*CmdPty) Streams

func (p *CmdPty) Streams() PtyStreams

type CtlMsg

type CtlMsg struct {
	Type    string `json:"type"`
	Payload string `json:"payload"`
}

type Exec

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

func NewExec

func NewExec(cmd *exec.Cmd) (*Exec, error)

func (*Exec) Getsize

func (p *Exec) Getsize() (int, int, error)

func (*Exec) IsTerminal

func (p *Exec) IsTerminal() bool

func (*Exec) PtyStreams

func (p *Exec) PtyStreams() PtyStreams

func (*Exec) Resize

func (p *Exec) Resize(height, width uint16) error

type NativeTty

type NativeTty struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewNativeTty

func NewNativeTty(in io.Reader, out, errOut io.Writer) (*NativeTty, error)

func (*NativeTty) Close

func (p *NativeTty) Close() error

func (*NativeTty) CopyToPty

func (p *NativeTty) CopyToPty(pty Pty) <-chan error

func (*NativeTty) Done

func (p *NativeTty) Done() <-chan struct{}

func (*NativeTty) Err

func (p *NativeTty) Err() error

func (*NativeTty) GetSize

func (p *NativeTty) GetSize() *term.TerminalSize

func (*NativeTty) IsTerminal

func (p *NativeTty) IsTerminal() bool

func (*NativeTty) MonitorSize

func (p *NativeTty) MonitorSize(size ...*term.TerminalSize) term.TerminalSizeQueue

func (*NativeTty) Safe

func (p *NativeTty) Safe(fn term.SafeFunc) error

func (*NativeTty) SetupTTY

func (p *NativeTty) SetupTTY() *term.TTY

func (*NativeTty) Streams

func (p *NativeTty) Streams() TtyStreams

type Opt

type Opt func(*Options)

func WithDetach

func WithDetach(detach bool, detachKeys string) Opt

type Options

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

type Player

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

func NewPlayer

func NewPlayer(fileName string, speed int64, repeat bool, wait time.Duration) (*Player, error)

func (*Player) Close

func (p *Player) Close() error

func (*Player) IsTerminal

func (p *Player) IsTerminal() bool

canot support resize method

func (*Player) Resize

func (p *Player) Resize(*term.TerminalSize) error

func (*Player) Streams

func (p *Player) Streams() PtyStreams

type PlayerStreams

type PlayerStreams struct {
	Stdin  io.ReadWriter // read ctl
	Stdout io.Writer
	Stderr io.Writer
}

type ProxyTty

type ProxyTty struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewProxyTty

func NewProxyTty(parent context.Context, bsize int) *ProxyTty

func (*ProxyTty) AddRecorder

func (p *ProxyTty) AddRecorder(r Recorder) error

func (*ProxyTty) AddTty

func (p *ProxyTty) AddTty(tty Tty, opts ...Opt) error

tty will be closed by proxyTty, when proxyTty at closed

func (*ProxyTty) Close

func (p *ProxyTty) Close() error

func (*ProxyTty) CopyToPty

func (p *ProxyTty) CopyToPty(pty Pty) <-chan error

func (*ProxyTty) Done

func (p *ProxyTty) Done() <-chan struct{}

func (*ProxyTty) Err

func (p *ProxyTty) Err() error

func (*ProxyTty) GetSize

func (t *ProxyTty) GetSize() *term.TerminalSize

func (*ProxyTty) IsTerminal

func (p *ProxyTty) IsTerminal() bool

func (*ProxyTty) MonitorSize

func (p *ProxyTty) MonitorSize(initialSizes ...*term.TerminalSize) term.TerminalSizeQueue

func (*ProxyTty) Next

func (p *ProxyTty) Next() *term.TerminalSize

func (*ProxyTty) Streams

func (p *ProxyTty) Streams() TtyStreams

type Pty

type Pty interface {
	Streams() PtyStreams
	IsTerminal() bool
	Resize(*term.TerminalSize) error
	Close() error
}

type PtyStreams

type PtyStreams struct {
	Stdin  io.Writer // /dev/ptmx
	Stdout io.Reader // /dev/ptmx
	Stderr io.Reader // /dev/ptmx
}

type ReadFunc

type ReadFunc func(p []byte) (n int, err error)

func (ReadFunc) Read

func (f ReadFunc) Read(p []byte) (int, error)

type RecData

type RecData struct {
	Time int64
	Data []byte
}

type Recorder

type Recorder interface {
	Close() error
	Streams() RecorderStreams
	Resize(size *term.TerminalSize) error
	Info(info []byte) error
}

func NewRecorder

func NewRecorder(out io.WriteCloser) (Recorder, error)

type RecorderFactory

type RecorderFactory func(out io.WriteCloser) (Recorder, error)

type RecorderStreams

type RecorderStreams struct {
	Stdin  io.Writer
	Stdout io.Writer
	Stderr io.Writer
}

type StreamTty

type StreamTty struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewStreamTty

func NewStreamTty(ctx context.Context, in io.Reader, out, errOut io.WriteCloser, isTty bool, resize <-chan term.TerminalSize) *StreamTty

func (*StreamTty) Close

func (p *StreamTty) Close() error

func (*StreamTty) CopyToPty

func (p *StreamTty) CopyToPty(pty Pty) <-chan error

func (*StreamTty) Done

func (p *StreamTty) Done() <-chan struct{}

func (*StreamTty) Err

func (p *StreamTty) Err() error

func (*StreamTty) GetSize

func (p *StreamTty) GetSize() *term.TerminalSize

func (*StreamTty) IsTerminal

func (p *StreamTty) IsTerminal() bool

func (*StreamTty) MonitorSize

func (p *StreamTty) MonitorSize(initialSizes ...*term.TerminalSize) term.TerminalSizeQueue

func (*StreamTty) Next

func (p *StreamTty) Next() *term.TerminalSize

func (*StreamTty) Streams

func (p *StreamTty) Streams() TtyStreams

type Tty

type Tty interface {
	Streams() TtyStreams
	IsTerminal() bool
	GetSize() *term.TerminalSize
	MonitorSize(...*term.TerminalSize) term.TerminalSizeQueue
	CopyToPty(pty Pty) <-chan error
	Done() <-chan struct{}
	Err() error
	Close() error
}

type TtyStreams

type TtyStreams struct {
	Stdin  io.Reader // os.Stdin
	Stdout io.Writer // os.Stdout
	Stderr io.Writer // os.Stderr
}

TtyStreams provides the standard names for iostreams. This is useful for embedding and for unit testing. Inconsistent and different names make it hard to read and review code

type WriteFunc

type WriteFunc func(p []byte) (n int, err error)

func (WriteFunc) Write

func (f WriteFunc) Write(p []byte) (int, error)

Directories

Path Synopsis
convert stream rec format to github.com/asciinema/asciinema format from github.com/yubo/gotty/rec
convert stream rec format to github.com/asciinema/asciinema format from github.com/yubo/gotty/rec
example

Jump to

Keyboard shortcuts

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