package tty ¶
import "golazy.dev/lazytui/encoding/tty"
Variables ¶
var ErrInvalidSize, ErrNilBackend, ErrNilTransport, ErrUnknownState, ErrUnsupported ¶
var (
ErrInvalidSize = errors.New("invalid terminal size")
ErrNilBackend = errors.New("nil tty backend")
ErrNilTransport = errors.New("nil tty transport")
ErrUnknownState = errors.New("unknown terminal state")
ErrUnsupported = errors.New("terminal operation unsupported")
)
Types ¶
type Backend ¶
Backend applies terminal operations to an implementation such as a real TTY, a ConPTY object, or a test fake.
type Backend interface {
IsTerminal() bool
Size() (Size, error)
Resize(Size) error
MakeRaw() (*State, error)
Restore(*State) error
}
type Client ¶
Client sends terminal-control requests to a server.
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(transport Transport) (*Client, error)
func (c *Client) IsTerminal ¶
func (c *Client) IsTerminal(ctx context.Context) (bool, error)
func (c *Client) MakeRaw ¶
func (c *Client) MakeRaw(ctx context.Context) (StateID, error)
func (c *Client) Resize ¶
func (c *Client) Resize(ctx context.Context, size Size) error
func (c *Client) Restore ¶
func (c *Client) Restore(ctx context.Context, state StateID) error
func (c *Client) Size ¶
func (c *Client) Size(ctx context.Context) (Size, error)
type Decoder ¶
Decoder reads newline-delimited request/response messages.
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoder(r io.Reader) *Decoder
func (d *Decoder) DecodeRequest ¶
func (d *Decoder) DecodeRequest() (Request, error)
func (d *Decoder) DecodeResponse ¶
func (d *Decoder) DecodeResponse() (Response, error)
type Device ¶
Device is the local handle for terminal-control operations.
type Device struct {
// contains filtered or unexported fields
}
func NewDevice ¶
NewDevice wraps backend in a Device.
func NewDevice(backend Backend) (*Device, error)
func Open ¶
Open wraps a real OS terminal file.
func Open(file *os.File) (*Device, error)
func (d *Device) IsTerminal ¶
IsTerminal reports whether the device is backed by a terminal.
func (d *Device) IsTerminal() bool
func (d *Device) MakeRaw ¶
MakeRaw puts the terminal into raw mode and returns a restorable state.
func (d *Device) MakeRaw() (*State, error)
func (d *Device) Resize ¶
Resize sets the terminal size.
func (d *Device) Resize(size Size) error
func (d *Device) Restore ¶
Restore restores a previous terminal state.
func (d *Device) Restore(state *State) error
func (d *Device) Size ¶
Size returns the current terminal size.
func (d *Device) Size() (Size, error)
type Encoder ¶
Encoder writes newline-delimited request/response messages.
type Encoder struct {
// contains filtered or unexported fields
}
func NewEncoder ¶
func NewEncoder(w io.Writer) *Encoder
func (e *Encoder) EncodeRequest ¶
func (e *Encoder) EncodeRequest(req Request) error
func (e *Encoder) EncodeResponse ¶
func (e *Encoder) EncodeResponse(resp Response) error
type Op ¶
Op identifies a terminal-control request.
type Op string
type Request ¶
Request is a wire-friendly terminal-control request.
type Request struct {
Op Op `json:"op"`
Size Size `json:"size,omitempty"`
State StateID `json:"state,omitempty"`
}
type Response ¶
Response is a wire-friendly terminal-control response.
type Response struct {
Size Size `json:"size,omitempty"`
State StateID `json:"state,omitempty"`
IsTerminal bool `json:"is_terminal,omitempty"`
Error string `json:"error,omitempty"`
}
type Server ¶
Server owns terminal state and applies requests from clients.
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(device *Device) (*Server, error)
func (s *Server) RoundTrip ¶
RoundTrip lets Server satisfy Transport for in-process clients and tests.
func (s *Server) RoundTrip(ctx context.Context, req Request) (Response, error)
func (s *Server) Serve ¶
Serve applies a single request.
func (s *Server) Serve(ctx context.Context, req Request) Response
type Size ¶
Size is a terminal size in character cells.
type Size struct {
Rows int `json:"rows,omitempty"`
Cols int `json:"cols,omitempty"`
}
func (s Size) String ¶
func (s Size) String() string
func (s Size) Valid ¶
Valid reports whether the size can be applied to a terminal.
func (s Size) Valid() bool
type State ¶
State contains backend-specific terminal state.
State values intentionally do not encode across the wire. A Server stores states and returns StateID tokens to clients.
type State struct {
// contains filtered or unexported fields
}
type StateID ¶
StateID is a server-local token for a saved terminal state.
type StateID string
type Transport ¶
Transport carries terminal-control requests to a server.
type Transport interface {
RoundTrip(context.Context, Request) (Response, error)
}
Package tty encodes terminal-control requests and applies them to terminal devices.
The package separates the client that asks for terminal operations from the server that owns the real terminal backend. That split lets future GoLazy processes attach to an existing terminal supervisor without sharing raw OS handles in the public API.