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

console

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package console is what a command says on stderr: its notes, warnings and errors, each an entry of one log; with --verbose, a debug line for each request; and, while a command waits on a terminal, the live line of the wait. A note is the bare sentence, as a script reading stderr has always seen it; a warning and an error carry their tags. --log-format says them as JSON or logfmt instead, an entry a line, each stamped with its time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Underlying

func Underlying(stream io.Writer) io.Writer

Underlying is what stream writes straight through to: stream itself, unless it is a Stream.

Types

type Format

type Format int

Format is how the notes are written: as text, the sentences a person reads, or as JSON or logfmt, an entry a line for a log collector.

const (
	// Text writes a note as its sentence, and a warning and an error after
	// their tags.
	Text Format = iota
	// JSON writes each entry as one JSON object, stamped with its time.
	JSON
	// Logfmt writes each entry as one logfmt record, stamped with its time.
	Logfmt
)

func ParseFormat

func ParseFormat(name string) (Format, error)

ParseFormat is the format name names, as --log-format takes it.

func (Format) String

func (f Format) String() string

String is the format's name, as --log-format takes it.

type Look added in v0.12.0

type Look struct {
	ASCII bool
	Still bool
}

Look is how a live line is drawn: in plain ASCII, for a terminal or font without the Unicode marks — ui.ascii, or status --plain — and still, its mark held rather than turning, for anyone motion distracts — ui.motion reduce.

type Notes

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

Notes is what a command says on stderr, through one log: a note about what it did, a warning about what it could not, the error it ended with, and, when verbose, a debug line about how it went. Copies share the log they were made with.

func New

func New(stderr io.Writer, opts Options) Notes

New is the notes said on stderr as opts asks, colored as the terminal there and the variables opts reads allow.

func (Notes) Debug

func (n Notes) Debug(sentence string)

Debug says sentence as a debug line, which only --verbose shows.

func (Notes) DebugWriter

func (n Notes) DebugWriter() io.Writer

DebugWriter is the debug lines as a stream, for the request log's outlines: each line written to it is a debug line, its runs of spaces closed up and a leading RFC 3339 time dropped, since the log stamps its own entries where its format carries a time.

func (Notes) Fail

func (n Notes) Fail(err error, status int)

Fail says err, the error the command ended with, and, in a structured format, the status it exits with, for a script reading the log to act on.

func (Notes) Note

func (n Notes) Note(sentence string)

Note says sentence, a note about what the command did or found: on a pipe, the sentence alone. --quiet drops it.

func (Notes) To

func (n Notes) To(stream io.Writer) Notes

To is the notes said to stream instead, tagged and colored as they were: for a stream that passes on to the one they were made for, such as one that clears a line kept there first.

func (Notes) Unwatched

func (n Notes) Unwatched(wait func(Wait) error) error

Unwatched runs wait with no live line kept, for stderr that no person watches — a pipe, a file: what it does goes unsaid, and only what it says prints.

func (Notes) Warn

func (n Notes) Warn(sentence string)

Warn says sentence as a warning: the command goes on, but something it was asked for did not happen.

func (Notes) Watched

func (n Notes) Watched(look Look, wait func(Wait) error) error

Watched runs wait with a live line kept at the foot of stderr, a terminal a person watches, drawn as look asks: a mark, turning unless look holds it still, what the wait is doing, and, once it counts, a bar and how many of how many. Whatever is written to stderr while it runs, through these notes or a Stream they are said on, prints above the line, which is erased once the wait is over; the wait's error is Watched's.

The line is a Bubble Tea program, inline and taking no input, so it sends the terminal no query whose answer would reach the shell, and catching no signal, which the command's context hears instead. The wait runs as the program's first command, so nothing here starts a goroutine of its own, and the program ends when the wait does: a wait stopped by ctrl+c still says why before the line goes.

func (Notes) Writer

func (n Notes) Writer() io.Writer

Writer is the notes as a stream, for prose a command says on stderr beside an artifact on stdout, such as a preview printed beside the JSON a script reads: each line written to it is a note, a blank one too.

type Options

type Options struct {
	Format    Format
	Verbosity Verbosity
	Getenv    func(name string) string
}

Options are how a command's notes are said: in which format, how much of them, and Getenv, which reads the variables that decide color — NO_COLOR, CLICOLOR_FORCE, TERM and the like — which no note reads from the process itself. A nil Getenv reads none.

type Stream

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

Stream is stderr as a command says everything on it: each write passed straight through, until a wait's live line is drawn there, when each is printed above the line instead, so nothing said lands on it — a note, a request's debug line from another goroutine, or a line written by code that knows only stderr.

func NewStream

func NewStream(stderr io.Writer) *Stream

NewStream is stderr, written straight through until a wait's line is drawn.

func (*Stream) Write

func (s *Stream) Write(written []byte) (int, error)

Write writes written through, or, once a live line is drawn, prints it above the line. A blank write is printed as a space, since the program prints nothing for an empty line.

type Verbosity

type Verbosity int

Verbosity is how much the notes say.

const (
	// Normal says notes, warnings and errors.
	Normal Verbosity = iota
	// Quiet says warnings and errors alone.
	Quiet
	// Verbose says debug lines too.
	Verbose
)

type Wait

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

Wait is what a wait a person may be watching tells its live line — what it is doing, and how much of it is done — and where it says what it finds while the line is kept: its notes, and what it prints above the line.

func (Wait) Above

func (w Wait) Above() io.Writer

Above is a stream printed above the live line, on stderr, a write at a time; with no line kept, it is the notes' stream, each line a note.

func (Wait) Counted

func (w Wait) Counted(done, total int)

Counted says how much of the wait is done: done of total, which the live line shows as a bar and in words.

func (Wait) Doing

func (w Wait) Doing(what string)

Doing says what the wait is doing, the words of its live line.

func (Wait) Notes

func (w Wait) Notes() Notes

Notes are the notes the wait says, printed above the live line while it is kept.

Jump to

Keyboard shortcuts

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