Documentation ¶
Overview ¶
Package pterm is a modern go module to beautify console output. It can be used without configuration, but if desired, everything can be customized down to the smallest detail. View the animated examples here: https://github.com/pterm/pterm#-examples
Index ¶
- Variables
- func DisableColor()
- func DisableDebugMessages()
- func DisableOutput()
- func EnableColor()
- func EnableDebugMessages()
- func EnableOutput()
- func Fprint(writer io.Writer, a ...interface{})
- func Fprintln(writer io.Writer, a ...interface{})
- func Fprinto(w io.Writer, a ...interface{})
- func GetTerminalHeight() int
- func GetTerminalSize() (width, height int, err error)
- func GetTerminalWidth() int
- func Print(a ...interface{})
- func Printf(format string, a ...interface{})
- func Println(a ...interface{})
- func Printo(a ...interface{})
- func RemoveColorFromString(a ...interface{}) string
- func SetDefaultOutput(w io.Writer)
- func Sprint(a ...interface{}) string
- func Sprintf(format string, a ...interface{}) string
- func Sprintln(a ...interface{}) string
- func Sprinto(a ...interface{}) string
- type BasicTextPrinter
- func (p *BasicTextPrinter) Print(a ...interface{}) *TextPrinter
- func (p *BasicTextPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p *BasicTextPrinter) Println(a ...interface{}) *TextPrinter
- func (p BasicTextPrinter) Sprint(a ...interface{}) string
- func (p BasicTextPrinter) Sprintf(format string, a ...interface{}) string
- func (p BasicTextPrinter) Sprintln(a ...interface{}) string
- func (p BasicTextPrinter) WithStyle(style *Style) *BasicTextPrinter
- type BigTextPrinter
- type BulletList
- func (l BulletList) Render() error
- func (l BulletList) Srender() (string, error)
- func (l BulletList) WithBullet(bullet string) *BulletList
- func (l BulletList) WithBulletStyle(style *Style) *BulletList
- func (l BulletList) WithItems(items []BulletListItem) *BulletList
- func (l BulletList) WithTextStyle(style *Style) *BulletList
- type BulletListItem
- func (p BulletListItem) Render()
- func (p BulletListItem) Srender() string
- func (p BulletListItem) WithBullet(bullet string) BulletListItem
- func (p BulletListItem) WithBulletStyle(style *Style) BulletListItem
- func (p BulletListItem) WithLevel(level int) BulletListItem
- func (p BulletListItem) WithText(text string) BulletListItem
- func (p BulletListItem) WithTextStyle(style *Style) BulletListItem
- type CenterPrinter
- func (p CenterPrinter) Print(a ...interface{}) *TextPrinter
- func (p CenterPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p CenterPrinter) Println(a ...interface{}) *TextPrinter
- func (p CenterPrinter) Sprint(a ...interface{}) string
- func (p CenterPrinter) Sprintf(format string, a ...interface{}) string
- func (p CenterPrinter) Sprintln(a ...interface{}) string
- func (p CenterPrinter) WithCenterEachLineSeparately(b ...bool) *CenterPrinter
- type Color
- func (c Color) Print(a ...interface{})
- func (c Color) Printf(format string, a ...interface{})
- func (c Color) Println(a ...interface{})
- func (c Color) Sprint(a ...interface{}) string
- func (c Color) Sprintf(format string, a ...interface{}) string
- func (c Color) Sprintln(a ...interface{}) string
- func (c Color) String() string
- type HeaderPrinter
- func (p *HeaderPrinter) Print(a ...interface{}) *TextPrinter
- func (p *HeaderPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p *HeaderPrinter) Println(a ...interface{}) *TextPrinter
- func (p HeaderPrinter) Sprint(a ...interface{}) string
- func (p HeaderPrinter) Sprintf(format string, a ...interface{}) string
- func (p HeaderPrinter) Sprintln(a ...interface{}) string
- func (p HeaderPrinter) WithBackgroundStyle(style *Style) *HeaderPrinter
- func (p HeaderPrinter) WithFullWidth(b ...bool) *HeaderPrinter
- func (p HeaderPrinter) WithMargin(margin int) *HeaderPrinter
- func (p HeaderPrinter) WithTextStyle(style *Style) *HeaderPrinter
- type Letter
- type Letters
- type LeveledList
- type LeveledListItem
- type LivePrinter
- type Panel
- type PanelPrinter
- type Panels
- type ParagraphPrinter
- func (p *ParagraphPrinter) Print(a ...interface{}) *TextPrinter
- func (p *ParagraphPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p *ParagraphPrinter) Println(a ...interface{}) *TextPrinter
- func (p ParagraphPrinter) Sprint(a ...interface{}) string
- func (p ParagraphPrinter) Sprintf(format string, a ...interface{}) string
- func (p ParagraphPrinter) Sprintln(a ...interface{}) string
- func (p ParagraphPrinter) WithMaxWidth(width int) *ParagraphPrinter
- type Prefix
- type PrefixPrinter
- func (p PrefixPrinter) GetFormattedPrefix() string
- func (p *PrefixPrinter) Print(a ...interface{}) *TextPrinter
- func (p *PrefixPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p *PrefixPrinter) Println(a ...interface{}) *TextPrinter
- func (p *PrefixPrinter) Sprint(a ...interface{}) string
- func (p PrefixPrinter) Sprintf(format string, a ...interface{}) string
- func (p PrefixPrinter) Sprintln(a ...interface{}) string
- func (p PrefixPrinter) WithDebugger(b ...bool) *PrefixPrinter
- func (p PrefixPrinter) WithFatal(b ...bool) *PrefixPrinter
- func (p PrefixPrinter) WithMessageStyle(style *Style) *PrefixPrinter
- func (p PrefixPrinter) WithPrefix(prefix Prefix) *PrefixPrinter
- func (p PrefixPrinter) WithScope(scope Scope) *PrefixPrinter
- type Progressbar
- func (p *Progressbar) Add(count int) *Progressbar
- func (p Progressbar) GenericStart() (*LivePrinter, error)
- func (p Progressbar) GenericStop() (*LivePrinter, error)
- func (p *Progressbar) GetElapsedTime() time.Duration
- func (p *Progressbar) Increment() *Progressbar
- func (p Progressbar) Start() (*Progressbar, error)
- func (p *Progressbar) Stop() (*Progressbar, error)
- func (p Progressbar) WithBarCharacter(char string) *Progressbar
- func (p Progressbar) WithBarStyle(style *Style) *Progressbar
- func (p Progressbar) WithCurrent(current int) *Progressbar
- func (p Progressbar) WithElapsedTimeRoundingFactor(duration time.Duration) *Progressbar
- func (p Progressbar) WithLastCharacter(char string) *Progressbar
- func (p Progressbar) WithRemoveWhenDone(b ...bool) *Progressbar
- func (p Progressbar) WithShowCount(b ...bool) *Progressbar
- func (p Progressbar) WithShowElapsedTime(b ...bool) *Progressbar
- func (p Progressbar) WithShowPercentage(b ...bool) *Progressbar
- func (p Progressbar) WithShowTitle(b ...bool) *Progressbar
- func (p Progressbar) WithTitle(name string) *Progressbar
- func (p Progressbar) WithTitleStyle(style *Style) *Progressbar
- func (p Progressbar) WithTotal(total int) *Progressbar
- type RGB
- func (p RGB) Fade(min, max, current float32, end ...RGB) RGB
- func (p RGB) GetValues() (r, g, b uint8)
- func (p RGB) Print(a ...interface{}) *TextPrinter
- func (p RGB) Printf(format string, a ...interface{}) *TextPrinter
- func (p RGB) Println(a ...interface{}) *TextPrinter
- func (p RGB) Sprint(a ...interface{}) string
- func (p RGB) Sprintf(format string, a ...interface{}) string
- func (p RGB) Sprintln(a ...interface{}) string
- type RenderPrinter
- type Scope
- type SectionPrinter
- func (p *SectionPrinter) Print(a ...interface{}) *TextPrinter
- func (p *SectionPrinter) Printf(format string, a ...interface{}) *TextPrinter
- func (p *SectionPrinter) Println(a ...interface{}) *TextPrinter
- func (p SectionPrinter) Sprint(a ...interface{}) string
- func (p SectionPrinter) Sprintf(format string, a ...interface{}) string
- func (p SectionPrinter) Sprintln(a ...interface{}) string
- func (p SectionPrinter) WithBottomPadding(padding int) *SectionPrinter
- func (p SectionPrinter) WithIndentCharacter(char string) *SectionPrinter
- func (p SectionPrinter) WithLevel(level int) *SectionPrinter
- func (p SectionPrinter) WithStyle(style *Style) *SectionPrinter
- func (p SectionPrinter) WithTopPadding(padding int) *SectionPrinter
- type Spinner
- func (s *Spinner) Fail(message ...interface{})
- func (s *Spinner) GenericStart() (*LivePrinter, error)
- func (s *Spinner) GenericStop() (*LivePrinter, error)
- func (s Spinner) Start(text ...interface{}) (*Spinner, error)
- func (s *Spinner) Stop() error
- func (s *Spinner) Success(message ...interface{})
- func (s *Spinner) UpdateText(text string)
- func (s *Spinner) Warning(message ...interface{})
- func (s Spinner) WithDelay(delay time.Duration) *Spinner
- func (s Spinner) WithMessageStyle(style *Style) *Spinner
- func (s Spinner) WithRemoveWhenDone(b ...bool) *Spinner
- func (s Spinner) WithSequence(sequence ...string) *Spinner
- func (s Spinner) WithStyle(style *Style) *Spinner
- func (s Spinner) WithText(text string) *Spinner
- type Style
- func (s Style) Add(styles ...Style) Style
- func (s Style) Code() string
- func (s Style) Print(a ...interface{})
- func (s Style) Printf(format string, a ...interface{})
- func (s Style) Println(a ...interface{})
- func (s Style) Sprint(a ...interface{}) string
- func (s Style) Sprintf(format string, a ...interface{}) string
- func (s Style) Sprintln(a ...interface{}) string
- func (s Style) String() string
- type Table
- func (p Table) Render() error
- func (p Table) Srender() (string, error)
- func (p Table) WithCSVReader(reader *csv.Reader) *Table
- func (p Table) WithData(data [][]string) *Table
- func (p Table) WithHasHeader(b ...bool) *Table
- func (p Table) WithHeaderStyle(style *Style) *Table
- func (p Table) WithSeparator(separator string) *Table
- func (p Table) WithSeparatorStyle(style *Style) *Table
- func (p Table) WithStyle(style *Style) *Table
- type TableData
- type TextPrinter
- type Theme
- func (t Theme) WithBulletListBulletStyle(style Style) Theme
- func (t Theme) WithBulletListTextStyle(style Style) Theme
- func (t Theme) WithDebugMessageStyle(style Style) Theme
- func (t Theme) WithDebugPrefixStyle(style Style) Theme
- func (t Theme) WithDescriptionMessageStyle(style Style) Theme
- func (t Theme) WithDescriptionPrefixStyle(style Style) Theme
- func (t Theme) WithErrorMessageStyle(style Style) Theme
- func (t Theme) WithErrorPrefixStyle(style Style) Theme
- func (t Theme) WithFatalMessageStyle(style Style) Theme
- func (t Theme) WithFatalPrefixStyle(style Style) Theme
- func (t Theme) WithHighlightStyle(style Style) Theme
- func (t Theme) WithInfoMessageStyle(style Style) Theme
- func (t Theme) WithInfoPrefixStyle(style Style) Theme
- func (t Theme) WithLetterStyle(style Style) Theme
- func (t Theme) WithPrimaryStyle(style Style) Theme
- func (t Theme) WithSecondaryStyle(style Style) Theme
- func (t Theme) WithSuccessMessageStyle(style Style) Theme
- func (t Theme) WithSuccessPrefixStyle(style Style) Theme
- func (t Theme) WithTreeStyle(style Style) Theme
- func (t Theme) WithTreeTextStyle(style Style) Theme
- func (t Theme) WithWarningMessageStyle(style Style) Theme
- func (t Theme) WithWarningPrefixStyle(style Style) Theme
- type Tree
- func (p Tree) Render() error
- func (p Tree) Srender() (string, error)
- func (p Tree) WithHorizontalString(s string) *Tree
- func (p Tree) WithIndent(indent int) *Tree
- func (p Tree) WithRoot(root TreeNode) *Tree
- func (p Tree) WithTextStyle(style *Style) *Tree
- func (p Tree) WithTopRightCornerString(s string) *Tree
- func (p Tree) WithTopRightDownStringOngoing(s string) *Tree
- func (p Tree) WithTreeStyle(style *Style) *Tree
- func (p Tree) WithVerticalString(s string) *Tree
- type TreeNode
Constants ¶
This section is empty.
Variables ¶
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 )
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") // ErrHexCodeIsInvalid - the given HEX code is invalid. ErrHexCodeIsInvalid = errors.New("hex code is not valid") )
var ( // Info returns a PrefixPrinter, which can be used to print text with an "info" Prefix. Info = PrefixPrinter{ MessageStyle: &ThemeDefault.InfoMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.InfoPrefixStyle, Text: "INFO", }, } // Warning returns a PrefixPrinter, which can be used to print text with a "warning" Prefix. Warning = PrefixPrinter{ MessageStyle: &ThemeDefault.WarningMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.WarningPrefixStyle, Text: "WARNING", }, } // Success returns a PrefixPrinter, which can be used to print text with a "success" Prefix. Success = PrefixPrinter{ MessageStyle: &ThemeDefault.SuccessMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.SuccessPrefixStyle, Text: "SUCCESS", }, } // Error returns a PrefixPrinter, which can be used to print text with an "error" Prefix. Error = PrefixPrinter{ MessageStyle: &ThemeDefault.ErrorMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.ErrorPrefixStyle, Text: " ERROR ", }, } // Fatal returns a PrefixPrinter, which can be used to print text with an "fatal" Prefix. // NOTICE: Fatal terminates the application immediately! Fatal = PrefixPrinter{ MessageStyle: &ThemeDefault.FatalMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.FatalPrefixStyle, Text: " FATAL ", }, Fatal: true, } // Debug Prints debug messages. By default it will only print if PrintDebugMessages is true. // You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself. Debug = PrefixPrinter{ MessageStyle: &ThemeDefault.DebugMessageStyle, Prefix: Prefix{ Text: " DEBUG ", Style: &ThemeDefault.DebugPrefixStyle, }, Debugger: true, } // Description returns a PrefixPrinter, which can be used to print text with a "description" Prefix. Description = PrefixPrinter{ MessageStyle: &ThemeDefault.DescriptionMessageStyle, Prefix: Prefix{ Style: &ThemeDefault.DescriptionPrefixStyle, Text: "Description", }, } )
var ( // Output completely disables output from pterm. Can be used in CLI application quiet mode. Output = false // PrintDebugMessages sets if messages printed by the DebugPrinter should be printed. PrintDebugMessages = false )
var ActiveProgressBars []*Progressbar
ActiveProgressBars contains all running progressbars. Generally, there should only be one active Progressbar at a time.
var ( // DefaultBasicText returns a default BasicTextPrinter, which can be used to print text as is. // No default style is present for BasicTextPrinter. DefaultBasicText = BasicTextPrinter{} )
var DefaultBigText = BigTextPrinter{ BigCharacters: map[string]string{ "a": ` █████ ██ ██ ███████ ██ ██ ██ ██ `, "A": ` █████ ██ ██ ███████ ██ ██ ██ ██ `, "b": `██████ ██ ██ ██████ ██ ██ ██████`, "B": `██████ ██ ██ ██████ ██ ██ ██████`, "c": ` ██████ ██ ██ ██ ██████`, "C": ` ██████ ██ ██ ██ ██████`, "d": `██████ ██ ██ ██ ██ ██ ██ ██████ `, "D": `██████ ██ ██ ██ ██ ██ ██ ██████ `, "e": `███████ ██ █████ ██ ███████`, "E": `███████ ██ █████ ██ ███████`, "f": `███████ ██ █████ ██ ██ `, "F": `███████ ██ █████ ██ ██ `, "g": ` ██████ ██ ██ ███ ██ ██ ██████ `, "G": ` ██████ ██ ██ ███ ██ ██ ██████ `, "h": `██ ██ ██ ██ ███████ ██ ██ ██ ██ `, "H": `██ ██ ██ ██ ███████ ██ ██ ██ ██ `, "i": `██ ██ ██ ██ ██`, "I": `██ ██ ██ ██ ██`, "j": ` ██ ██ ██ ██ ██ █████ `, "J": ` ██ ██ ██ ██ ██ █████ `, "k": `██ ██ ██ ██ █████ ██ ██ ██ ██`, "K": `██ ██ ██ ██ █████ ██ ██ ██ ██`, "l": `██ ██ ██ ██ ███████ `, "L": `██ ██ ██ ██ ███████ `, "m": `███ ███ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██`, "M": `███ ███ ████ ████ ██ ████ ██ ██ ██ ██ ██ ██`, "n": `███ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████`, "N": `███ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████`, "o": ` ██████ ██ ██ ██ ██ ██ ██ ██████ `, "O": ` ██████ ██ ██ ██ ██ ██ ██ ██████ `, "p": `██████ ██ ██ ██████ ██ ██ `, "P": `██████ ██ ██ ██████ ██ ██ `, "q": ` ██████ ██ ██ ██ ██ ██ ▄▄ ██ ██████ ▀▀ `, "Q": ` ██████ ██ ██ ██ ██ ██ ▄▄ ██ ██████ ▀▀ `, "r": `██████ ██ ██ ██████ ██ ██ ██ ██`, "R": `██████ ██ ██ ██████ ██ ██ ██ ██`, "s": `███████ ██ ███████ ██ ███████`, "S": `███████ ██ ███████ ██ ███████`, "t": `████████ ██ ██ ██ ██ `, "T": `████████ ██ ██ ██ ██ `, "u": `██ ██ ██ ██ ██ ██ ██ ██ ██████ `, "U": `██ ██ ██ ██ ██ ██ ██ ██ ██████ `, "v": `██ ██ ██ ██ ██ ██ ██ ██ ████ `, "V": `██ ██ ██ ██ ██ ██ ██ ██ ████ `, "w": `██ ██ ██ ██ ██ █ ██ ██ ███ ██ ███ ███ `, "W": `██ ██ ██ ██ ██ █ ██ ██ ███ ██ ███ ███ `, "x": `██ ██ ██ ██ ███ ██ ██ ██ ██ `, "X": `██ ██ ██ ██ ███ ██ ██ ██ ██ `, "y": `██ ██ ██ ██ ████ ██ ██ `, "Y": `██ ██ ██ ██ ████ ██ ██ `, "z": `███████ ███ ███ ███ ███████`, "Z": `███████ ███ ███ ███ ███████`, "0": ` ██████ ██ ████ ██ ██ ██ ████ ██ ██████ `, "1": ` ██ ███ ██ ██ ██ `, "2": `██████ ██ █████ ██ ███████ `, "3": `██████ ██ █████ ██ ██████ `, "4": `██ ██ ██ ██ ███████ ██ ██ `, "5": `███████ ██ ███████ ██ ███████ `, "6": ` ██████ ██ ███████ ██ ██ ██████ `, "7": `███████ ██ ██ ██ ██`, "8": ` █████ ██ ██ █████ ██ ██ █████ `, "9": ` █████ ██ ██ ██████ ██ █████ `, " ": " ", "!": `██ ██ ██ ██ `, "$": `▄▄███▄▄· ██ ███████ ██ ███████ ▀▀▀ `, "%": `██ ██ ██ ██ ██ ██ ██`, "/": ` ██ ██ ██ ██ ██ `, "(": ` ██ ██ ██ ██ ██ `, ")": `██ ██ ██ ██ ██ `, "?": `██████ ██ ▄███ ▀▀ ██ `, "[": `███ ██ ██ ██ ███`, "]": `███ ██ ██ ██ ███ `, ".": ` ██`, ",": ` ▄█`, "-": ` █████ `, "<": ` ██ ██ ██ ██ ██ `, ">": `██ ██ ██ ██ ██ `, "*": ` ▄ ██ ▄ ████ ▀ ██ ▀ `, "#": ` ██ ██ ████████ ██ ██ ████████ ██ ██ `, "_": ` ███████ `, }, }
DefaultBigText contains default values for BigTextPrinter.
var DefaultBulletList = BulletList{ Bullet: "•", TextStyle: &ThemeDefault.BulletListTextStyle, BulletStyle: &ThemeDefault.BulletListBulletStyle, }
DefaultBulletList contains standards, which can be used to print a BulletList.
var DefaultCenter = CenterPrinter{ CenterEachLineSeparately: false, }
DefaultCenter is the default CenterPrinter.
var ( // DefaultHeader returns the printer for a default header text. // Defaults to LightWhite, Bold Text and a Gray DefaultHeader background. DefaultHeader = HeaderPrinter{ TextStyle: &ThemeDefault.HeaderTextStyle, BackgroundStyle: &ThemeDefault.HeaderBackgroundStyle, Margin: 5, } )
var DefaultListItem = BulletListItem{ Bullet: "•", TextStyle: &ThemeDefault.BulletListTextStyle, BulletStyle: &ThemeDefault.BulletListBulletStyle, }
DefaultListItem contains standards, which can be used to print a ListItem.
var DefaultPanel = PanelPrinter{
Padding: 1,
}
DefaultPanel is the default PanelPrinter.
var DefaultParagraph = ParagraphPrinter{ MaxWidth: GetTerminalWidth(), }
DefaultParagraph contains the default values for a ParagraphPrinter.
var ( // DefaultProgressbar is the default progressbar. DefaultProgressbar = Progressbar{ Total: 100, BarCharacter: "█", LastCharacter: "█", ElapsedTimeRoundingFactor: time.Second, BarStyle: &ThemeDefault.ProgressbarBarStyle, TitleStyle: &ThemeDefault.ProgressbarTitleStyle, ShowTitle: true, ShowCount: true, ShowPercentage: true, ShowElapsedTime: true, BarFiller: " ", } )
var DefaultSection = SectionPrinter{ Style: &ThemeDefault.SectionStyle, Level: 1, TopPadding: 1, BottomPadding: 1, IndentCharacter: "#", }
DefaultSection is the default section printer.
var DefaultSpinner = Spinner{ Sequence: []string{"▀ ", " ▀", " ▄", "▄ "}, Style: &ThemeDefault.SpinnerStyle, Delay: time.Millisecond * 200, MessageStyle: &ThemeDefault.SpinnerTextStyle, SuccessPrinter: &Success, FailPrinter: &Error, WarningPrinter: &Warning, }
DefaultSpinner is the default spinner.
var DefaultTable = Table{ Style: &ThemeDefault.TableStyle, HeaderStyle: &ThemeDefault.TableHeaderStyle, Separator: " | ", SeparatorStyle: &ThemeDefault.TableSeparatorStyle, }
DefaultTable contains standards, which can be used to print a Table.
var DefaultTree = Tree{ TreeStyle: &ThemeDefault.TreeStyle, TextStyle: &ThemeDefault.TreeTextStyle, TopRightCornerString: "└", HorizontalString: "─", TopRightDownString: "├", VerticalString: "│", RightDownLeftString: "┬", Indent: 2, }
DefaultTree contains standards, which can be used to render a Tree.
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.
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.
var ( // GrayBoxStyle wraps text in a gray box. GrayBoxStyle = NewStyle(BgGray, FgLightWhite) )
var PrintColor = true
PrintColor is false if PTerm should not print colored output.
var ( // ThemeDefault is the default theme used by PTerm. // If this variable is overwritten, the new value is used as default theme. ThemeDefault = Theme{ PrimaryStyle: Style{FgCyan}, SecondaryStyle: Style{FgLightMagenta}, HighlightStyle: Style{Bold, FgYellow}, InfoMessageStyle: Style{FgLightCyan}, InfoPrefixStyle: Style{FgBlack, BgCyan}, SuccessMessageStyle: Style{FgGreen}, SuccessPrefixStyle: Style{FgBlack, BgGreen}, WarningMessageStyle: Style{FgYellow}, WarningPrefixStyle: Style{FgBlack, BgYellow}, ErrorMessageStyle: Style{FgLightRed}, ErrorPrefixStyle: Style{FgBlack, BgLightRed}, FatalMessageStyle: Style{FgLightRed}, FatalPrefixStyle: Style{FgBlack, BgLightRed}, DescriptionMessageStyle: Style{FgDefault}, DescriptionPrefixStyle: Style{FgLightWhite, BgDarkGray}, ScopeStyle: Style{FgGray}, ProgressbarBarStyle: Style{FgCyan}, ProgressbarTitleStyle: Style{FgLightCyan}, HeaderTextStyle: Style{FgLightWhite, Bold}, HeaderBackgroundStyle: Style{BgGray}, SpinnerStyle: Style{FgLightCyan}, SpinnerTextStyle: Style{FgLightWhite}, TableStyle: Style{FgDefault}, TableHeaderStyle: Style{FgLightCyan}, TableSeparatorStyle: Style{FgGray}, SectionStyle: Style{Bold, FgYellow}, BulletListTextStyle: Style{FgDefault}, BulletListBulletStyle: Style{FgGray}, TreeStyle: Style{FgGray}, TreeTextStyle: Style{FgDefault}, LetterStyle: Style{FgDefault}, DebugMessageStyle: Style{FgGray}, DebugPrefixStyle: Style{FgBlack, BgGray}, } )
Functions ¶
func DisableDebugMessages ¶ added in v0.9.0
func DisableDebugMessages()
DisableDebugMessages disables the output of debug printers.
func DisableOutput ¶ added in v0.5.1
func DisableOutput()
DisableOutput disables the output of PTerm.
func EnableDebugMessages ¶ added in v0.9.0
func EnableDebugMessages()
EnableDebugMessages enables the output of debug printers.
func Fprint ¶ added in v0.1.0
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.
func Fprintln ¶ added in v0.1.0
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.
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
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 Print ¶
func 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.
func Printf ¶
func 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.
func Println ¶
func 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.
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 RemoveColorFromString ¶ added in v0.4.0
func RemoveColorFromString(a ...interface{}) string
RemoveColorFromString removes color codes from a string.
func SetDefaultOutput ¶ added in v0.3.1
SetDefaultOutput sets the default output of pterm.
func Sprint ¶
func 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.
Types ¶
type BasicTextPrinter ¶ added in v0.6.0
type BasicTextPrinter struct {
Style *Style
}
BasicTextPrinter is the printer used to print the input as-is or as specified by user formatting.
func (*BasicTextPrinter) Print ¶ added in v0.6.0
func (p *BasicTextPrinter) Print(a ...interface{}) *TextPrinter
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 (*BasicTextPrinter) Printf ¶ added in v0.6.0
func (p *BasicTextPrinter) Printf(format string, a ...interface{}) *TextPrinter
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 (*BasicTextPrinter) Println ¶ added in v0.6.0
func (p *BasicTextPrinter) Println(a ...interface{}) *TextPrinter
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 (BasicTextPrinter) Sprint ¶ added in v0.6.0
func (p BasicTextPrinter) 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 (BasicTextPrinter) Sprintf ¶ added in v0.6.0
func (p BasicTextPrinter) Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
func (BasicTextPrinter) Sprintln ¶ added in v0.6.0
func (p BasicTextPrinter) 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.
func (BasicTextPrinter) WithStyle ¶ added in v0.6.0
func (p BasicTextPrinter) WithStyle(style *Style) *BasicTextPrinter
WithStyle adds a style to the printer.
type BigTextPrinter ¶ added in v0.8.0
type BigTextPrinter struct { // BigCharacters holds the map from a normal character to it's big version. BigCharacters map[string]string Letters Letters }
BigTextPrinter renders big text. You can use this as title screen for your application.
func (BigTextPrinter) Render ¶ added in v0.8.0
func (p BigTextPrinter) Render() error
Render prints the BigText to the terminal.
func (BigTextPrinter) Srender ¶ added in v0.8.0
func (p BigTextPrinter) Srender() (string, error)
Srender renders the BigText as a string.
func (BigTextPrinter) WithBigCharacters ¶ added in v0.8.0
func (p BigTextPrinter) WithBigCharacters(chars map[string]string) *BigTextPrinter
WithBigCharacters returns a new BigTextPrinter with specific BigCharacters.
func (BigTextPrinter) WithLetters ¶ added in v0.8.0
func (p BigTextPrinter) WithLetters(letters ...Letters) *BigTextPrinter
WithLetters returns a new BigTextPrinter with specific Letters
type BulletList ¶ added in v0.8.0
type BulletList struct { Items []BulletListItem TextStyle *Style Bullet string BulletStyle *Style }
BulletList is able to render a list.
func NewBulletListFromString ¶ added in v0.9.0
func NewBulletListFromString(s string, padding string) BulletList
NewBulletListFromString returns a BulletList with Text using the NewTreeListItemFromString method, splitting after return (\n).
func NewBulletListFromStrings ¶ added in v0.9.0
func NewBulletListFromStrings(s []string, padding string) BulletList
NewBulletListFromStrings returns a BulletList with Text using the NewTreeListItemFromString method.
func (BulletList) Render ¶ added in v0.8.0
func (l BulletList) Render() error
Render prints the list to the terminal.
func (BulletList) Srender ¶ added in v0.8.0
func (l BulletList) Srender() (string, error)
Srender renders the list as a string.
func (BulletList) WithBullet ¶ added in v0.8.0
func (l BulletList) WithBullet(bullet string) *BulletList
WithBullet returns a new list with a specific bullet.
func (BulletList) WithBulletStyle ¶ added in v0.8.0
func (l BulletList) WithBulletStyle(style *Style) *BulletList
WithBulletStyle returns a new list with a specific bullet style.
func (BulletList) WithItems ¶ added in v0.8.0
func (l BulletList) WithItems(items []BulletListItem) *BulletList
WithItems returns a new list with specific Items.
func (BulletList) WithTextStyle ¶ added in v0.8.0
func (l BulletList) WithTextStyle(style *Style) *BulletList
WithTextStyle returns a new list with a specific text style.
type BulletListItem ¶ added in v0.8.0
type BulletListItem struct { Level int Text string TextStyle *Style Bullet string BulletStyle *Style }
BulletListItem is able to render a ListItem.
func NewBulletListItemFromString ¶ added in v0.9.0
func NewBulletListItemFromString(text string, padding string) BulletListItem
NewBulletListItemFromString returns a BulletListItem with a Text. The padding is counted in the Text to define the Level of the ListItem.
func (BulletListItem) Render ¶ added in v0.8.0
func (p BulletListItem) Render()
Render renders the BulletListItem as a string.
func (BulletListItem) Srender ¶ added in v0.8.0
func (p BulletListItem) Srender() string
Srender renders the BulletListItem as a string.
func (BulletListItem) WithBullet ¶ added in v0.8.0
func (p BulletListItem) WithBullet(bullet string) BulletListItem
WithBullet returns a new BulletListItem with a specific Prefix.
func (BulletListItem) WithBulletStyle ¶ added in v0.8.0
func (p BulletListItem) WithBulletStyle(style *Style) BulletListItem
WithBulletStyle returns a new BulletListItem with a specific BulletStyle.
func (BulletListItem) WithLevel ¶ added in v0.8.0
func (p BulletListItem) WithLevel(level int) BulletListItem
WithLevel returns a new BulletListItem with a specific Level.
func (BulletListItem) WithText ¶ added in v0.8.0
func (p BulletListItem) WithText(text string) BulletListItem
WithText returns a new BulletListItem with a specific Text.
func (BulletListItem) WithTextStyle ¶ added in v0.8.0
func (p BulletListItem) WithTextStyle(style *Style) BulletListItem
WithTextStyle returns a new BulletListItem with a specific TextStyle.
type CenterPrinter ¶ added in v0.10.1
type CenterPrinter struct {
CenterEachLineSeparately bool
}
CenterPrinter prints centered text.
func (CenterPrinter) Print ¶ added in v0.10.1
func (p CenterPrinter) Print(a ...interface{}) *TextPrinter
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 (CenterPrinter) Printf ¶ added in v0.10.1
func (p CenterPrinter) Printf(format string, a ...interface{}) *TextPrinter
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 (CenterPrinter) Println ¶ added in v0.10.1
func (p CenterPrinter) Println(a ...interface{}) *TextPrinter
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 (CenterPrinter) Sprint ¶ added in v0.10.1
func (p CenterPrinter) 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 (CenterPrinter) Sprintf ¶ added in v0.10.1
func (p CenterPrinter) Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
func (CenterPrinter) Sprintln ¶ added in v0.10.1
func (p CenterPrinter) 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.
func (CenterPrinter) WithCenterEachLineSeparately ¶ added in v0.10.1
func (p CenterPrinter) WithCenterEachLineSeparately(b ...bool) *CenterPrinter
WithCenterEachLineSeparately centers each line separately.
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 ¶
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 ¶
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 ¶
Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Color.
type HeaderPrinter ¶ added in v0.0.1
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{}) *TextPrinter
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{}) *TextPrinter
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{}) *TextPrinter
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) 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.
func (HeaderPrinter) WithBackgroundStyle ¶ added in v0.1.0
func (p HeaderPrinter) WithBackgroundStyle(style *Style) *HeaderPrinter
WithBackgroundStyle changes the background styling of the header.
func (HeaderPrinter) WithFullWidth ¶ added in v0.1.0
func (p HeaderPrinter) WithFullWidth(b ...bool) *HeaderPrinter
WithFullWidth enables full width on a HeaderPrinter.
func (HeaderPrinter) WithMargin ¶ added in v0.1.0
func (p HeaderPrinter) WithMargin(margin int) *HeaderPrinter
WithMargin changes the background styling of the header.
func (HeaderPrinter) WithTextStyle ¶ added in v0.1.0
func (p HeaderPrinter) WithTextStyle(style *Style) *HeaderPrinter
WithTextStyle returns a new HeaderPrinter with changed
type Letter ¶ added in v0.8.0
Letter is an object, which holds a string and a specific Style for it.
func (Letter) WithString ¶ added in v0.8.0
WithString returns a new Letter with a specific String.
type Letters ¶ added in v0.8.0
type Letters []Letter
Letters is a slice of Letter.
func NewLettersFromString ¶ added in v0.8.0
NewLettersFromString creates a Letters object from a string, which is prefilled with the LetterStyle from ThemeDefault. You can override the ThemeDefault LetterStyle if you want to.
func NewLettersFromStringWithStyle ¶ added in v0.8.0
NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.
type LeveledList ¶ added in v0.9.3
type LeveledList []LeveledListItem
LeveledList is a list, which contains multiple LeveledListItem.
type LeveledListItem ¶ added in v0.9.3
LeveledListItem combines a text with a specific level. The level is the indent, which would normally be seen in a BulletList.
type LivePrinter ¶ added in v0.5.0
type LivePrinter interface { // GenericStart runs Start, but returns a LivePrinter. // This is used for the interface LivePrinter. // You most likely want to use Start instead of this in your program. GenericStart() (*LivePrinter, error) // GenericStop runs Stop, but returns a LivePrinter. // This is used for the interface LivePrinter. // You most likely want to use Stop instead of this in your program. GenericStop() (*LivePrinter, error) }
LivePrinter is a printer which can update it's output live.
type Panel ¶ added in v0.11.0
type Panel struct {
Data string
}
Panel contains the data, which should be printed inside a PanelPrinter.
type PanelPrinter ¶ added in v0.11.0
PanelPrinter prints content in boxes.
func (PanelPrinter) Render ¶ added in v0.11.0
func (p PanelPrinter) Render() error
Render prints the Template to the terminal.
func (PanelPrinter) Srender ¶ added in v0.11.0
func (p PanelPrinter) Srender() (string, error)
Srender renders the Template as a string.
func (PanelPrinter) WithPadding ¶ added in v0.11.0
func (p PanelPrinter) WithPadding(padding int) *PanelPrinter
WithPadding returns a new PanelPrinter with specific options.
func (PanelPrinter) WithPanels ¶ added in v0.11.0
func (p PanelPrinter) WithPanels(panels Panels) *PanelPrinter
WithPanels returns a new PanelPrinter with specific options.
type Panels ¶ added in v0.11.0
type Panels [][]Panel
Panels is a two dimensional coordinate system for Panel.
type ParagraphPrinter ¶ added in v0.5.0
type ParagraphPrinter struct {
MaxWidth int
}
ParagraphPrinter can print paragraphs to a fixed line width. The text will split between words, so that words will stick together. It's like in a book.
func (*ParagraphPrinter) Print ¶ added in v0.5.0
func (p *ParagraphPrinter) Print(a ...interface{}) *TextPrinter
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 (*ParagraphPrinter) Printf ¶ added in v0.5.0
func (p *ParagraphPrinter) Printf(format string, a ...interface{}) *TextPrinter
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 (*ParagraphPrinter) Println ¶ added in v0.5.0
func (p *ParagraphPrinter) Println(a ...interface{}) *TextPrinter
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 (ParagraphPrinter) Sprint ¶ added in v0.5.0
func (p ParagraphPrinter) 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 (ParagraphPrinter) Sprintf ¶ added in v0.5.0
func (p ParagraphPrinter) Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
func (ParagraphPrinter) Sprintln ¶ added in v0.5.0
func (p ParagraphPrinter) 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.
func (ParagraphPrinter) WithMaxWidth ¶ added in v0.5.0
func (p ParagraphPrinter) WithMaxWidth(width int) *ParagraphPrinter
WithMaxWidth returns a new ParagraphPrinter with a specific MaxWidth
type PrefixPrinter ¶
type PrefixPrinter struct { Prefix Prefix Scope Scope MessageStyle *Style Fatal bool // If Debugger is true, the printer will only print if PrintDebugMessages is set to true. // You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself. Debugger 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{}) *TextPrinter
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{}) *TextPrinter
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{}) *TextPrinter
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) 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.
func (PrefixPrinter) WithDebugger ¶ added in v0.9.0
func (p PrefixPrinter) WithDebugger(b ...bool) *PrefixPrinter
WithDebugger returns a new Printer with specific Debugger value. If Debugger is true, the printer will only print if PrintDebugMessages is set to true. You can change PrintDebugMessages with EnableDebugMessages and DisableDebugMessages, or by setting the variable itself.
func (PrefixPrinter) WithFatal ¶ added in v0.3.0
func (p PrefixPrinter) WithFatal(b ...bool) *PrefixPrinter
WithFatal 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) WithMessageStyle ¶ added in v0.1.0
func (p PrefixPrinter) WithMessageStyle(style *Style) *PrefixPrinter
WithMessageStyle adds a custom prefix to the printer.
func (PrefixPrinter) WithPrefix ¶ added in v0.1.0
func (p PrefixPrinter) WithPrefix(prefix Prefix) *PrefixPrinter
WithPrefix adds a custom prefix to the printer.
func (PrefixPrinter) WithScope ¶
func (p PrefixPrinter) WithScope(scope Scope) *PrefixPrinter
WithScope adds a scope to the Prefix.
type Progressbar ¶ added in v0.2.1
type Progressbar struct { Title string Total int Current int BarCharacter string LastCharacter string ElapsedTimeRoundingFactor time.Duration BarFiller string ShowElapsedTime bool ShowCount bool ShowTitle bool ShowPercentage bool RemoveWhenDone 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) GenericStart ¶ added in v0.5.0
func (p Progressbar) GenericStart() (*LivePrinter, error)
GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.
func (Progressbar) GenericStop ¶ added in v0.5.0
func (p Progressbar) GenericStop() (*LivePrinter, error)
GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.
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) Start ¶ added in v0.2.1
func (p Progressbar) Start() (*Progressbar, error)
Start the progressbar.
func (*Progressbar) Stop ¶ added in v0.2.1
func (p *Progressbar) Stop() (*Progressbar, error)
Stop the progressbar.
func (Progressbar) WithBarCharacter ¶ added in v0.8.0
func (p Progressbar) WithBarCharacter(char string) *Progressbar
WithBarCharacter sets the bar character of the progressbar.
func (Progressbar) WithBarStyle ¶ added in v0.3.0
func (p Progressbar) WithBarStyle(style *Style) *Progressbar
WithBarStyle sets the style of the bar.
func (Progressbar) WithCurrent ¶ added in v0.3.0
func (p Progressbar) WithCurrent(current int) *Progressbar
WithCurrent sets the current value of the progressbar.
func (Progressbar) WithElapsedTimeRoundingFactor ¶ added in v0.3.0
func (p Progressbar) WithElapsedTimeRoundingFactor(duration time.Duration) *Progressbar
WithElapsedTimeRoundingFactor sets the rounding factor of the elapsed time.
func (Progressbar) WithLastCharacter ¶ added in v0.3.0
func (p Progressbar) WithLastCharacter(char string) *Progressbar
WithLastCharacter sets the last character of the progressbar.
func (Progressbar) WithRemoveWhenDone ¶ added in v0.7.0
func (p Progressbar) WithRemoveWhenDone(b ...bool) *Progressbar
WithRemoveWhenDone sets if the progressbar should be removed when it is done.
func (Progressbar) WithShowCount ¶ added in v0.3.0
func (p Progressbar) WithShowCount(b ...bool) *Progressbar
WithShowCount sets if the total and current count should be displayed in the progressbar.
func (Progressbar) WithShowElapsedTime ¶ added in v0.3.0
func (p Progressbar) WithShowElapsedTime(b ...bool) *Progressbar
WithShowElapsedTime sets if the elapsed time should be displayed in the progressbar.
func (Progressbar) WithShowPercentage ¶ added in v0.3.0
func (p Progressbar) WithShowPercentage(b ...bool) *Progressbar
WithShowPercentage sets if the completed percentage should be displayed in the progressbar.
func (Progressbar) WithShowTitle ¶ added in v0.3.0
func (p Progressbar) WithShowTitle(b ...bool) *Progressbar
WithShowTitle sets if the title should be displayed in the progressbar.
func (Progressbar) WithTitle ¶ added in v0.3.0
func (p Progressbar) WithTitle(name string) *Progressbar
WithTitle sets the name of the progressbar.
func (Progressbar) WithTitleStyle ¶ added in v0.3.0
func (p Progressbar) WithTitleStyle(style *Style) *Progressbar
WithTitleStyle sets the style of the title.
func (Progressbar) WithTotal ¶ added in v0.3.0
func (p Progressbar) WithTotal(total int) *Progressbar
WithTotal sets the total value of the progressbar.
type RGB ¶ added in v0.5.1
RGB color model is an additive color model in which red, green, and blue light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue. https://en.wikipedia.org/wiki/RGB_color_model
func NewRGBFromHEX ¶ added in v0.5.1
NewRGBFromHEX converts a HEX and returns a new RGB.
func (RGB) Fade ¶ added in v0.5.1
Fade fades one RGB value (over other RGB values) to another RGB value, by giving the function a minimum, maximum and current value.
func (RGB) Print ¶ added in v0.5.1
func (p RGB) Print(a ...interface{}) *TextPrinter
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 (RGB) Printf ¶ added in v0.5.1
func (p RGB) Printf(format string, a ...interface{}) *TextPrinter
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 (RGB) Println ¶ added in v0.5.1
func (p RGB) Println(a ...interface{}) *TextPrinter
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 (RGB) Sprint ¶ added in v0.5.1
Sprint formats using the default formats for its operands and returns the resulting string. Spaces are added between operands when neither is a string.
type RenderPrinter ¶ added in v0.5.0
type RenderPrinter interface { // Render the XXX to the terminal. Render() error // Srender returns the rendered string of XXX. Srender() (string, error) }
RenderPrinter is used to display renderable content. Example for renderable content is a Table.
type Scope ¶
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 SectionPrinter ¶ added in v0.3.2
type SectionPrinter struct { Style *Style Level int IndentCharacter string TopPadding int BottomPadding int }
SectionPrinter prints a new section title. It can be used to structure longer text, or different chapters of your program.
func (*SectionPrinter) Print ¶ added in v0.3.2
func (p *SectionPrinter) Print(a ...interface{}) *TextPrinter
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 (*SectionPrinter) Printf ¶ added in v0.3.2
func (p *SectionPrinter) Printf(format string, a ...interface{}) *TextPrinter
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 (*SectionPrinter) Println ¶ added in v0.3.2
func (p *SectionPrinter) Println(a ...interface{}) *TextPrinter
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 (SectionPrinter) Sprint ¶ added in v0.3.2
func (p SectionPrinter) 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 (SectionPrinter) Sprintf ¶ added in v0.3.2
func (p SectionPrinter) Sprintf(format string, a ...interface{}) string
Sprintf formats according to a format specifier and returns the resulting string.
func (SectionPrinter) Sprintln ¶ added in v0.3.2
func (p SectionPrinter) 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.
func (SectionPrinter) WithBottomPadding ¶ added in v0.5.0
func (p SectionPrinter) WithBottomPadding(padding int) *SectionPrinter
WithBottomPadding returns a new SectionPrinter with a specific top padding.
func (SectionPrinter) WithIndentCharacter ¶ added in v0.8.0
func (p SectionPrinter) WithIndentCharacter(char string) *SectionPrinter
WithIndentCharacter returns a new SectionPrinter with a specific IndentCharacter.
func (SectionPrinter) WithLevel ¶ added in v0.4.0
func (p SectionPrinter) WithLevel(level int) *SectionPrinter
WithLevel returns a new SectionPrinter with a specific level.
func (SectionPrinter) WithStyle ¶ added in v0.4.0
func (p SectionPrinter) WithStyle(style *Style) *SectionPrinter
WithStyle returns a new SectionPrinter with a specific style.
func (SectionPrinter) WithTopPadding ¶ added in v0.4.0
func (p SectionPrinter) WithTopPadding(padding int) *SectionPrinter
WithTopPadding returns a new SectionPrinter with a specific top padding.
type Spinner ¶ added in v0.1.0
type Spinner struct { Text string Sequence []string Style *Style Delay time.Duration MessageStyle *Style SuccessPrinter TextPrinter FailPrinter TextPrinter WarningPrinter TextPrinter 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 TextPrinter 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) GenericStart ¶ added in v0.5.0
func (s *Spinner) GenericStart() (*LivePrinter, error)
GenericStart runs Start, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Start instead of this in your program.
func (*Spinner) GenericStop ¶ added in v0.5.0
func (s *Spinner) GenericStop() (*LivePrinter, error)
GenericStop runs Stop, but returns a LivePrinter. This is used for the interface LivePrinter. You most likely want to use Stop instead of this in your program.
func (*Spinner) Stop ¶ added in v0.1.0
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
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) WithMessageStyle ¶ added in v0.1.0
WithMessageStyle adds a style to the spinner message.
func (Spinner) WithRemoveWhenDone ¶ added in v0.3.0
WithRemoveWhenDone removes the spinner after it is done.
func (Spinner) WithSequence ¶ added in v0.1.0
WithSequence adds a sequence 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 (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 ¶
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 ¶
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 ¶
Sprintf formats according to a format specifier and returns the resulting string. Input will be colored with the parent Style.
type Table ¶ added in v0.5.0
type Table struct { Style *Style HasHeader bool HeaderStyle *Style Separator string SeparatorStyle *Style Data TableData }
Table is able to render tables.
func (Table) WithCSVReader ¶ added in v0.5.1
WithCSVReader return a new Table with specified Data extracted from CSV.
func (Table) WithHasHeader ¶ added in v0.5.0
WithHasHeader returns a new Table, where the first line is marked as a header.
func (Table) WithHeaderStyle ¶ added in v0.5.0
WithHeaderStyle returns a new Table with a specific HeaderStyle.
func (Table) WithSeparator ¶ added in v0.5.0
WithSeparator returns a new Table with a specific separator.
func (Table) WithSeparatorStyle ¶ added in v0.5.0
WithSeparatorStyle returns a new Table with a specific SeparatorStyle.
type TableData ¶ added in v0.5.0
type TableData [][]string
TableData is the type that contains the data of a Table.
type TextPrinter ¶ added in v0.5.0
type TextPrinter 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{}) *TextPrinter // 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{}) *TextPrinter // 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{}) *TextPrinter }
TextPrinter contains methods to print formatted text to the console or return it as a string.
type Theme ¶ added in v0.6.0
type Theme struct { PrimaryStyle Style SecondaryStyle Style HighlightStyle Style InfoMessageStyle Style InfoPrefixStyle Style SuccessMessageStyle Style SuccessPrefixStyle Style WarningMessageStyle Style WarningPrefixStyle Style ErrorMessageStyle Style ErrorPrefixStyle Style FatalMessageStyle Style FatalPrefixStyle Style DescriptionMessageStyle Style DescriptionPrefixStyle Style ScopeStyle Style ProgressbarBarStyle Style ProgressbarTitleStyle Style HeaderTextStyle Style HeaderBackgroundStyle Style SpinnerStyle Style SpinnerTextStyle Style TableStyle Style TableHeaderStyle Style TableSeparatorStyle Style SectionStyle Style BulletListTextStyle Style BulletListBulletStyle Style TreeStyle Style TreeTextStyle Style LetterStyle Style DebugMessageStyle Style DebugPrefixStyle Style }
Theme for PTerm. Theme contains every Style used in PTerm. You can create own themes for your application or use one of the existing themes.
func (Theme) WithBulletListBulletStyle ¶ added in v0.10.0
WithBulletListBulletStyle returns a new theme with overridden value.
func (Theme) WithBulletListTextStyle ¶ added in v0.10.0
WithBulletListTextStyle returns a new theme with overridden value.
func (Theme) WithDebugMessageStyle ¶ added in v0.9.0
WithDebugMessageStyle returns a new theme with overridden value.
func (Theme) WithDebugPrefixStyle ¶ added in v0.9.0
WithDebugPrefixStyle returns a new theme with overridden value.
func (Theme) WithDescriptionMessageStyle ¶ added in v0.6.0
WithDescriptionMessageStyle returns a new theme with overridden value.
func (Theme) WithDescriptionPrefixStyle ¶ added in v0.6.0
WithDescriptionPrefixStyle returns a new theme with overridden value.
func (Theme) WithErrorMessageStyle ¶ added in v0.6.0
WithErrorMessageStyle returns a new theme with overridden value.
func (Theme) WithErrorPrefixStyle ¶ added in v0.6.0
WithErrorPrefixStyle returns a new theme with overridden value.
func (Theme) WithFatalMessageStyle ¶ added in v0.6.0
WithFatalMessageStyle returns a new theme with overridden value.
func (Theme) WithFatalPrefixStyle ¶ added in v0.6.0
WithFatalPrefixStyle returns a new theme with overridden value.
func (Theme) WithHighlightStyle ¶ added in v0.6.0
WithHighlightStyle returns a new theme with overridden value.
func (Theme) WithInfoMessageStyle ¶ added in v0.6.0
WithInfoMessageStyle returns a new theme with overridden value.
func (Theme) WithInfoPrefixStyle ¶ added in v0.6.0
WithInfoPrefixStyle returns a new theme with overridden value.
func (Theme) WithLetterStyle ¶ added in v0.8.0
WithLetterStyle returns a new theme with overridden value.
func (Theme) WithPrimaryStyle ¶ added in v0.6.0
WithPrimaryStyle returns a new theme with overridden value.
func (Theme) WithSecondaryStyle ¶ added in v0.6.0
WithSecondaryStyle returns a new theme with overridden value.
func (Theme) WithSuccessMessageStyle ¶ added in v0.6.0
WithSuccessMessageStyle returns a new theme with overridden value.
func (Theme) WithSuccessPrefixStyle ¶ added in v0.6.0
WithSuccessPrefixStyle returns a new theme with overridden value.
func (Theme) WithTreeStyle ¶ added in v0.9.3
WithTreeStyle returns a new theme with overridden value.
func (Theme) WithTreeTextStyle ¶ added in v0.9.3
WithTreeTextStyle returns a new theme with overridden value.
func (Theme) WithWarningMessageStyle ¶ added in v0.6.0
WithWarningMessageStyle returns a new theme with overridden value.
func (Theme) WithWarningPrefixStyle ¶ added in v0.6.0
WithWarningPrefixStyle returns a new theme with overridden value.
type Tree ¶ added in v0.9.3
type Tree struct { Root TreeNode TreeStyle *Style TextStyle *Style TopRightCornerString string TopRightDownString string HorizontalString string VerticalString string RightDownLeftString string Indent int }
Tree is able to render a list.
func (Tree) WithHorizontalString ¶ added in v0.9.3
WithHorizontalString returns a new list with a specific HorizontalString.
func (Tree) WithIndent ¶ added in v0.9.3
WithIndent returns a new list with a specific amount of spacing between the levels. Indent must be at least 1.
func (Tree) WithTextStyle ¶ added in v0.9.3
WithTextStyle returns a new list with a specific text style.
func (Tree) WithTopRightCornerString ¶ added in v0.9.3
WithTopRightCornerString returns a new list with a specific TopRightCornerString.
func (Tree) WithTopRightDownStringOngoing ¶ added in v0.9.3
WithTopRightDownStringOngoing returns a new list with a specific TopRightDownString.
func (Tree) WithTreeStyle ¶ added in v0.9.3
WithTreeStyle returns a new list with a specific tree style.
func (Tree) WithVerticalString ¶ added in v0.9.3
WithVerticalString returns a new list with a specific VerticalString.
type TreeNode ¶ added in v0.9.3
TreeNode is used as items in a Tree.
func NewTreeFromLeveledList ¶ added in v0.9.3
func NewTreeFromLeveledList(leveledListItems LeveledList) TreeNode
NewTreeFromLeveledList converts a TreeItems list to a TreeNode and returns it.
Source Files ¶
- basic_text_printer.go
- bigtext_printer.go
- bulletlist_printer.go
- center_printer.go
- color.go
- errors.go
- header_printer.go
- interface_live_printer.go
- interface_renderable_printer.go
- interface_text_printer.go
- panel_printer.go
- paragraph_printer.go
- prefix_printer.go
- print.go
- progressbar.go
- pterm.go
- rgb.go
- section_printer.go
- spinner.go
- table_printer.go
- terminal.go
- theme.go
- tree_printer.go