pterm

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2020 License: MIT Imports: 10 Imported by: 1,712

README

:computer: PTerm | Pretty Terminal

A golang module to print pretty text

Latest Release Stars Forks Issues
Downloads
PTerm Documentation Dops


⚠ NOTICE

PTerm is currently under development. It is very likely that not all things will remain as they are at the moment. However, PTerm is still functional. The versioning of PTerm follows the SemVer guidelines. Breaking Changes are explicitly mentioned in the changelogs and the version will be increased accordingly. Everybody is welcome to improve PTerm, whether by making suggestions or pull requests. Thanks <3

If you want to wait for a stable release, make sure to star the project and follow it, to get notified when we release v1.0.0 (stable) 🚀

📦 Installation

To make PTerm available in your project, you can run the following command.
Make sure to run this command inside your project, when you're using go modules 😉

go get github.com/pterm/pterm

📝 Documentation

To view the official documentation of the latest release, you can go to the automatically generated page of pkg.go.dev This documentation is very technical and includes every method that can be used in PTerm.

For an easy start we recommend that you take a look at the examples section. Here you can see pretty much every feature of PTerm with its source code. The animations of the examples are automatically updated as soon as something changes in PTerm.

Have fun exploring this project 🚀

❤ Contributing

If you have found a bug or want to suggest a feature, you can do so here by opening a new issue.

If you want to contribute to the development of PTerm, you are very welcome to do so. Our contribution guidelines can be found here.

🧪 Examples

demo

Animation

SHOW SOURCE
package main

import (
	"strconv"
	"strings"
	"time"

	"github.com/pterm/pterm"
)

var (
	fakeInstallList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+
		"pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ")
)

func main() {
	// Change this to time.Millisecond*200 to speed up the demo.
	// Useful when debugging.
	const second = time.Second

	pterm.Header.SetBackgroundStyle(pterm.BgLightBlue).SetMargin(10).Println("PTDP - PTerm Demo Program")
	pterm.Info.Println("This animation was generated with the latest version of PTerm!" +
		"\nPTerm works on nearly every terminal and operating system." +
		"\nIt's super easy to use!" +
		"\nIf you want, you can customize everything :)" +
		"\nYou can see the code of this demo in the " + pterm.LightMagenta("./_examples/demo") + " directory." +
		"\n" +
		"\nThis demo was updated at: " + pterm.Green(time.Now().Format("02 Jan 2006 - 15:04:05 MST")))
	pterm.Println()

	introSpinner := pterm.DefaultSpinner.SetRemoveWhenDone(true).Start("Waiting for 15 seconds...")
	time.Sleep(second)
	for i := 14; i > 0; i-- {
		if i > 1 {
			introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " seconds...")
		} else {
			introSpinner.UpdateText("Waiting for " + strconv.Itoa(i) + " second...")
		}
		time.Sleep(second)
	}
	introSpinner.Stop()

	clear()

	pterm.Header.SetBackgroundStyle(pterm.BgLightBlue).SetMargin(10).Println("Pseudo Application created with PTerm")

	time.Sleep(second)

	setupSpinner := pterm.DefaultSpinner.Start("Fetching pseudo install list...")
	time.Sleep(second * 4)
	setupSpinner.Success()

	installSpinner := pterm.DefaultSpinner.Start("Installing...")
	for _, s := range fakeInstallList {
		installSpinner.UpdateText("Installing " + s + "...")
		time.Sleep(second)
	}
	installSpinner.Success("Installed all pseudo programs!")
}

func clear() {
	print("\033[H\033[2J")
}

override-default-printer

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	pterm.Error.Println("This is the default Error")

	pterm.Error.Prefix = pterm.Prefix{
		Text:  "OVERRIDE",
		Style: pterm.Style{pterm.BgCyan, pterm.FgRed},
	}

	pterm.Error.Println("This is the default Error after the prefix was overridden")
}

print-header

Animation

SHOW SOURCE
package main

import (
	"time"

	"github.com/pterm/pterm"
)

func main() {
	tick := time.Tick(time.Second * 2)

	// Print with the default HeaderPrinter
	pterm.Header.Println("This is the default header style")

	<-tick // Wait

	// Print a custom header
	pterm.Header.SetFullWidth().SetTextStyle(pterm.FgDarkGray).SetBackgroundStyle(pterm.BgLightMagenta).Println("Hello, World!")

	<-tick // Wait

	// Create a custom HeaderPrinter
	customHeaderPrinter := pterm.HeaderPrinter{
		TextStyle:       pterm.Style{pterm.FgLightRed},
		BackgroundStyle: pterm.Style{pterm.BgGreen},
		Margin:          15,
	}
	// Use custom Header printer
	customHeaderPrinter.Println("This is a custom header.")
}

print-with-color

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Simple Println with different colored words.
	pterm.Println(pterm.Red("Hello, ") + pterm.Green("World") + pterm.Cyan("!"))
	pterm.Println(pterm.Red("Even " + pterm.Cyan("nested ") + pterm.Green("colors ") + "are supported!"))
}

progressbar

Animation

SHOW SOURCE
package main

import (
	"strings"
	"time"

	"github.com/pterm/pterm"
)

var fakeInstallList = strings.Split("pseudo-excel pseudo-photoshop pseudo-chrome pseudo-outlook pseudo-explorer "+
	"pseudo-dops pseudo-git pseudo-vsc pseudo-intellij pseudo-minecraft pseudo-scoop pseudo-chocolatey", " ")

var vki int

func main() {
	p := pterm.DefaultProgressbar.SetTotal(2000).SetTitle("Downloading stuff").Start()

	for i := 0; i < p.Total; i++ {
		p.Increment()
		time.Sleep(time.Millisecond * 5)
		if i%200 == 0 {
			p.Title = "Downloading " + fakeInstallList[vki]
			vki++
		}
	}
}

spinner

Animation

SHOW SOURCE
package main

import (
	"time"

	"github.com/pterm/pterm"
)

func main() {
	spinnerSuccess := pterm.DefaultSpinner.Start("Doing something important... (will succeed)")

	time.Sleep(time.Second * 3) // Simulate 3 seconds of processing something

	spinnerSuccess.Success()

	spinnerWarning := pterm.DefaultSpinner.Start("Doing something important... (will warn)")

	time.Sleep(time.Second * 3) // Simulate 3 seconds of processing something

	spinnerWarning.Warning()

	spinnerFail := pterm.DefaultSpinner.Start("Doing something important... (will fail)")

	time.Sleep(time.Second * 3) // Simulate 3 seconds of processing something

	spinnerFail.Fail()

	spinnerLiveText := pterm.DefaultSpinner.Start("Doing a lot of stuff...")

	time.Sleep(time.Second * 2)

	spinnerLiveText.UpdateText("It's really much")

	time.Sleep(time.Second * 2)

	spinnerLiveText.UpdateText("We're nearly done!")

	time.Sleep(time.Second * 2)

	spinnerLiveText.Success("Finally!")
}

Documentation

Index

Constants

View Source
const Version = "v0.2.1" // <---VERSION---> | This comment is for our CI System. Do not edit it.

Version returns the current version of PTerm in SemVer format.

Variables

View Source
var (
	// Sprint formats using the default formats for its operands and returns the resulting string.
	// Spaces are added between operands when neither is a string.
	Sprint = color.Sprint

	// Sprintf formats according to a format specifier and returns the resulting string.
	Sprintf = color.Sprintf

	// Println formats using the default formats for its operands and writes to standard output.
	// Spaces are always added between operands and a newline is appended.
	// It returns the number of bytes written and any write error encountered.
	Println = color.Println

	// Printf formats according to a format specifier and writes to standard output.
	// It returns the number of bytes written and any write error encountered.
	Printf = color.Printf

	// Print formats using the default formats for its operands and writes to standard output.
	// Spaces are added between operands when neither is a string.
	// It returns the number of bytes written and any write error encountered.
	Print = color.Print

	// Fprint formats using the default formats for its operands and writes to w.
	// Spaces are added between operands when neither is a string.
	// It returns the number of bytes written and any write error encountered.
	Fprint = color.Fprint

	// Fprintln formats using the default formats for its operands and writes to w.
	// Spaces are always added between operands and a newline is appended.
	// It returns the number of bytes written and any write error encountered.
	Fprintln = color.Fprintln

	// RemoveColors removes color codes from a string.
	RemoveColors = color.ClearCode
)
View Source
var (
	// Red is an alias for FgRed.Sprint.
	Red = FgRed.Sprint
	// Cyan is an alias for FgCyan.Sprint.
	Cyan = FgCyan.Sprint
	// Gray is an alias for FgGray.Sprint.
	Gray = FgGray.Sprint
	// Blue is an alias for FgBlue.Sprint.
	Blue = FgBlue.Sprint
	// Black is an alias for FgBlack.Sprint.
	Black = FgBlack.Sprint
	// Green is an alias for FgGreen.Sprint.
	Green = FgGreen.Sprint
	// White is an alias for FgWhite.Sprint.
	White = FgWhite.Sprint
	// Yellow is an alias for FgYellow.Sprint.
	Yellow = FgYellow.Sprint
	// Magenta is an alias for FgMagenta.Sprint.
	Magenta = FgMagenta.Sprint

	// Normal is an alias for FgDefault.Sprint.
	Normal = FgDefault.Sprint

	// LightRed is a shortcut for FgLightRed.Sprint.
	LightRed = FgLightRed.Sprint
	// LightCyan is a shortcut for FgLightCyan.Sprint.
	LightCyan = FgLightCyan.Sprint
	// LightBlue is a shortcut for FgLightBlue.Sprint.
	LightBlue = FgLightBlue.Sprint
	// LightGreen is a shortcut for FgLightGreen.Sprint.
	LightGreen = FgLightGreen.Sprint
	// LightWhite is a shortcut for FgLightWhite.Sprint.
	LightWhite = FgLightWhite.Sprint
	// LightYellow is a shortcut for FgLightYellow.Sprint.
	LightYellow = FgLightYellow.Sprint
	// LightMagenta is a shortcut for FgLightMagenta.Sprint.
	LightMagenta = FgLightMagenta.Sprint
)
View Source
var (
	// Info returns a PrefixPrinter, which can be used to print text with an "info" Prefix.
	Info = PrefixPrinter{
		Prefix: Prefix{
			Text:  "INFO",
			Style: NewStyle(FgBlack, BgCyan),
		},
		MessageStyle: NewStyle(FgLightCyan),
	}

	// Warning returns a PrefixPrinter, which can be used to print text with a "warning" Prefix.
	Warning = PrefixPrinter{
		Prefix: Prefix{
			Text:  "WARNING",
			Style: NewStyle(FgBlack, BgYellow),
		},
		MessageStyle: NewStyle(FgYellow),
	}

	// Success returns a PrefixPrinter, which can be used to print text with a "success" Prefix.
	Success = PrefixPrinter{
		Prefix: Prefix{
			Text:  "SUCCESS",
			Style: NewStyle(FgBlack, BgGreen),
		},
		MessageStyle: NewStyle(FgGreen),
	}

	// Error returns a PrefixPrinter, which can be used to print text with an "error" Prefix.
	Error = PrefixPrinter{
		Prefix: Prefix{
			Text:  "ERROR",
			Style: NewStyle(FgBlack, BgLightRed),
		},
		MessageStyle: NewStyle(FgLightRed),
	}

	// Description returns a PrefixPrinter, which can be used to print text with a "description" Prefix.
	Description = PrefixPrinter{
		Prefix: Prefix{
			Text:  "Description",
			Style: Style{FgLightWhite, BgDarkGray},
		},
		MessageStyle: Style{FgLightWhite},
	}
)
View Source
var (
	// DefaultProgressbar is the default progressbar.
	DefaultProgressbar = Progressbar{
		Total:                     100,
		LineCharacter:             "█",
		LastCharacter:             "█",
		ElapsedTimeRoundingFactor: time.Second,
		BarStyle:                  Style{FgLightCyan},
		TitleStyle:                Style{FgCyan},
		ShowTitle:                 true,
		ShowCount:                 true,
		ShowPercentage:            true,
		ShowElapsedTime:           true,
	}
)
View Source
var DefaultSpinner = Spinner{
	Sequence:       []string{"▀ ", " ▀", " ▄", "▄ "},
	Style:          Style{FgLightCyan},
	Delay:          time.Millisecond * 200,
	MessageStyle:   Style{FgLightWhite},
	SuccessPrinter: Success,
	FailPrinter:    Error,
	WarningPrinter: Warning,
}

DefaultSpinner is the default spinner.

View Source
var (
	// ErrTerminalSizeNotDetectable - the terminal size can not be detected and the fallback values are used.
	ErrTerminalSizeNotDetectable = errors.New("terminal size could not be detected - using fallback value")
)
View Source
var FallbackTerminalHeight = 10

FallbackTerminalHeight is the value used for GetTerminalHeight, if the actual height can not be detected You can override that value if necessary.

View Source
var FallbackTerminalWidth = 80

FallbackTerminalWidth is the value used for GetTerminalWidth, if the actual width can not be detected You can override that value if necessary.

View Source
var (
	// GrayBoxStyle wraps text in a gray box.
	GrayBoxStyle = NewStyle(BgGray, FgLightWhite)
)
View Source
var (
	// Header returns the printer for a default header text.
	// Defaults to LightWhite, Bold Text and a Gray Header background.
	Header = HeaderPrinter{
		TextStyle:       Style{FgLightWhite, Bold},
		BackgroundStyle: Style{BgGray},
		Margin:          5,
	}
)

Functions

func Fprinto added in v0.1.0

func Fprinto(w io.Writer, a ...interface{})

Fprinto prints Printo to a custom writer.

func GetTerminalHeight added in v0.1.0

func GetTerminalHeight() int

GetTerminalHeight returns the terminal height of the active terminal.

func GetTerminalSize added in v0.1.0

func GetTerminalSize() (width, height int, err error)

GetTerminalSize returns the width and the height of the active terminal.

func GetTerminalWidth added in v0.1.0

func GetTerminalWidth() int

GetTerminalWidth returns the terminal width of the active terminal.

func Printo added in v0.1.0

func Printo(a ...interface{})

Printo overrides the current line in a terminal. If the current line is empty, the text will be printed like with pterm.Print. To create a new line, which Example: pterm.Printo("Hello, World") time.Sleep(time.Second) pterm.Oprint("Hello, Earth!")

func Sprintln added in v0.2.0

func Sprintln(a ...interface{}) string

Sprintln returns what Println would print to the terminal.

Types

type Color

type Color uint8

Color is a number which will be used to color strings in the terminal.

const (
	FgBlack Color = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
	// FgDefault revert default FG.
	FgDefault Color = 39
)

Foreground colors. basic foreground colors 30 - 37.

const (
	FgDarkGray Color = iota + 90
	FgLightRed
	FgLightGreen
	FgLightYellow
	FgLightBlue
	FgLightMagenta
	FgLightCyan
	FgLightWhite
	// FgGray is an alias of FgDarkGray.
	FgGray Color = 90
)

Extra foreground color 90 - 97.

const (
	BgBlack Color = iota + 40
	BgRed
	BgGreen
	BgYellow // BgBrown like yellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
	// BgDefault reverts to the default background.
	BgDefault Color = 49
)

Background colors. basic background colors 40 - 47.

const (
	BgDarkGray Color = iota + 100
	BgLightRed
	BgLightGreen
	BgLightYellow
	BgLightBlue
	BgLightMagenta
	BgLightCyan
	BgLightWhite
	// BgGray is an alias of BgDarkGray.
	BgGray Color = 100
)

Extra background color 100 - 107.

const (
	Reset Color = iota
	Bold
	Fuzzy
	Italic
	Underscore
	Blink
	FastBlink
	Reverse
	Concealed
	Strikethrough
)

Option settings.

func (Color) Print

func (c Color) Print(a ...interface{})

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Printf

func (c Color) Printf(format string, a ...interface{})

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Println

func (c Color) Println(a ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Color.

func (Color) Sprint

func (c Color) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string. Input will be colored with the parent Color.

func (Color) Sprintf

func (c Color) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Color.

func (Color) Sprintln

func (c Color) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Color.

func (Color) String

func (c Color) String() string

String converts the color to a string. eg "35".

type GenericPrinter

type GenericPrinter interface {
	// Sprint formats using the default formats for its operands and returns the resulting string.
	// Spaces are added between operands when neither is a string.
	Sprint(a ...interface{}) string

	// Sprintln formats using the default formats for its operands and returns the resulting string.
	// Spaces are always added between operands and a newline is appended.
	Sprintln(a ...interface{}) string

	// Sprintf formats according to a format specifier and returns the resulting string.
	Sprintf(format string, a ...interface{}) string

	// Print formats using the default formats for its operands and writes to standard output.
	// Spaces are added between operands when neither is a string.
	// It returns the number of bytes written and any write error encountered.
	Print(a ...interface{}) GenericPrinter

	// Println formats using the default formats for its operands and writes to standard output.
	// Spaces are always added between operands and a newline is appended.
	// It returns the number of bytes written and any write error encountered.
	Println(a ...interface{}) GenericPrinter

	// Printf formats according to a format specifier and writes to standard output.
	// It returns the number of bytes written and any write error encountered.
	Printf(format string, a ...interface{}) GenericPrinter
}

GenericPrinter contains methods to print formatted text to the console or return it as a string.

type HeaderPrinter added in v0.0.1

type HeaderPrinter struct {
	TextStyle       Style
	BackgroundStyle Style
	Margin          int
	FullWidth       bool
}

HeaderPrinter contains the data used to craft a header. A header is printed as a big box with text in it. Can be used as title screens or section separator.

func (HeaderPrinter) Print added in v0.0.1

func (p HeaderPrinter) Print(a ...interface{}) GenericPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (HeaderPrinter) Printf added in v0.0.1

func (p HeaderPrinter) Printf(format string, a ...interface{}) GenericPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (HeaderPrinter) Println added in v0.0.1

func (p HeaderPrinter) Println(a ...interface{}) GenericPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (HeaderPrinter) SetBackgroundStyle added in v0.2.0

func (p HeaderPrinter) SetBackgroundStyle(colors ...Color) *HeaderPrinter

SetBackgroundStyle changes the background styling of the header.

func (HeaderPrinter) SetFullWidth added in v0.2.0

func (p HeaderPrinter) SetFullWidth() *HeaderPrinter

SetFullWidth enables full width on a HeaderPrinter.

func (HeaderPrinter) SetMargin added in v0.2.0

func (p HeaderPrinter) SetMargin(margin int) *HeaderPrinter

SetMargin changes the background styling of the header.

func (HeaderPrinter) SetTextStyle added in v0.2.0

func (p HeaderPrinter) SetTextStyle(colors ...Color) *HeaderPrinter

SetTextStyle changes the text styling of the header.

func (HeaderPrinter) Sprint added in v0.0.1

func (p HeaderPrinter) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.

func (HeaderPrinter) Sprintf added in v0.0.1

func (p HeaderPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (HeaderPrinter) Sprintln added in v0.0.1

func (p HeaderPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

type Prefix

type Prefix struct {
	Text  string
	Style Style
}

Prefix contains the data used as the beginning of a printed text via a PrefixPrinter.

type PrefixPrinter

type PrefixPrinter struct {
	Prefix       Prefix
	Scope        Scope
	MessageStyle Style
	Fatal        bool
}

PrefixPrinter is the printer used to print a Prefix.

func (PrefixPrinter) GetFormattedPrefix

func (p PrefixPrinter) GetFormattedPrefix() string

GetFormattedPrefix returns the Prefix as a styled text string.

func (PrefixPrinter) Print

func (p PrefixPrinter) Print(a ...interface{}) GenericPrinter

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (PrefixPrinter) Printf

func (p PrefixPrinter) Printf(format string, a ...interface{}) GenericPrinter

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered.

func (PrefixPrinter) Println

func (p PrefixPrinter) Println(a ...interface{}) GenericPrinter

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func (PrefixPrinter) SetFatal added in v0.2.1

func (p PrefixPrinter) SetFatal(fatal bool) *PrefixPrinter

SetFatal sets if the printer should panic after printing. NOTE: The printer will only panic if either PrefixPrinter.Println, PrefixPrinter.Print or PrefixPrinter.Printf is called.

func (PrefixPrinter) SetMessageStyle added in v0.2.0

func (p PrefixPrinter) SetMessageStyle(colors ...Color) *PrefixPrinter

SetMessageStyle adds a custom prefix to the printer.

func (PrefixPrinter) SetPrefix added in v0.2.0

func (p PrefixPrinter) SetPrefix(prefix Prefix) *PrefixPrinter

SetPrefix adds a custom prefix to the printer.

func (PrefixPrinter) SetScope added in v0.2.0

func (p PrefixPrinter) SetScope(scope string, colors ...Color) *PrefixPrinter

SetScope adds a scope to the Prefix.

func (PrefixPrinter) Sprint

func (p PrefixPrinter) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.

func (PrefixPrinter) Sprintf

func (p PrefixPrinter) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string.

func (PrefixPrinter) Sprintln

func (p PrefixPrinter) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.

type Progressbar added in v0.2.1

type Progressbar struct {
	Title                     string
	Total                     int
	Current                   int
	UpdateDelay               time.Duration
	LineCharacter             string
	LastCharacter             string
	ElapsedTimeRoundingFactor time.Duration

	ShowElapsedTime bool
	ShowCount       bool
	ShowTitle       bool
	ShowPercentage  bool

	TitleStyle Style
	BarStyle   Style

	IsActive bool
	// contains filtered or unexported fields
}

Progressbar shows a progress animation in the terminal.

func (*Progressbar) Add added in v0.2.1

func (p *Progressbar) Add(count int) *Progressbar

Add to current value.

func (*Progressbar) GetElapsedTime added in v0.2.1

func (p *Progressbar) GetElapsedTime() time.Duration

GetElapsedTime returns the elapsed time, since the progressbar was started.

func (*Progressbar) Increment added in v0.2.1

func (p *Progressbar) Increment() *Progressbar

Increment current value by one.

func (Progressbar) SetBarStyle added in v0.2.1

func (p Progressbar) SetBarStyle(colors ...Color) *Progressbar

SetBarStyle sets the style of the bar.

func (Progressbar) SetCurrent added in v0.2.1

func (p Progressbar) SetCurrent(current int) *Progressbar

SetCurrent sets the current value of the progressbar.

func (Progressbar) SetElapsedTimeRoundingFactor added in v0.2.1

func (p Progressbar) SetElapsedTimeRoundingFactor(duration time.Duration) *Progressbar

SetElapsedTimeRoundingFactor sets the rounding factor of the elapsed time.

func (Progressbar) SetLastCharacter added in v0.2.1

func (p Progressbar) SetLastCharacter(char string) *Progressbar

SetLastCharacter sets the last character of the progressbar.

func (Progressbar) SetLineCharacter added in v0.2.1

func (p Progressbar) SetLineCharacter(char string) *Progressbar

SetLineCharacter sets the line character of the progressbar.

func (Progressbar) SetShowCount added in v0.2.1

func (p Progressbar) SetShowCount(show bool) *Progressbar

SetShowCount sets if the total and current count should be displayed in the progressbar.

func (Progressbar) SetShowElapsedTime added in v0.2.1

func (p Progressbar) SetShowElapsedTime(show bool) *Progressbar

SetShowElapsedTime sets if the elapsed time should be displayed in the progressbar.

func (Progressbar) SetShowPercentage added in v0.2.1

func (p Progressbar) SetShowPercentage(show bool) *Progressbar

SetShowPercentage sets if the completed percentage should be displayed in the progressbar.

func (Progressbar) SetShowTitle added in v0.2.1

func (p Progressbar) SetShowTitle(show bool) *Progressbar

SetShowTitle sets if the title should be displayed in the progressbar.

func (Progressbar) SetTitle added in v0.2.1

func (p Progressbar) SetTitle(name string) *Progressbar

SetTitle sets the name of the progressbar.

func (Progressbar) SetTitleStyle added in v0.2.1

func (p Progressbar) SetTitleStyle(colors ...Color) *Progressbar

SetTitleStyle sets the style of the title.

func (Progressbar) SetTotal added in v0.2.1

func (p Progressbar) SetTotal(total int) *Progressbar

SetTotal sets the total value of the progressbar.

func (Progressbar) SetUpdateDelay added in v0.2.1

func (p Progressbar) SetUpdateDelay(delay time.Duration) *Progressbar

SetUpdateDelay sets the update delay of the progressbar.

func (Progressbar) Start added in v0.2.1

func (p Progressbar) Start() *Progressbar

Start the progressbar.

func (*Progressbar) Stop added in v0.2.1

func (p *Progressbar) Stop() *Progressbar

Stop the progressbar.

type Scope

type Scope struct {
	Text  string
	Style Style
}

Scope contains the data of the optional scope of a prefix. If it has a text, it will be printed after the Prefix in brackets.

type Spinner added in v0.1.0

type Spinner struct {
	Text           string
	Sequence       []string
	Style          Style
	Delay          time.Duration
	MessageStyle   Style
	SuccessPrinter GenericPrinter
	FailPrinter    GenericPrinter
	WarningPrinter GenericPrinter
	RemoveWhenDone bool

	IsActive bool
}

Spinner is a loading animation, which can be used if the progress is unknown. It's an animation loop, which can have a text and supports throwing errors or warnings. A GenericPrinter is used to display all outputs, after the spinner is done.

func (*Spinner) Fail added in v0.1.0

func (s *Spinner) Fail(message ...interface{})

Fail displays the fail printer. If no message is given, the text of the spinner will be reused as the default message.

func (Spinner) SetRemoveWhenDone added in v0.2.0

func (s Spinner) SetRemoveWhenDone(b bool) *Spinner

SetRemoveWhenDone removes the spinner after it is done.

func (Spinner) Start added in v0.1.0

func (s Spinner) Start(text ...interface{}) *Spinner

Start starts the spinner.

func (*Spinner) Stop added in v0.1.0

func (s *Spinner) Stop()

Stop terminates the Spinner immediately. The Spinner will not resolve into anything.

func (*Spinner) Success added in v0.1.0

func (s *Spinner) Success(message ...interface{})

Success displays the success printer. If no message is given, the text of the spinner will be reused as the default message.

func (*Spinner) UpdateText added in v0.2.0

func (s *Spinner) UpdateText(text string)

UpdateText updates the message of the active spinner. Can be used live.

func (*Spinner) Warning added in v0.1.0

func (s *Spinner) Warning(message ...interface{})

Warning displays the warning printer. If no message is given, the text of the spinner will be reused as the default message.

func (Spinner) WithDelay added in v0.1.0

func (s Spinner) WithDelay(delay time.Duration) *Spinner

WithDelay adds a delay to the spinner.

func (Spinner) WithMessageStyle added in v0.1.0

func (s Spinner) WithMessageStyle(colors ...Color) *Spinner

WithMessageStyle adds a style to the spinner message.

func (Spinner) WithSequence added in v0.1.0

func (s Spinner) WithSequence(sequence ...string) *Spinner

WithSequence adds a sequence to the spinner.

func (Spinner) WithStyle added in v0.1.0

func (s Spinner) WithStyle(colors ...Color) *Spinner

WithStyle adds a style to the spinner.

func (Spinner) WithText added in v0.1.0

func (s Spinner) WithText(text string) *Spinner

WithText adds a text to the spinner.

type Style

type Style []Color

Style is a collection of colors. Can include foreground, background and styling (eg. Bold, Underscore, etc.) colors.

func NewStyle added in v0.0.1

func NewStyle(colors ...Color) Style

NewStyle returns a new Style. Accepts multiple colors.

func (Style) Code

func (s Style) Code() string

Code convert to code string. returns like "32;45;3".

func (Style) Print

func (s Style) Print(a ...interface{})

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Printf

func (s Style) Printf(format string, a ...interface{})

Printf formats according to a format specifier and writes to standard output. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Println

func (s Style) Println(a ...interface{})

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered. Input will be colored with the parent Style.

func (Style) Sprint

func (s Style) Sprint(a ...interface{}) string

Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string. Input will be colored with the parent Style.

func (Style) Sprintf

func (s Style) Sprintf(format string, a ...interface{}) string

Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Style.

func (Style) Sprintln

func (s Style) Sprintln(a ...interface{}) string

Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended. Input will be colored with the parent Style.

func (Style) String

func (s Style) String() string

String convert to code string. returns like "32;45;3".

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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