term

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 16 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 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

View Source
const MaxCapture = 64 << 10

MaxCapture is how much of a program's output a Capture keeps: its last 64 KB.

Variables

View Source
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

func Plain(b []byte) string

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.

func (*Capture) Reset

func (c *Capture) Reset()

Reset forgets what was kept.

func (*Capture) Text

func (c *Capture) Text() string

Text is what was kept, as plain text (see Plain).

func (*Capture) Write

func (c *Capture) Write(p []byte) (int, error)

Write keeps p, dropping the oldest bytes beyond MaxCapture.

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 New

func New(argv []string, dir string, env []string) *Relay

New is a relay for argv in dir with the environment env.

func (*Relay) Run

func (r *Relay) Run() error

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

func (r *Relay) SetStderr(w io.Writer)

SetStderr is unused: the program's errors come through its terminal like the rest.

func (*Relay) SetStdin

func (r *Relay) SetStdin(in io.Reader)

SetStdin sets where the user's keys come from (default: os.Stdin).

func (*Relay) SetStdout

func (r *Relay) SetStdout(out io.Writer)

SetStdout sets the user's terminal (default: os.Stdout).

Jump to

Keyboard shortcuts

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