Documentation
¶
Overview ¶
Package output provides types related to formatted terminal output.
Index ¶
- Constants
- Variables
- type Block
- type Context
- type FancyLine
- type Output
- func (o *Output) Block(summary FancyLine) *Block
- func (o *Output) Pending(message FancyLine) Pending
- func (o *Output) Progress(bars []ProgressBar, opts *ProgressOpts) Progress
- func (o *Output) ProgressWithStatusBars(bars []ProgressBar, statusBars []*StatusBar, opts *ProgressOpts) ProgressWithStatusBars
- func (o *Output) Verbose(s string)
- func (o *Output) VerboseLine(line FancyLine)
- func (o *Output) Verbosef(format string, args ...interface{})
- func (o *Output) Write(s string)
- func (o *Output) WriteLine(line FancyLine)
- func (o *Output) Writef(format string, args ...interface{})
- type OutputOpts
- type Pending
- type Progress
- type ProgressBar
- type ProgressOpts
- type ProgressWithStatusBars
- type StatusBar
- type Style
- type Writer
Constants ¶
const ( EmojiFailure = "❌" EmojiWarning = "❗️" EmojiSuccess = "✅" )
Standard emoji for use in output.
Variables ¶
var ( StyleReset = &style{"\033[0m"} StyleLogo = Fg256Color(57) StylePending = Fg256Color(4) StyleWarning = Fg256Color(124) StyleSuccess = Fg256Color(2) StyleBold = &style{"\033[1m"} StyleItalic = &style{"\033[3m"} StyleUnderline = &style{"\033[4m"} // Search-specific colors. StyleSearchQuery = Fg256Color(68) StyleSearchBorder = Fg256Color(239) StyleSearchLink = Fg256Color(237) StyleSearchRepository = Fg256Color(23) StyleSearchFilename = Fg256Color(69) StyleSearchMatch = CombineStyles(Fg256Color(0), Bg256Color(11)) StyleSearchLineNumbers = Fg256Color(69) StyleSearchCommitAuthor = Fg256Color(2) StyleSearchCommitSubject = Fg256Color(68) StyleSearchCommitDate = Fg256Color(23) // Search alert specific colors. StyleSearchAlertTitle = Fg256Color(124) StyleSearchAlertDescription = Fg256Color(124) StyleSearchAlertProposedTitle = &style{""} StyleSearchAlertProposedQuery = Fg256Color(69) StyleSearchAlertProposedDescription = &style{""} StyleLinesDeleted = Fg256Color(196) StyleLinesAdded = Fg256Color(2) )
var DefaultProgressTTYOpts = &ProgressOpts{ SuccessEmoji: "\u2705", SuccessStyle: StyleSuccess, PendingStyle: StylePending, }
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
*Output
// contains filtered or unexported fields
}
Block represents a block of output with one status line, and then zero or more lines of output nested under the status line.
type FancyLine ¶
type FancyLine struct {
// contains filtered or unexported fields
}
FancyLine is a formatted output line with an optional emoji and style.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output encapsulates a standard set of functionality for commands that need to output human-readable data.
Output is not appropriate for machine-readable data, such as JSON.
func (*Output) Block ¶
Block starts a new block context. This should not be invoked if there is an active Pending or Progress context.
func (*Output) Pending ¶
Pending sets up a new pending context. This should not be invoked if there is an active Block or Progress context. The emoji in the message will be ignored, as Pending will render its own spinner.
A Pending instance must be disposed of via the Complete or Destroy methods.
func (*Output) Progress ¶
func (o *Output) Progress(bars []ProgressBar, opts *ProgressOpts) Progress
Progress sets up a new progress bar context. This should not be invoked if there is an active Block or Pending context.
A Progress instance must be disposed of via the Complete or Destroy methods.
func (*Output) ProgressWithStatusBars ¶
func (o *Output) ProgressWithStatusBars(bars []ProgressBar, statusBars []*StatusBar, opts *ProgressOpts) ProgressWithStatusBars
ProgressWithStatusBars sets up a new progress bar context with StatusBar contexts. This should not be invoked if there is an active Block or Pending context.
A Progress instance must be disposed of via the Complete or Destroy methods.
func (*Output) VerboseLine ¶
type OutputOpts ¶
type OutputOpts struct {
// ForceColor ignores all terminal detection and enabled coloured output.
ForceColor bool
// ForceTTY ignores all terminal detection and enables TTY output.
ForceTTY bool
// ForceHeight ignores all terminal detection and sets the height to this value.
ForceHeight int
// ForceWidth ignores all terminal detection and sets the width to this value.
ForceWidth int
Verbose bool
}
type Pending ¶
type Pending interface {
// Anything sent to the Writer methods will be displayed as a log message
// above the pending line.
Context
// Update and Updatef change the message shown after the spinner.
Update(s string)
Updatef(format string, args ...interface{})
// Complete stops the spinner and replaces the pending line with the given
// message.
Complete(message FancyLine)
// Destroy stops the spinner and removes the pending line.
Destroy()
}
type Progress ¶
type Progress interface {
Context
// Complete stops the set of progress bars and marks them all as completed.
Complete()
// Destroy stops the set of progress bars and clears them from the
// terminal.
Destroy()
// SetLabel updates the label for the given bar.
SetLabel(i int, label string)
// SetLabelAndRecalc updates the label for the given bar and recalculates
// the maximum width of the labels.
SetLabelAndRecalc(i int, label string)
// SetValue updates the value for the given bar.
SetValue(i int, v float64)
}
type ProgressBar ¶
type ProgressOpts ¶
type ProgressOpts struct {
PendingStyle Style
SuccessEmoji string
SuccessStyle Style
// NoSpinner turns of the automatic updating of the progress bar and
// spinner in a background goroutine.
// Used for testing only!
NoSpinner bool
}
func (*ProgressOpts) WithNoSpinner ¶
func (opt *ProgressOpts) WithNoSpinner(noSpinner bool) *ProgressOpts
type ProgressWithStatusBars ¶
type StatusBar ¶
type StatusBar struct {
// contains filtered or unexported fields
}
StatusBar is a sub-element of a progress bar that displays the current status of a process.
func NewStatusBar ¶
func NewStatusBar() *StatusBar
func NewStatusBarWithLabel ¶
type Writer ¶
type Writer interface {
// These methods only write the given message if verbose mode is enabled.
Verbose(s string)
Verbosef(format string, args ...interface{})
VerboseLine(line FancyLine)
// These methods write their messages unconditionally.
Write(s string)
Writef(format string, args ...interface{})
WriteLine(line FancyLine)
}
Writer defines a common set of methods that can be used to output status information.
Note that the *f methods can accept Style instances in their arguments with the %s format specifier: if given, the detected colour support will be respected when outputting.