Documentation
¶
Overview ¶
Package term runs a vendor's interactive command in a pseudo-terminal of its own, attached to the user's terminal (a relay): the user sees the program and answers what it asks, and hopsesh only watches what it prints and how it ends.
The rules (docs/design.md §15, "Terminal steps"): the program's input is fed only by the user's keyboard, paste and the terminal's own answers to its queries; hopsesh writes no byte into it. The program is started from its argument list, never typed into a shell. What it prints goes to the user unchanged and, passively, into a bounded buffer that only the module's reader looks at (the session's link, a refusal); nothing of it is logged, journaled or kept once the step is read.
Index ¶
Constants ¶
const MaxCapture = 64 << 10
MaxCapture is how much of a program's output a Capture keeps: its last 64 KB.
Variables ¶
var ErrNoPseudoTerminal = errors.New("no pseudo-terminal on this system")
ErrNoPseudoTerminal is returned when this system cannot give the program a pseudo-terminal (a Windows older than 10 1809 has no ConPTY). The caller can run the program on the terminal directly instead, without watching it.
Functions ¶
func Plain ¶
Plain turns what a program printed to a terminal into plain text: control sequences (CSI, OSC, DCS and the like) are taken out, a cursor move to another line becomes a line break and one along the line a space, carriage returns become line breaks, and the other control characters but tab go. The target of an OSC 8 hyperlink stays, between spaces, since a program may show a link's text and keep its address there. Invalid UTF-8 is dropped.
Types ¶
type Capture ¶
type Capture struct {
// contains filtered or unexported fields
}
Capture keeps the last MaxCapture bytes a program printed, in memory only, for a module's reader to look at once the program ended. It is safe for concurrent use.
type Relay ¶
type Relay struct {
Argv []string
Dir string
Env []string // the program's whole environment
// Capture gets a copy of everything the program prints (nil: nothing is kept).
Capture *Capture
// Width and Height are the pseudo-terminal's size when the user's side is not a
// terminal (0: a default); a terminal's own size wins.
Width, Height int
// Code is the program's exit code once Run returned (-1: unknown); Cols, the width it
// started with.
Code int
Cols int
// contains filtered or unexported fields
}
Relay runs one program under a pseudo-terminal attached to the user's terminal. It implements Bubble Tea's ExecCommand (Run, SetStdin, SetStdout, SetStderr), so a terminal UI can hand it the terminal with tea.Exec and get it back afterwards.
func (*Relay) Run ¶
Run starts the program, relays until it ends, and restores the user's terminal. An exit code other than 0 is not an error (Code has it); an error means the program could not be run, or the relay broke.
func (*Relay) SetStderr ¶
SetStderr is unused: the program's errors come through its terminal like the rest.