interactive

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 0 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package interactive translates local terminal bytes into remote writes and local escape commands.

It has no dependency on a console, Session, or Transport. Callers own the actual writes and local presentation so the same byte-level controller can serve serial, SSH, and future interactive terminal clients.

Index

Constants

View Source
const DefaultEscapeByte byte = 0x1D

DefaultEscapeByte is the byte conventionally emitted by Ctrl+].

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Kind    ActionKind
	Data    []byte
	Command byte
}

Action describes one ordered effect requested by a Controller.

Data is populated for ActionRemote and contains caller-owned bytes copied by Controller. Command is populated for ActionUnknownEscape. ActionQuit, ActionHelp, ActionTogglePromptTimestamp, ActionFileTransfer, ActionEscapePending, and ActionCancelEscape do not carry payload data.

type ActionKind

type ActionKind uint8

ActionKind identifies the result of processing local terminal input.

const (
	// ActionRemote writes Data to the connected Session without changing it.
	ActionRemote ActionKind = iota
	// ActionQuit asks the local interactive client to end its Session.
	ActionQuit
	// ActionHelp asks the local interactive client to display escape help.
	ActionHelp
	// ActionTogglePromptTimestamp asks the local interactive client to toggle
	// its presentation-only shell prompt timestamps.
	ActionTogglePromptTimestamp
	// ActionFileTransfer asks the local interactive client to open its
	// file-transfer menu. The menu and transfer remain local to that client.
	ActionFileTransfer
	// ActionEscapePending reports that the controller has entered local escape
	// mode and is waiting for its command byte.
	ActionEscapePending
	// ActionCancelEscape reports that Esc returned the controller from local
	// escape mode to normal remote-input mode without forwarding Esc.
	ActionCancelEscape
	// ActionUnknownEscape reports an unsupported byte following the escape byte.
	ActionUnknownEscape
)

type Controller

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

Controller maintains the escape-prefix state for one interactive input stream. Its zero value uses DefaultEscapeByte.

Controller is intentionally not safe for concurrent use because terminal input must be processed in read order by one input loop.

func NewController

func NewController(escapeByte byte) *Controller

NewController creates a Controller whose local escape prefix is escapeByte.

escapeByte is kept as a constructor argument so future CLI configuration can change the prefix without changing the state machine. A zero value uses DefaultEscapeByte so a Controller can be constructed from an omitted setting.

func (*Controller) EscapeByte

func (c *Controller) EscapeByte() byte

EscapeByte returns the configured local escape prefix.

func (*Controller) Process

func (c *Controller) Process(data []byte) []Action

Process consumes data in input order and returns the remote and local actions it represents.

In normal mode, Ctrl+C is byte 0x03 and is emitted as ActionRemote. In local escape mode, Ctrl+C cancels that mode and is still emitted as ActionRemote. Esc emits ActionCancelEscape without reaching the remote input. An unsupported command after the escape prefix is reported locally and always returns the controller to normal input mode.

Jump to

Keyboard shortcuts

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