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

output

package
v0.0.0-...-97ff80a Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package output provides types related to formatted terminal output.

Index

Constants

View Source
const (
	EmojiFailure = "❌"
	EmojiWarning = "❗️"
	EmojiSuccess = "✅"
)

Standard emoji for use in output.

Variables

View Source
var (
	StyleReset   = &style{"\033[0m"}
	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)
)

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.

func (*Block) Close

func (b *Block) Close()

type Context

type Context interface {
	Writer

	Close()
}

type FancyLine

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

FancyLine is a formatted output line with an optional emoji and style.

func Line

func Line(emoji string, style Style, s string) FancyLine

Line creates a new FancyLine without a format string.

func Linef

func Linef(emoji string, style Style, format string, a ...interface{}) FancyLine

Line creates a new FancyLine with a format string. As with Writer, the arguments may include Style instances with the %s specifier.

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 NewOutput

func NewOutput(w io.Writer, opts OutputOpts) *Output

func (*Output) Block

func (o *Output) Block(summary FancyLine) *Block

Block starts a new block context. This should not be invoked if there is an active Pending or Progress context.

func (*Output) Pending

func (o *Output) Pending(message FancyLine) 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) Verbose

func (o *Output) Verbose(s string)

func (*Output) VerboseLine

func (o *Output) VerboseLine(line FancyLine)

func (*Output) Verbosef

func (o *Output) Verbosef(format string, args ...interface{})

func (*Output) Write

func (o *Output) Write(s string)

func (*Output) WriteLine

func (o *Output) WriteLine(line FancyLine)

func (*Output) Writef

func (o *Output) Writef(format string, args ...interface{})

type OutputOpts

type OutputOpts struct {
	// ForceColor ignores all terminal detection and enabled coloured output.
	ForceColor bool
	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)

	// SetValue updates the value for the given bar.
	SetValue(i int, v float64)
}

type ProgressBar

type ProgressBar struct {
	Label string
	Max   float64
	Value float64
	// contains filtered or unexported fields
}

type ProgressOpts

type ProgressOpts struct {
	PendingStyle Style
	SuccessEmoji string
	SuccessStyle Style
}

type ProgressWithStatusBars

type ProgressWithStatusBars interface {
	Progress

	StatusBarUpdatef(i int, format string, args ...interface{})
	StatusBarCompletef(i int, format string, args ...interface{})
	StatusBarFailf(i int, format string, args ...interface{})
	StatusBarResetf(i int, label, format string, args ...interface{})
}

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

func NewStatusBarWithLabel(label string) *StatusBar

func (*StatusBar) Completef

func (sb *StatusBar) Completef(format string, args ...interface{})

Completef sets the StatusBar to completed and updates its text.

func (*StatusBar) Failf

func (sb *StatusBar) Failf(format string, args ...interface{})

Failf sets the StatusBar to completed and failed and updates its text.

func (*StatusBar) Resetf

func (sb *StatusBar) Resetf(label, format string, args ...interface{})

Resetf sets the status of the StatusBar to incomplete and updates its label and text.

func (*StatusBar) Updatef

func (sb *StatusBar) Updatef(format string, args ...interface{})

Updatef updates the StatusBar's text.

type Style

type Style interface {
	fmt.Stringer
}

func Bg256Color

func Bg256Color(code int) Style

func CombineStyles

func CombineStyles(styles ...Style) Style

func Fg256Color

func Fg256Color(code int) Style

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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