Documentation
¶
Overview ¶
Package tvxterm provides a small terminal widget for tview.
The package is built around three pieces:
- View: a tview primitive that renders terminal state
- Backend: a transport abstraction for PTY, SSH, or custom streams
- Emulator: a small VT-like state machine that turns bytes into cells
View and Backend form the primary public API for embedding terminal sessions into applications. Emulator and Snapshot are also exported so callers can test, inspect, or reuse the byte-to-cell pipeline directly when needed.
Index ¶
- type Backend
- type Cell
- type Emulator
- type PTYBackend
- type Snapshot
- type StreamBackend
- type StyleState
- type View
- func (v *View) Attach(backend Backend)
- func (v *View) Blur()
- func (v *View) Close() error
- func (v *View) Draw(screen tcell.Screen)
- func (v *View) Focus(delegate func(p tview.Primitive))
- func (v *View) HasFocus() bool
- func (v *View) InputHandler() func(event *tcell.EventKey, setFocus func(p tview.Primitive))
- func (v *View) MouseHandler() ...
- func (v *View) PasteHandler() func(text string, setFocus func(p tview.Primitive))
- func (v *View) ScrollbackDown(lines int)
- func (v *View) ScrollbackPageDown()
- func (v *View) ScrollbackPageUp()
- func (v *View) ScrollbackStatus() (offset int, rows int)
- func (v *View) ScrollbackUp(lines int)
- func (v *View) SendKey(event *tcell.EventKey) bool
- func (v *View) SendPaste(text string) bool
- func (v *View) SetBackendExitHandler(fn func(*View, error)) *View
- func (v *View) SetTitleHandler(fn func(*View, string)) *View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
Backend is the transport abstraction for the terminal widget. Anything that can read terminal output, accept terminal input, and resize a terminal session can be attached.
type Emulator ¶
type Emulator struct {
// contains filtered or unexported fields
}
Emulator is a deliberately small VT-like emulator.
It is responsible for converting terminal bytes into a cell grid plus a small amount of terminal state. Applications embedding View usually do not need to use Emulator directly, but it remains exported for testing and advanced use.
func NewEmulator ¶
NewEmulator creates an emulator with the given initial size.
func (*Emulator) DrainResponses ¶
DrainResponses returns terminal responses generated by the emulator, such as DSR or DA replies, and clears the pending response queue.
func (*Emulator) SnapshotAt ¶
SnapshotAt returns a view of the screen including local scrollback.
An offset of 0 returns the live screen. Positive offsets walk backward into retained scrollback rows.
type PTYBackend ¶
type PTYBackend struct {
// contains filtered or unexported fields
}
PTYBackend wraps a local PTY-backed process.
func NewPTYBackend ¶
func NewPTYBackend(cmd *exec.Cmd, cols, rows int) (*PTYBackend, error)
NewPTYBackend starts cmd under a PTY and returns a Backend implementation for it with the requested initial size.
func (*PTYBackend) Close ¶
func (b *PTYBackend) Close() error
func (*PTYBackend) Resize ¶
func (b *PTYBackend) Resize(cols, rows int) error
type Snapshot ¶
type Snapshot struct {
Cols int
Rows int
CursorX int
CursorY int
CursorVis bool
CursorBlink bool
AppCursor bool
AppKeypad bool
ColumnMode132 bool
AutoWrap bool
UsingAlt bool
ReverseVideo bool
BracketedPaste bool
FocusReporting bool
MouseX10 bool
MouseVT200 bool
MouseButtonEvt bool
MouseAnyEvt bool
MouseSGR bool
ScrollTop int
ScrollBottom int
ScrollbackRows int
WindowTitle string
Cells [][]Cell
}
Snapshot is an immutable copy of the emulator's visible state.
type StreamBackend ¶
type StreamBackend struct {
// contains filtered or unexported fields
}
StreamBackend adapts generic terminal-like streams to Backend. This is useful when another library owns session creation and only exposes stdin/stdout plus optional resize/close hooks.
func NewStreamBackend ¶
func NewStreamBackend(reader io.Reader, writer io.Writer, resize func(cols, rows int) error, close func() error) *StreamBackend
NewStreamBackend wraps generic terminal-like streams plus optional resize and close hooks into a Backend.
func (*StreamBackend) Close ¶
func (b *StreamBackend) Close() error
func (*StreamBackend) Resize ¶
func (b *StreamBackend) Resize(cols, rows int) error
type StyleState ¶
StyleState is the emulator's logical text style before it is converted into a tcell.Style for drawing.
type View ¶
View is a tview primitive that renders a terminal stream inside a boxed widget. Design intent:
- frontend: tview primitive
- state: tiny VT-like emulator
- backend: PTY/SSH/anything implementing Backend
This mirrors the separation used by gowid's terminal widget: input/output are not tied to a subprocess launcher, and drawing happens from an intermediate terminal state rather than directly from raw bytes.
func New ¶
func New(app *tview.Application) *View
New creates a terminal view bound to the given tview application.
The application reference is used for redraw scheduling and optional focus/paste integration. Passing nil is allowed for tests or headless use.
func (*View) Attach ¶
Attach connects a backend to the view and starts reading from it.
Callers typically create one backend per view and attach it once.
func (*View) InputHandler ¶
func (*View) MouseHandler ¶
func (v *View) MouseHandler() func(action tview.MouseAction, event *tcell.EventMouse, setFocus func(p tview.Primitive)) (consumed bool, capture tview.Primitive)
func (*View) PasteHandler ¶
func (*View) ScrollbackDown ¶
ScrollbackDown moves the local scrollback view downward by the given number of lines. Non-positive values are treated as 1.
func (*View) ScrollbackPageDown ¶
func (v *View) ScrollbackPageDown()
ScrollbackPageDown moves the local scrollback view down by one visible page.
func (*View) ScrollbackPageUp ¶
func (v *View) ScrollbackPageUp()
ScrollbackPageUp moves the local scrollback view by one visible page.
func (*View) ScrollbackStatus ¶
ScrollbackStatus returns the current local scroll offset and the total number of available scrollback rows.
func (*View) ScrollbackUp ¶
ScrollbackUp moves the local scrollback view upward by the given number of lines. Non-positive values are treated as 1.
func (*View) SendKey ¶ added in v0.1.1
SendKey writes a single key event to the attached backend using the same encoding rules as interactive input handling.
func (*View) SendPaste ¶ added in v0.1.1
SendPaste writes pasted text to the attached backend, preserving bracketed paste behavior when enabled by the remote terminal.
func (*View) SetBackendExitHandler ¶
SetBackendExitHandler installs a callback invoked when the attached backend read loop exits with an error or EOF.