mux

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdminToggleSSH   byte = 0x01
	AdminToggleRelay byte = 0x02
	AdminKick        byte = 0x03
	AdminNavUp       byte = 0x04
	AdminNavDown     byte = 0x05
	AdminToggleWeb   byte = 0x06

	// Per-session access toggles.
	AdminSessionToggleSSH   byte = 0x07
	AdminSessionToggleWeb   byte = 0x08
	AdminSessionToggleRelay byte = 0x09

	AdminToggleAPI        byte = 0x0A
	AdminSessionToggleAPI byte = 0x0B
)

Admin action types sent from client to server.

View Source
const (
	ScrollUp       byte = 0x01 // one line up
	ScrollDown     byte = 0x02 // one line down
	ScrollHalfUp   byte = 0x03 // half page up
	ScrollHalfDown byte = 0x04 // half page down
	ScrollTop      byte = 0x05 // jump to top of scrollback
	ScrollBottom   byte = 0x06 // jump to bottom (exit scroll)
)

Scroll actions sent in MsgScrollAction payloads.

Variables

This section is empty.

Functions

func DecodeAdminAction

func DecodeAdminAction(data []byte) (action byte, connID uint64)

DecodeAdminAction deserializes an admin action.

func EncodeAdminAction

func EncodeAdminAction(action byte, connID uint64) []byte

EncodeAdminAction serializes an admin action. Format: [action:1][id:8] (id only used for kick)

func EncodeAdminState

func EncodeAdminState(s *AdminState) []byte

EncodeAdminState serializes AdminState for proto transport. Format: [ssh:1][web:1][relay:1][sessSSH:1][sessWeb:1][sessRelay:1][selected:1][nconns:1]

then per conn: [id:8][srcLen:1][src][addrLen:1][addr][commentLen:1][comment][sessionLen:1][session][durLen:1][dur]

func Render

func Render(sess *Session, totalCols, totalRows int, hud *HUDInfo) []byte

Render composites the session's active window into ANSI output.

func RenderAdmin

func RenderAdmin(state *AdminState, cols, rows int) []byte

RenderAdmin draws a centered admin panel overlay.

func RenderScroll

func RenderScroll(sess *Session, totalCols, totalRows, offset int) []byte

RenderScroll composites a scrolled view of the active pane. offset is the number of lines scrolled up from the bottom.

func RenderScrollIndicator

func RenderScrollIndicator(buf []byte, offset, total, cols, rows int) []byte

RenderScrollIndicator appends a right-aligned "[scroll: LINE/TOTAL]" bar on the last row of the terminal.

func ValidateSessionName

func ValidateSessionName(name string) error

ValidateSessionName checks that a session name is non-empty, printable ASCII, and at most 64 bytes.

Types

type AdminConn

type AdminConn struct {
	ID         uint64
	Source     string
	RemoteAddr string
	KeyComment string
	Session    string
	Duration   string // pre-formatted
}

AdminConn describes a connection for display in the admin panel.

type AdminState

type AdminState struct {
	Conns        []AdminConn
	SSHEnabled   bool
	WebEnabled   bool
	RelayEnabled bool
	Selected     int

	// Per-session access flags for the attached session.
	SessionAllowSSH   bool
	SessionAllowWeb   bool
	SessionAllowRelay bool

	APIEnabled      bool
	SessionAllowAPI bool

	// RelayConfigured is true when the user has a relay account set up.
	RelayConfigured bool
}

AdminState holds the data for the admin panel overlay.

func DecodeAdminState

func DecodeAdminState(data []byte) *AdminState

DecodeAdminState deserializes AdminState from proto transport.

type CellSnapshot

type CellSnapshot struct {
	Content string
	Width   int
	Style   uv.Style
}

CellSnapshot holds a copied cell's content and style.

type HUDInfo

type HUDInfo struct {
	SSHAddr   string // empty = not listening
	WebAddr   string // empty = not listening
	RelayAddr string // empty = not connected
	PrefixKey byte
}

HUDInfo holds server status for the HUD overlay.

type Pane

type Pane struct {
	ID int
	// contains filtered or unexported fields
}

Pane is a pseudo-terminal backed by a VT emulator.

func NewPane

func NewPane(id int, cols, rows int, shell string, scrollbackLines ...int) (*Pane, error)

NewPane spawns a shell in a new PTY with the given dimensions. scrollbackLines controls VT scrollback depth; 0 means default (10000).

func (*Pane) AddWriter

func (p *Pane) AddWriter(w io.Writer)

AddWriter registers a writer to receive raw PTY output. Silently drops the registration if the per-pane writer limit is reached.

func (*Pane) Close

func (p *Pane) Close()

Close sends SIGHUP and reaps the child process.

func (*Pane) CursorPos

func (p *Pane) CursorPos() image.Point

CursorPos returns the cursor position under the lock.

func (*Pane) CursorVisible

func (p *Pane) CursorVisible() bool

CursorVisible returns whether the cursor should be shown.

func (*Pane) Dead

func (p *Pane) Dead() bool

Dead reports whether the pane's shell process has exited.

func (*Pane) DrainBell

func (p *Pane) DrainBell() bool

DrainBell returns true if a bell has fired since the last drain.

func (*Pane) DrainClipboard

func (p *Pane) DrainClipboard() []byte

DrainClipboard returns and clears any pending OSC 52 clipboard data.

func (*Pane) PlainText added in v1.0.29

func (p *Pane) PlainText() string

PlainText returns the visible screen as plain text with trailing whitespace trimmed per line.

func (*Pane) Redraw

func (p *Pane) Redraw()

Redraw sends SIGWINCH to force the child process to repaint.

func (*Pane) RemoveWriter

func (p *Pane) RemoveWriter(w io.Writer)

RemoveWriter unregisters a previously added writer.

func (*Pane) Resize

func (p *Pane) Resize(cols, rows int)

Resize updates the PTY and VT emulator dimensions.

func (*Pane) Screen

func (p *Pane) Screen() ScreenState

Screen returns a snapshot of the pane's visible screen under the lock. Safe to read concurrently with readLoop writing to the VT emulator.

func (*Pane) ScrollScreen

func (p *Pane) ScrollScreen(offset, viewW, viewH int) ScreenState

ScrollScreen returns a screen snapshot scrolled up by offset lines into the scrollback buffer. offset=0 means the live screen. The returned ScreenState has dimensions viewW x viewH.

func (*Pane) ScrollbackLen

func (p *Pane) ScrollbackLen() int

ScrollbackLen returns the number of lines in the scrollback buffer.

func (*Pane) Snapshot

func (p *Pane) Snapshot() []byte

Snapshot returns the current screen state as ANSI escape sequences.

func (*Pane) Title

func (p *Pane) Title() string

Title returns the pane's OSC title, or "shell" if unset.

func (*Pane) Wait

func (p *Pane) Wait()

Wait blocks until the pane's read loop exits.

func (*Pane) WriteInput

func (p *Pane) WriteInput(data []byte) (int, error)

WriteInput writes user input to the PTY.

type Rect

type Rect struct {
	X, Y, W, H int
}

Rect is a positioned rectangle within the terminal.

type ScreenState

type ScreenState struct {
	Cells  []CellSnapshot
	Cursor image.Point
	W, H   int
}

ScreenState holds a snapshot of the pane's visible screen, cursor position, and dimensions. Cells is a flat slice indexed as [row*W+col].

type Session

type Session struct {
	Name  string
	ID    uint64
	Shell string // shell to spawn in new panes
	// contains filtered or unexported fields
}

Session is a named collection of windows.

func NewSession

func NewSession(name string, cols, rows int, shell string) (*Session, error)

NewSession creates a session with one window at the given dimensions.

func (*Session) ActiveWindow

func (s *Session) ActiveWindow() *Window

ActiveWindow returns the currently selected window.

func (*Session) ActiveWindowIndex

func (s *Session) ActiveWindowIndex() int

ActiveWindowIndex returns the index of the active window.

func (*Session) AllowAPI added in v1.0.29

func (s *Session) AllowAPI() bool

AllowAPI returns whether API access (send/screen) is permitted for this session.

func (*Session) AllowRelay

func (s *Session) AllowRelay() bool

AllowRelay returns whether relay access is permitted for this session.

func (*Session) AllowSSH

func (s *Session) AllowSSH() bool

AllowSSH returns whether SSH access is permitted for this session.

func (*Session) AllowWeb

func (s *Session) AllowWeb() bool

AllowWeb returns whether web access is permitted for this session.

func (*Session) Close

func (s *Session) Close()

Close closes all windows in the session.

func (*Session) CloseActiveWindow

func (s *Session) CloseActiveWindow() bool

CloseActiveWindow closes the active window. Returns true if the session is empty.

func (*Session) Dead

func (s *Session) Dead() bool

Dead reports whether the session has no live windows.

func (*Session) NewWindow

func (s *Session) NewWindow() error

NewWindow creates a new window and makes it active.

func (*Session) NextWindow

func (s *Session) NextWindow()

NextWindow cycles to the next window.

func (*Session) Pane

func (s *Session) Pane() *Pane

Pane returns the active pane.

func (*Session) PrevWindow

func (s *Session) PrevWindow()

PrevWindow cycles to the previous window.

func (*Session) ReapDead

func (s *Session) ReapDead() bool

ReapDead removes all dead windows. Returns true if session is empty.

func (*Session) Resize

func (s *Session) Resize(cols, rows int)

Resize updates session dimensions and resizes all windows.

func (*Session) SelectWindow

func (s *Session) SelectWindow(idx int)

SelectWindow switches to the window at the given index.

func (*Session) SetAllowAPI added in v1.0.29

func (s *Session) SetAllowAPI(v bool)

SetAllowAPI toggles API access for this session.

func (*Session) SetAllowRelay

func (s *Session) SetAllowRelay(v bool)

SetAllowRelay toggles relay access for this session.

func (*Session) SetAllowSSH

func (s *Session) SetAllowSSH(v bool)

SetAllowSSH toggles SSH access for this session.

func (*Session) SetAllowWeb

func (s *Session) SetAllowWeb(v bool)

SetAllowWeb toggles web access for this session.

func (*Session) Title

func (s *Session) Title() string

Title returns the active window's title.

func (*Session) Windows

func (s *Session) Windows() []*Window

Windows returns a copy of the window list.

type Window

type Window struct {
	ID int
	// contains filtered or unexported fields
}

Window manages a single pane within a session.

func NewWindow

func NewWindow(id int, cols, rows int, shell string) (*Window, error)

NewWindow creates a window with a single pane of the given size.

func (*Window) ActivePane

func (w *Window) ActivePane() *Pane

ActivePane returns the pane.

func (*Window) Close

func (w *Window) Close()

Close closes the pane.

func (*Window) Dead

func (w *Window) Dead() bool

Dead reports whether the pane has exited.

func (*Window) Panes

func (w *Window) Panes() []*Pane

Panes returns the single pane as a slice.

func (*Window) Resize

func (w *Window) Resize(cols, rows int)

Resize updates the pane dimensions.

func (*Window) Snapshot

func (w *Window) Snapshot() *Pane

Snapshot returns the pane for rendering.

func (*Window) Title

func (w *Window) Title() string

Title returns the pane's title.

Jump to

Keyboard shortcuts

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