Documentation
¶
Overview ¶
Package display shows the progress of a command on its standard error, from the events of its progress.Bus: the live tree, a few rows at the bottom of a terminal that show the work under way and what of it failed; the counter, one line there that says how far the work has got; plain lines, one for each thing worth a line, for a log as much as a terminal; and the summary a display leaves behind once the command has ended.
The tree and the counter own the bottom rows of the terminal, the region, and nothing else. The command's own output goes to the terminal through the writers of the Terminal, which take the region off before anything else is written, and let it back only once what was written ended a line, so that a question waiting for its answer is never drawn over. The lines a display leaves for good, plain lines and the tree's finished steps, go out through the Terminal too: above the region, never into a line the command has not ended, and ahead of whatever the command writes after the events they tell of. A display leaves the terminal altogether while a question is asked, through progress.Suspend, and never hides the cursor, so a process killed while it draws leaves a terminal that works, at worst with the rows of its last frame on it.
Lines from goroutines that run beside the command, the stack of a panic a pool's worker recovered from or a log line, go through the Terminal's Lines writers, which hold them, whole lines only, while a question is asked or the command has a line open, so that none lands inside the question, and write them above the region once they may.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a display of one line, which says for each step whose targets are counted, the roots of a progress.Tally, how far it has got, and how long the command has run:
power on · batch 3/60 · 17/480 · 1 failed · 8 running · 0:41
Steps under way side by side each get a segment of their own, split by " | ". While no counted step is under way the line names the innermost step that is, or the command. Hidden steps are not shown.
A Counter is a progress.Sink and a progress.Suspender. Its methods are safe for concurrent use.
func NewCounter ¶
func NewCounter(term *Terminal, o CounterOptions) *Counter
NewCounter returns a counter that draws on term once Start is called. The time on its line is counted from now.
func (*Counter) Close ¶
func (c *Counter) Close()
Close stops the drawing and takes the line off the terminal. Closing a closed Counter does nothing.
func (*Counter) Draw ¶
func (c *Counter) Draw()
Draw draws the line as the work stands now, unless the command has run for less than a second.
type CounterOptions ¶
type CounterOptions struct {
// Now is the clock the time on the line is read from; nil is time.Now.
Now func() time.Time
// ASCII splits the parts of the line with " - " rather than " · ",
// for a terminal whose locale is not UTF-8.
ASCII bool
}
CounterOptions configure a Counter.
type Plain ¶
type Plain struct {
// contains filtered or unexported fields
}
Plain is a display of plain lines, one for each thing worth a line, with the time since the command started in front and no escape codes, for a log as much as for a terminal:
[0:00] bmc power › power off: start, 480 hosts, 8 at a time [0:03] bmc power › power off › exe0007 failed (transport): exe0007.mgmt: dial tcp: i/o timeout [0:10] bmc power › power off: 312/480 done, 1 failed, 8 running, 160 queued [0:18] bmc power › power off: failed in 18s: 478 ok, 2 failed
A line names the span it tells of by the path to it from the command, its parts joined by "›", or by ">" with PlainOptions.ASCII. It is written as a step or a batch starts and ends, as a pause of a known length starts, and as a wait fails or is interrupted; for each target that fails, once; and, every ten seconds, for each counted step under way, a root of a progress.Tally, with how far it has got. Hidden spans and calls get no line, and neither do the lines of output the work prints: exec prints them at the end, and the machine formats carry them whole.
The lines go out through the Terminal: ahead of whatever the command writes after the events they tell of, never into a line the command has not ended, and not while a question is asked. A Plain is a progress.Sink and a progress.Suspender; its methods are safe for concurrent use.
func NewPlain ¶
func NewPlain(term *Terminal, o PlainOptions) *Plain
NewPlain returns a display of plain lines on term, which counts the time in front of its lines from now.
func (*Plain) Close ¶
func (p *Plain) Close()
Close stops the writing Start began, and writes what is left. Closing a closed Plain does nothing.
func (*Plain) Draw ¶
func (p *Plain) Draw()
Draw writes the lines not yet written and the heartbeats due now, where the terminal lets it.
type PlainOptions ¶
type PlainOptions struct {
// Now is the clock the heartbeats are read from, and the time in front
// of a line counted from; nil is time.Now. The Bus's clock should be
// the same.
Now func() time.Time
// ASCII writes the path to a span with ">" between its parts, for a
// locale that is not UTF-8, rather than "›".
ASCII bool
// Noun says how many targets a step or a batch expects, n of them,
// in the line that starts it: "480 hosts"; nil is "1 host" and "%d
// hosts".
Noun func(n int) string
}
PlainOptions configure a Plain.
type Summary ¶
type Summary struct {
// contains filtered or unexported fields
}
Summary is the one line a display leaves behind once the command has ended: how the command ended, how long it ran, and how many of the things it worked on ended how.
provision reinstall: failed in 18m03s: 478 ok, 2 failed
How the command ended comes first, since the counts need not say it: a command that fails in a step that counts nothing, or stops before the steps that would have counted the rest, can have counted nothing but ok. Each node, or whatever else a target names, counts once, as the worst of the ways its targets ended below the counted steps: failed, then canceled, then skipped, then ok, so that a node reset after its boot override was set is one node, not two. A batch left out, after one that failed or for an interrupt, counts as its Total. A command that counted no targets says only how it ended. The line says nothing of why a target failed: the command's error says that, once, after it.
A Summary is a progress.Sink; its methods are safe for concurrent use.
func (*Summary) Line ¶
Line returns the summary once the command has ended, if it is worth a line: when the command ran for a second or longer, as long as a display takes to show itself, so that a command done within its first second leaves standard error as it would without a display, failed targets or not; its error says what failed. Otherwise, and before the command has ended, it is "".
type Terminal ¶
type Terminal struct {
// PanicLog receives the stack of a display that panicked while it
// drew, the front end's diagnostics; nil is the terminal itself.
PanicLog io.Writer
// Program names the program in the line that says a display stopped,
// "clusterctl: …", so that it is not read as the command's own; empty
// leaves the name out.
Program string
// Foreground, when it is set, reports whether the process is the job
// in the terminal's foreground. A job in the background draws nothing:
// the shell's prompt and what is typed at it are on the rows a frame
// would erase.
Foreground func() bool
// contains filtered or unexported fields
}
Terminal is the terminal a display draws on, shared with the command's own output. It is safe for concurrent use.
func NewTerminal ¶
NewTerminal returns the terminal w is, whose width and height size tells; nil size is a terminal 80 columns wide.
func (*Terminal) Lines ¶
Lines returns a writer to w, a stream that shows on the terminal, for lines that come from beside the command, from goroutines that may write at any moment: the stack of a panic a pool's worker recovered from, or a log line. It writes whole lines only: at once where no region is drawn, and otherwise with the next frame, above it. It holds them while a question is asked, between progress.Suspend and its resume, and while the command has a line open, such as a question it asks itself; the next frame, the write that ends the open line, the resume and Close write them, in order, and so does a write of the command's, before its own bytes. A line that does not end waits for its end, and Close ends it. What waits is bounded, 256 KiB: a line past that is left out, and a line written with the others says how many were.
w must not be a writer of the Terminal's own. What is written is not changed, and Write reports it all written: the lines are a courtesy.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is the live display of a terminal: a few rows at its bottom, the region, that show the work under way as a tree, redrawn as it goes on, and a line above them for each step once it has finished:
✓ configuring the network boot 2.3s
provision reinstall · 4:12
setting the machines to boot from the network once 312/480 · 1 failed · 8 running · 159 queued
✗ exe0007 transport: {}: dial tcp: i/o timeout
▸ exe0313 4s PATCH /redfish/v1/Systems/1
▸ exe0314 3s GET /redfish/v1/Systems/1
… 6 more running
✓ exe[0001-0006,0008-0312]
The command heads the region, and each step, batch and wait under way has a row, indented under the span it is part of; a step says how many of its targets are done, of how many, and how they stand, as a progress.Tally counts them. The targets of a step are folded: those that ended well into one node set, those that failed into one row for each class and error they share, with a target's own name read as {}, those interrupted and those left out into one row each. Those still queued are only counted, and those running are listed, the longest running first, with how long they have run, against the bound of the request they wait for when it has one, and what that request is, or the last line of output for a step that shows lines. A pause counts down.
A hidden span is drawn only once it has run for a second, and a line is left for it only when it failed or took that long. A span that ends well within a tenth of a second, with nothing drawn below it, is done without a row or a line; one that failed keeps its line however quickly it did, and so does one that had something drawn below it. A step with no name is no row: what is below it is drawn in its place.
The region is at most a third of the terminal's rows, and six rows on a smaller one; rows that do not fit are cut, the running targets first, each list down to a row that says how many it leaves out, and every row is cut to the width, so that none wraps. The tree is drawn at most ten times a second, from a second after it was made: a command done by then never shows one, nor the lines of its steps. On a terminal of fewer than 8 rows or 40 columns, as it says at each frame, the counter's line is drawn instead. Once the command has been interrupted, its row says so, with how many targets will stop and how many will not start.
A Tree is a progress.Sink, a progress.LineSink and a progress.Suspender. Its methods are safe for concurrent use.
func NewTree ¶
func NewTree(term *Terminal, o TreeOptions) *Tree
NewTree returns a tree that draws on term once Start is called. The time on its first row is counted from now.
func (*Tree) Close ¶
func (t *Tree) Close()
Close stops the drawing, takes the region off the terminal and writes the lines not yet written, if the tree was ever drawn. Closing a closed Tree does nothing.
func (*Tree) Draw ¶
func (t *Tree) Draw()
Draw draws a frame as the work stands now, with the lines of the steps that finished above it, unless the command has run for less than a second. The terminal writes nothing for a frame that reads as the one before.
func (*Tree) Start ¶
func (t *Tree) Start()
Start draws the tree every 100ms, from a second after it was made, until Close.
func (*Tree) Suspend ¶
func (t *Tree) Suspend()
Suspend takes the region off the terminal, once the lines not yet written are, until Resume.
func (*Tree) WantsLines ¶
WantsLines asks for the lines of output of a step that shows them, the last of which a running target's row shows.
type TreeOptions ¶
type TreeOptions struct {
// Now is the clock the times of the tree are read from; nil is
// time.Now. The Bus's clock should be the same.
Now func() time.Time
// ASCII draws with ASCII marks alone, for a terminal whose locale is
// not UTF-8.
ASCII bool
// Interrupted is closed once the command has been interrupted; nil is
// a command that never is.
Interrupted <-chan struct{}
}
TreeOptions configure a Tree.