Help us shape the future of Go! Take the 2026 Go Developer Survey

tui

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package tui holds the interactive Reinstate surfaces built on Bubble Tea.

The layering rule is absolute: tui is a view. It reads through the engine packages (sessionindex, preflight, handoff, sync) and returns an Intent describing what the user chose. It never launches a vendor process, never writes into a vendor store, and never decides policy. Engine packages never import tui or ui.

The reason a surface returns an Intent instead of acting is the terminal. Resuming a session hands the terminal to a vendor CLI that draws its own full-screen UI. That can only happen after Bubble Tea has restored the terminal completely, which means after the program has exited — so the program exits first, and the caller acts second.

Copyright 2026 Harjot Singh Rana. Licensed under Apache-2.0.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInteractive = errors.New("interactive surface requires a terminal")

ErrNotInteractive is returned when Run is called without a usable terminal. Callers translate it into the usage-coded refusal with a --json hint.

Functions

This section is empty.

Types

type Action

type Action string

Action is what an interactive surface decided to do.

const (
	// ActionNone means the user cancelled. The caller exits 0 silently.
	ActionNone Action = ""
	// ActionResume continues a session in its own vendor agent.
	ActionResume Action = "resume"
	// ActionFork branches a session through its vendor's native fork path.
	ActionFork Action = "fork"
	// ActionHandoff starts a new session in a different agent from a capsule.
	ActionHandoff Action = "handoff"
	// ActionInspect prints the full metadata report for a session.
	ActionInspect Action = "inspect"
	// ActionCommand runs another rein subcommand, named in Intent.Command.
	// It is how the command palette reaches verbs that are not session actions.
	ActionCommand Action = "command"
)

type ClipboardFunc

type ClipboardFunc func(string) error

ClipboardFunc copies text to the system clipboard.

func OSC52Clipboard

func OSC52Clipboard(out io.Writer) ClipboardFunc

OSC52Clipboard returns a ClipboardFunc that copies through the terminal itself using the OSC 52 escape sequence.

This is deliberately not a native clipboard binding. A session reference is most often needed on a machine reached over SSH, where a host-side clipboard call would put the text on the wrong computer. OSC 52 asks the terminal emulator that the human is actually looking at to do the copy, so it works locally, over SSH, and inside tmux and screen alike.

type ClipboardMsg

type ClipboardMsg struct {
	Text string
	Err  error
}

ClipboardMsg reports the outcome of a copy so a surface can show a status.

func (ClipboardMsg) String

func (c ClipboardMsg) String() string

String renders a human status line for a copy result.

type Intent

type Intent struct {
	Action Action
	// Reference is the canonical agent:native-session-id.
	Reference string
	// Destination is the handoff target agent key. Empty unless ActionHandoff.
	Destination string
	// Policy is the handoff projection policy. Empty unless ActionHandoff.
	Policy string
	// Command is the rein subcommand to run. Set only for ActionCommand, and
	// always a fixed identifier chosen from a table, never user-typed text.
	Command string
	// AcknowledgedWarnings holds exact warning IDs the user ticked. These are
	// passed straight through to the same authorization call the flag path
	// uses; the TUI grants nothing the flags could not.
	AcknowledgedWarnings []string
}

Intent is the result of an interactive surface: what to do, to what, and with which acknowledgements. It is deliberately flat and free of engine types so the boundary stays narrow.

func Run

func Run(ctx context.Context, surface Surface, opts RunOptions) (Intent, error)

Run starts an interactive surface and returns the user's intent.

It refuses non-interactive capabilities rather than degrading, because the caller has already chosen this path by consulting the same capability.

func (Intent) Chosen

func (i Intent) Chosen() bool

Chosen reports whether the user picked an action rather than cancelling.

type RunOptions

type RunOptions struct {
	In         io.Reader
	Out        io.Writer
	Capability ui.Capability
	// AltScreen puts the program on the alternate buffer, leaving the user's
	// scrollback untouched. Full-screen surfaces set it; inline prompts do not.
	AltScreen bool
	// contains filtered or unexported fields
}

RunOptions configure one interactive program.

type Surface

type Surface interface {
	tea.Model
	// Intent returns the decision after the program has exited.
	Intent() Intent
	// Err returns a fatal error encountered while running, if any.
	Err() error
}

Surface is a Bubble Tea model that resolves to an Intent.

Implementations must return a zero Intent when the user cancels, and must never perform the action themselves.

Directories

Path Synopsis
Package handoffui is the interactive handoff studio.
Package handoffui is the interactive handoff studio.
Package palette is the command palette: one keystroke that reaches every verb, from anywhere.
Package palette is the command palette: one keystroke that reaches every verb, from anywhere.
Package readiness computes, caches, and presents how resumable a session is.
Package readiness computes, caches, and presents how resumable a session is.
Package switcher is the interactive session list behind bare `rein`.
Package switcher is the interactive session list behind bare `rein`.
Package tuitest is the deterministic frame harness for Reinstate's interactive surfaces.
Package tuitest is the deterministic frame harness for Reinstate's interactive surfaces.
Package wizard is the interactive front end for `rein init`.
Package wizard is the interactive front end for `rein init`.

Jump to

Keyboard shortcuts

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