term

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 17 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

Index

Constants

View Source
const (
	// ExitFailure is an error, a refusal among them.
	ExitFailure = 1
	// ExitAttention is an outcome that needs a person's look: a hold, a
	// look left incomplete, or archives that don't match.
	ExitAttention = 3
)

The exit codes a command's outcome calls for (Design v3 §12), named so no site chooses a bare number and none reads one back as control flow.

View Source
const JSONVersion = 1

JSONVersion is the version of the --json envelope and the results in it.

Variables

StopSignals are the signals that stop a command, each cancelling its context so it unwinds: an interrupt, a terminate, and a hangup, which a closed terminal window or a dropped SSH session sends. Under Go's default a hangup ended the process on the spot, leaving a Tart check's VM running and its clone on disk (#240).

View Source
var TableLine = regexp.MustCompile(`\S {2,}\S`)

TableLine is a line whose cells are set apart by two spaces or more, which is set in columns rather than wrapped.

Functions

func Answer

func Answer(yes bool) *bool

Answer is an answer for Decision.Nobody.

func Cut

func Cut(line string, width int) string

Cut is a table's line cut at width, its end said with "…", as a terminal shows a table's widest free-text cell, the last; -v shows it whole, and off a terminal nothing is cut, since field testing reads dockhand through a pipe and acts on its words. A line that isn't a table's, or fits, is as it is.

func ExitCode

func ExitCode(err error) int

ExitCode is the process exit code for err: its own when it carries one, however wrapped, else its refusal's kind's (refusal.Kind.Exit, the one table of them), else ExitFailure.

func Exitf

func Exitf(code int, format string, args ...any) error

Exitf is an ExitError with code, its message formatted.

func UntilStopped added in v0.9.0

func UntilStopped(parent context.Context) (context.Context, context.CancelFunc)

UntilStopped is parent until one of StopSignals arrives, as signal.NotifyContext makes it, and the function to call once the command is done. A stop signal the process started with ignored stays ignored: nohup starts dockhand with hangups ignored so that it outlives its terminal, and a non-interactive shell starts a background job with interrupts ignored, where asking to be told of one would heed it. Once stopped, writes to standard output or error no longer end the process: the terminal or pipe they went to may be gone with the hangup, and the unwind is worth more than its words, so a write there fails as any write does, with its error, which teardown doesn't wait on, where Go's default for a broken pipe on those two is to end the process as SIGPIPE does. Until then a pipe closed by its reader, as by head, still ends dockhand quietly.

func Visible added in v0.9.0

func Visible(text string) string

Visible is text that is someone else's, a pull request's diff, paths, title or commit subject, made safe to write to a terminal: every control character but newline and tab is shown in a visible form, so that a carriage return, an escape sequence or a backspace in it can't draw over what it is shown beside (#330). A C0 control and DEL show as their Unicode control pictures (␍, ␛, ␡), a C1 control as <U+0085>, and a byte that isn't UTF-8 as <0x9B>, since a terminal not reading UTF-8 takes some of those for C1 controls. The bidirectional formatting characters show as a C1 control does, <U+202E>: an override can show a Portfile line in another order than Tcl reads it. Text with none of these comes back as it was.

func Wrapped

func Wrapped(line string, width int) string

Wrapped is one line as the output's writer sets it at width: broken at its spaces where it's wider and has somewhere to break, its later lines two past its own indent; a table's line, or one with escape codes or a tab, as it is.

func WriteError added in v0.9.0

func WriteError(w io.Writer, err error)

WriteError writes a command's final error, as the process ends on it, made safe to show (Visible): it may carry another's words, Git's, GitHub's, or a remote's, which mustn't draw over the terminal (#330, #365). An error with no words writes nothing.

Types

type Decision

type Decision struct {
	Question string
	Yes      bool
	Undone   string
	ByYes    string
	// Nobody is the answer where nobody is there to ask and none refuses,
	// as for a question with a safe way on, stopping a running check
	// that a script asked to replace; nil refuses.
	Nobody *bool
}

Decision is a yes-or-no question a command asks before it acts: what it asks on a terminal, its answer when the person just presses return, and what was left undone without one, "nothing was removed", with what --yes would do, "--yes removes these".

type Display

type Display struct {
	// NoColour is NO_COLOR set, or dockhand console's --plain.
	NoColour bool
	// Columns is COLUMNS, where it's set; prose off a terminal wraps at it,
	// else at 100, since field testing reads dockhand through a pipe.
	Columns int
}

Display is how a command line's text is shown, as its environment asks: whether the marks are coloured, and the columns text wraps at where output isn't a terminal. The command line reads them from the environment (NO_COLOR, COLUMNS), as nothing below it does.

type ExitError

type ExitError struct {
	Code    int
	Message string
}

ExitError carries the exit code a command's outcome calls for.

func (*ExitError) Error

func (e *ExitError) Error() string

type Gatherer

type Gatherer interface {
	Gather(step any)
	Result() any
}

A Gatherer is a command's result that the steps it goes on to report into, so that the command has one shape wherever it stops: what a step didn't reach is left out.

type Stage

type Stage struct {
	// contains filtered or unexported fields
}

Stage is a stage's report held back (Staged).

func (*Stage) Done

func (st *Stage) Done(format string, args ...any)

Done says a stage that went through in its one line, where its report was held back, which is -v's: the report is dropped, unless a question already said it.

func (*Stage) Drop

func (st *Stage) Drop()

Drop drops a stage's report held back, said elsewhere in a line of its own, as a batch's row says it.

func (*Stage) Say

func (st *Stage) Say()

Say says the stage's report held back, as for a stage that held or failed, where the person reads why.

type StatusLine

type StatusLine struct {
	// contains filtered or unexported fields
}

StatusLine is standard error with at most one line redrawn in place, as outdated redraws its count. A line printed while it shows clears it first and draws it again after, so the two never share a line.

func (*StatusLine) Clear

func (s *StatusLine) Clear()

Clear removes the line, if one shows.

func (*StatusLine) Say

func (s *StatusLine) Say(line string)

Say prints a line of its own, above the line shown.

func (*StatusLine) Show

func (s *StatusLine) Show(text string)

Show draws text in place of what the line showed, cut short of the terminal's width with "…": a line that wrapped left its first row behind at each redraw, since the clear reaches only the cursor's row, and a check's progress read as one long line of every step (#332's try).

type Streams

type Streams struct {
	In  io.Reader
	Out io.Writer
	Err io.Writer
	// contains filtered or unexported fields
}

Streams are the standard streams a command reads and writes. Out is standard output raw, beneath it only --json's switch, for what comes from a file, a tool or a template: a Portfile, a diff, a log, a completion script, a usage page, a Markdown body. Dockhand's own sentences, tables and views write to Prose, which wraps at the width and colours the marks. The name typed by habit is the safe one: a payload written to Out by mistake for Prose costs a long line, where a wrapped Portfile was a broken one (#94, docs/designs/prose-stream.md at 36675f0d).

func Begin

func Begin(streams Streams, args []string) Streams

Begin are the streams a command line runs with: its input read by line, its output switched off while --json gathers the envelope, which args ask for, its output mode, and its status line.

func (Streams) AsTerminal

func (s Streams) AsTerminal() Streams

AsTerminal are the streams as a terminal's, where a test stands one in: every stream is one, and questions are asked of In.

func (Streams) Ask

func (s Streams) Ask(question string) (string, error)

Ask puts a question on standard error and reads one line. Input that ends without an answer is an empty answer, which takes the default.

func (Streams) AskYes

func (s Streams) AskYes(question string, empty bool) (bool, error)

AskYes asks a yes-or-no question on the terminal, with the answer an empty line gives: Decide's asking half, for a question whose command has made sure a person is there, as setup's offers and submit's tested checkboxes do.

func (Streams) Beneath added in v0.8.0

func (s Streams) Beneath() (io.Reader, io.Writer)

Beneath are the input and the output as a view drawn on the whole screen reads and writes them (term/screen): the output beneath the writers Begin puts before it, which would wrap a frame's lines, colour its marks, and break its one write into several.

func (Streams) Command

func (s Streams) Command() string

Command is the command the line runs (Reports), or empty before it's known.

func (Streams) Decide

func (s Streams) Decide(yes bool, d Decision) (bool, model.Answered, error)

Decide settles a decision: --yes takes it, a terminal asks it, and otherwise it's refused in one sentence, "nothing was removed: without a terminal, --yes removes these", exit 1. Seven commands each wrote the refusal their own way, two of them exiting 0 (clean's and review --pr's). It says how it was answered; a person's no is an answer, not an error.

func (Streams) Emit

func (s Streams) Emit(result any)

Emit keeps a command's result for the --json envelope.

func (Streams) ErrTerminal

func (s Streams) ErrTerminal() bool

ErrTerminal reports whether errors and progress go to a terminal, where a line can be redrawn.

func (Streams) Finish

func (s Streams) Finish(args []string, requests int64, err error) error

Finish ends a command line of args: where it reports as JSON, its envelope, which carries err and the GitHub requests it sent, is written, and an error is returned that carries only err's exit code; otherwise err as it is. Begin's streams.

func (Streams) Hanging

func (s Streams) Hanging(first, text string) string

Hanging is text wrapped at the output's width (Width), its first line after first and the rest after a hanging indent as wide as first, as status's attention list wraps its rows (2026-10-20): one writer for prose, where only that list wrapped, and lines ran to 400 columns. A line is never cut; a word wider than the width overruns it.

func (Streams) Height

func (s Streams) Height() int

Height is the output terminal's rows, for a view to fit; 0 off a terminal, where nothing is fitted.

func (Streams) Held

func (s Streams) Held() bool

Held reports whether the streams are a stage's whose report is held back (Staged): its progress, record IDs and provider steps, is -v's then, and on a terminal the line redrawn says the latest.

func (Streams) JSON

func (s Streams) JSON() bool

JSON reports whether the command line asked for --json.

func (Streams) LinkSteps

func (s Streams) LinkSteps(whole Gatherer)

LinkSteps makes whole the command's one result, with each later step's inside it, so a script reads one shape wherever the command stopped: ship's and bump's are the batch's, each change's update with its later steps inside, and check's the check's. A command already gathering keeps its own, as ship keeps its batch through each change's submission.

func (Streams) OutTerminal

func (s Streams) OutTerminal() bool

OutTerminal reports whether the output is a terminal that can be redrawn.

func (Streams) Plain

func (s Streams) Plain() Streams

Plain are the streams with their marks uncoloured, for dockhand console's --plain: line output a script or a log reads.

func (Streams) Prose added in v0.9.0

func (s Streams) Prose() io.Writer

Prose is the writer for dockhand's own sentences, tables and views: it wraps at the width, a terminal's or COLUMNS (wrapWriter), and colours the marks on a terminal. Streams never begun, as a test's, write prose to Out as it is.

func (Streams) ReadLine

func (s Streams) ReadLine() (string, error)

ReadLine reads one line of input, through the command's one reader.

func (Streams) Reports

func (s Streams) Reports(command string, asJSON bool)

Reports names the command the line runs, as its envelope says, and whether it reports as JSON, which silences standard output until Finish writes the envelope. Begin's streams.

func (Streams) Say

func (s Streams) Say(line string)

Say prints a line on standard error, above the line redrawn there.

func (Streams) SetVerbosity

func (s Streams) SetVerbosity(count int)

SetVerbosity records -v's count for the command line, which its streams' every copy reads (Verbose).

func (Streams) Staged

func (s Streams) Staged(under string) (Streams, *Stage)

Staged are streams for one stage of a command that runs several, as ship's edit, commit, check, and submission: at the default level, what the stage writes to standard output is held back, and said only where the stage held or failed (Stage.Say) or asks a question, which the person answers from it; with -v it's said as it's written (part 5, item 3: a clean bump printed four stages' full reports, 46 lines, where the person needs a line a stage). On a terminal, the stage under way is the line redrawn on standard error, until it's done or said.

func (Streams) Stamped added in v0.9.0

func (s Streams) Stamped(stamp func(io.Writer) io.Writer) Streams

Stamped are the streams with each line of standard output, prose and raw alike, passed through stamp first, beneath --json's switch: serve's time stamp off a terminal, which "serve: stopped" lost where Prose was built before it.

func (Streams) Status

func (s Streams) Status() *StatusLine

Status is the command's redrawn line on standard error.

func (Streams) Terminal

func (s Streams) Terminal() bool

Terminal reports whether the input is an interactive terminal, the only place a command may ask a question.

func (Streams) Unattended

func (s Streams) Unattended() Streams

Unattended are the streams of a command that asks nothing, whatever its input, as bump does: everything that would ask goes the way it goes without a terminal.

func (Streams) Verbose

func (s Streams) Verbose() int

Verbose is -v's count: 0 at the default level, 1 with -v, 2 with -vv (Design v3 §12).

func (Streams) Width

func (s Streams) Width() int

Width is the output terminal's columns, for text to wrap at; off a terminal, COLUMNS where it's set (Display), else 100.

func (Streams) WithDisplay

func (s Streams) WithDisplay(display Display) Streams

WithDisplay are the streams with how their text is shown. On a terminal, and unless NoColour, the marks standard output prints are coloured (the person's "Marks only", 2026-10-22): ✗ red, ! yellow, ✓ green, and nothing else, no meaning resting on colour alone. Begin wraps the output.

func (Streams) WithProseTap added in v0.9.0

func (s Streams) WithProseTap(tap io.Writer) Streams

WithProseTap are the streams with what Prose writes read by tap as well, as it goes to Out, wrapped and coloured, and nothing Out is given raw: a test's reading of dockhand's own words, which a payload, as wide as it came, isn't held to (#94).

Directories

Path Synopsis
Package screen is the terminal a view draws on whole, as dockhand console does: the alternate screen, its input read in raw mode as keys, and a frame drawn in one write at the terminal's size.
Package screen is the terminal a view draws on whole, as dockhand console does: the alternate screen, its input read in raw mode as keys, and a frame drawn in one write at the terminal's size.

Jump to

Keyboard shortcuts

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