kttyd

package module
v0.0.0-...-d310c9f Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 19 Imported by: 0

README

kttyd

Documentation

Index

Constants

View Source
const (
	// Unknown message type, maybe sent by a bug
	UnknownInput = '0'
	// User input typically from a keyboard
	Input = '1'
	// Ping to the server
	Ping = '2'
	// Notify that the browser size has been changed
	ResizeTerminal = '3'
	// Change encoding
	SetEncoding = '4'
)
View Source
const (
	// Unknown message type, maybe set by a bug
	UnknownOutput = '0'
	// Normal output to the terminal
	Output = '1'
	// Pong to the browser
	Pong = '2'
	// Set window title of the terminal
	SetWindowTitle = '3'
	// Set terminal preference
	SetPreferences = '4'
	// Make terminal to reconnect
	SetReconnect = '5'
	// Set the input buffer size
	SetBufferSize = '6'
)

Variables

View Source
var (
	// ErrSlaveClosed indicates the function has exited by the slave
	ErrSlaveClosed = errors.New("slave closed")

	// ErrSlaveClosed is returned when the slave connection is closed.
	ErrMasterClosed = errors.New("master closed")
)
View Source
var Protocols = []string{"webtty"}

Functions

func BasicAuthWrapper

func BasicAuthWrapper(h http.Handler, credential string) http.Handler

func CacheControlWrapper

func CacheControlWrapper(h http.Handler) http.Handler

Types

type Decoder

type Decoder interface {
	Decode(dst, src []byte) (int, error)
}

type Encoder

type Encoder interface {
	Encode(dst, src []byte) (int, error)
}

type Kttyd

type Kttyd struct {
	Port string
	Path string
	// contains filtered or unexported fields
}

func NewKttyd

func NewKttyd(bindAddress string, command string, args []string) (*Kttyd, error)

func (*Kttyd) SetBasicAuth

func (ctx *Kttyd) SetBasicAuth(auth string) *Kttyd

func (*Kttyd) SetLogger

func (ctx *Kttyd) SetLogger(errlog func(error)) *Kttyd

func (*Kttyd) SetTitle

func (ctx *Kttyd) SetTitle(title string) *Kttyd

func (*Kttyd) SetWorkdir

func (ctx *Kttyd) SetWorkdir(workdir string) *Kttyd

func (*Kttyd) Start

func (ctx *Kttyd) Start() error

func (*Kttyd) Stop

func (ctx *Kttyd) Stop()

type KttydSlave

type KttydSlave interface {
	Slave

	Close() error
}

type Master

type Master io.ReadWriter

type NullCodec

type NullCodec struct{}

func (NullCodec) Decode

func (NullCodec) Decode(dst, src []byte) (int, error)

func (NullCodec) Encode

func (NullCodec) Encode(dst, src []byte) (int, error)

type Option

type Option func(*WebTTY) error

Option is an option for WebTTY.

func WithFixedColumns

func WithFixedColumns(columns int) Option

WithFixedColumns sets a fixed width to TTY master.

func WithFixedRows

func WithFixedRows(rows int) Option

WithFixedRows sets a fixed height to TTY master.

func WithMasterPreferences

func WithMasterPreferences(preferences any) Option

WithMasterPreferences sets an optional configuration of master.

func WithPermitWrite

func WithPermitWrite() Option

WithPermitWrite sets a WebTTY to accept input from slaves.

func WithReconnect

func WithReconnect(timeInSeconds int) Option

WithReconnect enables reconnection on the master side.

func WithWindowTitle

func WithWindowTitle(windowTitle []byte) Option

WithWindowTitle sets the default window title of the session

type Slave

type Slave interface {
	io.ReadWriter

	// WindowTitleVariables returns any values that can be used to fill out
	// the title of a terminal.
	WindowTitleVariables() map[string]any

	// ResizeTerminal sets a new size of the terminal.
	ResizeTerminal(columns int, rows int) error
}

type WebTTY

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

func NewWebTTY

func NewWebTTY(masterConn Master, slave Slave, options ...Option) (*WebTTY, error)

New creates a new instance of WebTTY. masterConn is a connection to the PTY master, typically it's a websocket connection to a client. slave is a PTY slave such as a local command with a PTY.

func (*WebTTY) Run

func (wt *WebTTY) Run(ctx context.Context) error

Run starts the main process of the WebTTY. This method blocks until the context is canceled. Note that the master and slave are left intact even after the context is canceled. Closing them is caller's responsibility. If the connection to one end gets closed, returns ErrSlaveClosed or ErrMasterClosed.

type WebsockerMaster

type WebsockerMaster struct {
	*websocket.Conn
}

func (*WebsockerMaster) Read

func (ctx *WebsockerMaster) Read(p []byte) (n int, err error)

func (*WebsockerMaster) Write

func (ctx *WebsockerMaster) Write(p []byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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