Documentation
¶
Overview ¶
Package thrupty is the entry point of the thruPTY terminal emulator (throughput + through PTY + True PTY). It wires the child-process transport (ConPTY, Unix PTY, or direct pipes), the VT/ANSI terminal state machine, and the render host — thrupty's own WebGPU renderer or one of the vtui backends — into a running application. Main is exported so that cmd/thrupty is a thin wrapper and tests can drive the full startup path in-process.
thrupty preserves the high-throughput architecture of refterm, Casey Muratori's reference terminal renderer: a double-mapped circular source buffer (ByteRing), a SIMD parser with runtime AVX2/SSE2/SWAR dispatch (terminal), a double-buffered line table, and single-pass cell-expansion GPU rendering (renderer).
Index ¶
- func HexColor(rrggbb string) uint32
- func Main(args []string) int
- func TranslateInput(e *vtinput.InputEvent, win32Mode bool, kittyFlags int, appCursorKeys bool) string
- func TranslateKeyToKitty(e *vtinput.InputEvent, flags int, appCursorKeys bool) string
- func TranslateLegacySpecialKey(e *vtinput.InputEvent, appCursorKeys bool) string
- func TranslateMouseInput(e *vtinput.InputEvent) string
- type Far2lHandler
- type InputModes
- type PTYInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Main ¶
Main is the entry point for the thrupty executable. It is exported so that cmd/thrupty can call it, and also so that tests can exercise the full startup path without spawning a subprocess.
By default Main spawns the system shell on a PTY and renders it. The default renderer is the vtui-hosted gogpu window (--gui=gogpu); --gui also accepts x11/wayland (Unix only), cellgpu selects thrupty's own WebGPU renderer, and --tty renders through vtui's console ANSI path. The legacy demo content is available with --demo, the smoke test with --smoke-test. With --exec <cmd> [args...] the command runs directly on anonymous pipes, bypassing ConPTY entirely — the refterm architecture, used for throughput benchmarks and non-interactive tools.
func TranslateInput ¶
func TranslateInput(e *vtinput.InputEvent, win32Mode bool, kittyFlags int, appCursorKeys bool) string
TranslateInput converts thrupty input events into ANSI sequences that interactive shell apps expect (ported from f4 input_translation.go).
func TranslateKeyToKitty ¶
func TranslateKeyToKitty(e *vtinput.InputEvent, flags int, appCursorKeys bool) string
func TranslateLegacySpecialKey ¶
func TranslateLegacySpecialKey(e *vtinput.InputEvent, appCursorKeys bool) string
TranslateLegacySpecialKey encodes non-printable keys as ANSI sequences.
func TranslateMouseInput ¶
func TranslateMouseInput(e *vtinput.InputEvent) string
TranslateMouseInput encodes a mouse event as an SGR (1006) mouse sequence.
Types ¶
type Far2lHandler ¶
type Far2lHandler struct {
// Write delivers replies to the child process (pty.Write).
Write func([]byte)
// GetSize returns the terminal grid size in cells (columns, rows).
GetSize func() (w, h int)
// Notify shows a desktop notification requested by the guest ('n' command).
// May be nil, in which case notifications are dropped.
Notify func(title, text string)
// contains filtered or unexported fields
}
Far2lHandler processes far2l APC sequences arriving from the child process and writes replies back to the PTY.
func (*Far2lHandler) HandleFar2lAPC ¶
func (h *Far2lHandler) HandleFar2lAPC(s string)
HandleFar2lAPC handles one APC payload (the bytes between ESC _ and the terminator). Robustness: any garbage before the actual marker is skipped.
func (*Far2lHandler) ProcessFar2lInteract ¶
func (h *Far2lHandler) ProcessFar2lInteract(data []byte)
ProcessFar2lInteract handles one decoded far2l interact request.
func (*Far2lHandler) SendFar2lTerminalSize ¶
func (h *Far2lHandler) SendFar2lTerminalSize()
SendFar2lTerminalSize pushes the current grid size to the guest.
type InputModes ¶
type InputModes struct {
Win32InputMode bool
KittyFlags int
AppCursorKeys bool
BracketedPasteMode bool
MouseTrackingMode int
}
InputModes mirrors the terminal mode flags that affect input translation. They are tracked by the terminal parser (see terminal.Terminal).
type PTYInput ¶
type PTYInput struct {
// Sink receives fully assembled input events (after the key+text merge
// and the PreTranslate hook). Set in normal operation: the terminal
// thread's consumer translates and writes. When nil, events are
// translated synchronously via Write (unit-test path).
Sink func(*vtinput.InputEvent)
// Write delivers translated input to the child process. Used only
// when Sink is nil.
Write func([]byte)
// Modes returns the terminal's current input-related mode flags.
// If nil, all modes are assumed off.
Modes func() InputModes
// ReadClipboard reads the system clipboard for Ctrl+Shift+V paste.
// May be nil, in which case the shortcut is inert.
ReadClipboard func() (string, error)
// PreTranslate intercepts a fully assembled input event (after the
// key+text merge) before ANSI translation. Returning true consumes the
// event: nothing is written to the PTY. The vtui overlay uses this to
// take over input while one of its frames is open. May be nil.
PreTranslate func(*vtinput.InputEvent) bool
// contains filtered or unexported fields
}
PTYInput converts renderer key/text events into vtinput events. The translation to ANSI bytes and the (potentially blocking) write to the child happen on the terminal thread: assembled events are handed to Sink.
func (*PTYInput) HandleMouse ¶
func (in *PTYInput) HandleMouse(e *vtinput.InputEvent)
HandleMouse forwards a mouse event (the vtui overlay gets it first via PreTranslate, then the sink or the synchronous path).
func (*PTYInput) HandleMouseEvent ¶
func (in *PTYInput) HandleMouseEvent(ev renderer.MouseEvent)
HandleMouseEvent converts a renderer mouse event into a vtinput mouse event (tracking the held-button mask like a Win32 MOUSE_EVENT_RECORD) and forwards it for SGR mouse translation.
func (*PTYInput) HandlePaste ¶
HandlePaste sends pasted text to the child, wrapping it in bracketed-paste markers when the application enabled mode 2004 (f4 panels_frame.go). With a sink attached the paste travels as events (PasteStart marker, payload, PasteEnd marker) so the write happens on the terminal thread; the payload rides in Far2lData — InputEvent has no dedicated text field — and is written verbatim by the consumer.
func (*PTYInput) HandleText ¶
HandleText processes text input produced by a key press.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ByteRing implements the circular source buffer at the heart of thrupty's throughput story: the backing store is mapped twice back-to-back in the virtual address space, so a read that wraps around the physical end of the allocation is returned as a single contiguous slice — zero-copy ring reads, exactly like refterm's source buffer.
|
Package ByteRing implements the circular source buffer at the heart of thrupty's throughput story: the backing store is mapped twice back-to-back in the virtual address space, so a read that wraps around the physical end of the allocation is returned as a single contiguous slice — zero-copy ring reads, exactly like refterm's source buffer. |
|
cmd
|
|
|
thrupty
command
Command thrupty is the thruPTY terminal emulator executable.
|
Command thrupty is the thruPTY terminal emulator executable. |
|
Package pty abstracts child-process transport behind the PtyBackend interface: ConPTY on Windows and /dev/ptmx on Unix (Linux, macOS, the BSDs, Solaris).
|
Package pty abstracts child-process transport behind the PtyBackend interface: ConPTY on Windows and /dev/ptmx on Unix (Linux, macOS, the BSDs, Solaris). |
|
Package renderer is thrupty's own WebGPU render host — the cellgpu backend.
|
Package renderer is thrupty's own WebGPU render host — the cellgpu backend. |
|
Package termcell holds the small value types shared by the terminal state machine and the GPU renderer: the per-cell text cell (the grid's source of truth), the baked per-cell GPU payload, glyph atlas tile info, and shaped-cell runs.
|
Package termcell holds the small value types shared by the terminal state machine and the GPU renderer: the per-cell text cell (the grid's source of truth), the baked per-cell GPU payload, glyph atlas tile info, and shaped-cell runs. |
|
Package terminal is thrupty's VT/ANSI state machine.
|
Package terminal is thrupty's VT/ANSI state machine. |
|
Package termui extracts the terminal into a self-contained component (TerminalUI) with its own goroutine, step 3 of the vtui integration roadmap (see AGENTS.md, Phase 5).
|
Package termui extracts the terminal into a self-contained component (TerminalUI) with its own goroutine, step 3 of the vtui integration roadmap (see AGENTS.md, Phase 5). |
|
Package vtuibridge connects the vtui UI toolkit to thrupty's GPU renderer.
|
Package vtuibridge connects the vtui UI toolkit to thrupty's GPU renderer. |