package tty

import "golazy.dev/lazytui/encoding/tty"

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.

Variables

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 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 Op

Op identifies a terminal-control request.

type Op string

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 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
}