pterm

package module
Version: v0.12.50 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: MIT Imports: 21 Imported by: 518

README ยถ

๐Ÿ’ป PTerm | Pretty Terminal Printer

A modern Go framework to make beautiful CLIs

Latest Release Stars Forks Downloads Forks
Downloads

PTerm

Show Demo Code


PTerm.sh | Installation | Getting Started | Documentation | Examples | Q&A | Discord


๐Ÿ“ฆ 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

If you want to create a CLI tool, make sure to check out our cli-template, which features automatic website generation, automatic deployments, a custom CI-System and much more!

โญ Main Features

Feature Description
๐Ÿช€ Easy to use Our first priority is to keep PTerm as easy to use as possible.
With many examples for each individual component, getting started with PTerm is extremely easy.
All components are similar in design and implement interfaces to simplify mixing individual components together.
๐Ÿคนโ€โ™€๏ธ Cross-Platform We take special precautions to ensure that PTerm works on as many operating systems and terminals as possible.
Whether it's Windows CMD, macOS iTerm2 or in the backend (for example inside a GitHub Action or other CI systems), PTerm guarantees beautiful output!
๐Ÿงช Well tested PTerm has a 100% test coverage, which means that every line of code inside PTerm gets tested automatically
We test PTerm continuously. However, since a human cannot test everything all the time, we have our own test system with which we currently run 28774automated tests to ensure that PTerm has no bugs.
โœจ Consistent Colors PTerm uses the ANSI color scheme which is widely used by terminals to ensure consistent colors in different terminal themes.
If that's not enough, PTerm can be used to access the full RGB color scheme (16 million colors) in terminals that support TrueColor.
๐Ÿ“š Component system PTerm consists of many components, called Printers, which can be used individually or together to generate pretty console output.
๐Ÿ›  Configurable PTerm can be used by without any configuration. However, you can easily configure each component with little code, so everyone has the freedom to design their own terminal output.
โœ 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 example code. The animations of the examples are automatically updated as soon as something changes in PTerm.

Printers (Components)

Feature Examples - Feature Examples
Bar Charts Examples - RGB Examples
BigText Examples - Sections Examples
Box Examples - Spinners Examples
Bullet Lists Examples - Trees Examples
Centered Examples - Theming Examples
Colors Examples - Tables Examples
Headers Examples - Styles Examples
Panels Examples - Area Examples
Paragraphs Examples -
Prefixes Examples -
Progress Bars Examples -

๐Ÿฆธโ€โ™‚๏ธ Supporters

- User ๐Ÿ’ธ
Jens Lauterbach @jenslauterbach 25$

๐Ÿงช Examples


โ€ผ๏ธ You can find all the examples, in a much better structure and their source code, in "_examples" โ€ผ๏ธ
Click on the link above to show the examples folder.

area/demo

Animation

SHOW SOURCE
package main

import (
	"time"

	"github.com/pterm/pterm"
)

func main() {
	pterm.Info.Println("The previous text will stay in place, while the area updates.")
	pterm.Print("\n\n") // Add two new lines as spacer.

	area, _ := pterm.DefaultArea.WithCenter().Start() // Start the Area printer, with the Center option.
	for i := 0; i < 10; i++ {
		str, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str.
		area.Update(str)                                                                                                // Update Area contents.
		time.Sleep(time.Second)
	}
	area.Stop()
}

barchart/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	positiveBars := pterm.Bars{
		pterm.Bar{
			Label: "Bar 1",
			Value: 5,
		},
		pterm.Bar{
			Label: "Bar 2",
			Value: 3,
		},
		pterm.Bar{
			Label: "Longer Label",
			Value: 7,
		},
	}

	pterm.Info.Println("Chart example with positive only values (bars use 100% of chart area)")
	_ = pterm.DefaultBarChart.WithBars(positiveBars).Render()
	_ = pterm.DefaultBarChart.WithHorizontal().WithBars(positiveBars).Render()
}

barchart/mixed-values

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	mixedBars := pterm.Bars{
		pterm.Bar{
			Label: "Bar 1",
			Value: 2,
		},
		pterm.Bar{
			Label: "Bar 2",
			Value: -3,
		},
		pterm.Bar{
			Label: "Bar 3",
			Value: -2,
		},
		pterm.Bar{
			Label: "Bar 4",
			Value: 5,
		},
		pterm.Bar{
			Label: "Longer Label",
			Value: 7,
		},
	}

	pterm.DefaultSection.Println("Chart example with mixed values (note screen space usage in case when ABSOLUTE values of negative and positive parts are differ too much)")
	_ = pterm.DefaultBarChart.WithBars(mixedBars).WithShowValue().Render()
	_ = pterm.DefaultBarChart.WithHorizontal().WithBars(mixedBars).WithShowValue().Render()
}

barchart/negative-values

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	negativeBars := pterm.Bars{
		pterm.Bar{
			Label: "Bar 1",
			Value: -5,
		},
		pterm.Bar{
			Label: "Bar 2",
			Value: -3,
		},
		pterm.Bar{
			Label: "Longer Label",
			Value: -7,
		},
	}

	pterm.Info.Println("Chart example with negative only values (bars use 100% of chart area)")
	_ = pterm.DefaultBarChart.WithBars(negativeBars).WithShowValue().Render()
	_ = pterm.DefaultBarChart.WithHorizontal().WithBars(negativeBars).WithShowValue().Render()
}

basictext/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// A BasicText printer is used to print text, without special formatting.
	// As it implements the TextPrinter interface, you can use it in combination with other printers.
	pterm.DefaultBasicText.Println("Default basic text printer.")
	pterm.DefaultBasicText.Println("Can be used in any" + pterm.LightMagenta(" TextPrinter ") + "context.")
	pterm.DefaultBasicText.Println("For example to resolve progressbars and spinners.")
	// If you just want to print text, you should use this instead:
	// 	pterm.Println("Hello, World!")
}

bigtext/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
	"github.com/pterm/pterm/putils"
)

func main() {
	// Print a large text with the LetterStyle from the standard theme.
	// Useful for title screens.
	pterm.DefaultBigText.WithLetters(putils.LettersFromString("PTerm")).Render()

	// Print a large text with differently colored letters.
	pterm.DefaultBigText.WithLetters(
		putils.LettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgCyan)),
		putils.LettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
		Render()

	// LettersFromStringWithRGB can be used to create a large text with a specific RGB color.
	pterm.DefaultBigText.WithLetters(
		putils.LettersFromStringWithRGB("PTerm", pterm.NewRGB(255, 215, 0))).
		Render()
}

box/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	pterm.Info.Println("This might not be rendered correctly on GitHub,\nbut it will work in a real terminal.\nThis is because GitHub does not use a monospaced font by default for SVGs")

	panel1 := pterm.DefaultBox.Sprint("Lorem ipsum dolor sit amet,\nconsectetur adipiscing elit,\nsed do eiusmod tempor incididunt\nut labore et dolore\nmagna aliqua.")
	panel2 := pterm.DefaultBox.WithTitle("title").Sprint("Ut enim ad minim veniam,\nquis nostrud exercitation\nullamco laboris\nnisi ut aliquip\nex ea commodo\nconsequat.")
	panel3 := pterm.DefaultBox.WithTitle("bottom center title").WithTitleBottomCenter().Sprint("Duis aute irure\ndolor in reprehenderit\nin voluptate velit esse cillum\ndolore eu fugiat\nnulla pariatur.")

	panels, _ := pterm.DefaultPanel.WithPanels(pterm.Panels{
		{{Data: panel1}, {Data: panel2}},
		{{Data: panel3}},
	}).Srender()

	pterm.DefaultBox.WithTitle("Lorem Ipsum").WithTitleBottomRight().WithRightPadding(0).WithBottomPadding(0).Println(panels)
}

bulletlist/customized

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	// Print a customized list with different styles and levels.
	pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
		{Level: 0, Text: "Blue", TextStyle: pterm.NewStyle(pterm.FgBlue), BulletStyle: pterm.NewStyle(pterm.FgRed)},
		{Level: 1, Text: "Green", TextStyle: pterm.NewStyle(pterm.FgGreen), Bullet: "-", BulletStyle: pterm.NewStyle(pterm.FgLightWhite)},
		{Level: 2, Text: "Cyan", TextStyle: pterm.NewStyle(pterm.FgCyan), Bullet: ">", BulletStyle: pterm.NewStyle(pterm.FgYellow)},
	}).Render()
}

bulletlist/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
	"github.com/pterm/pterm/putils"
)

func main() {
	// Print a list with different levels.
	// Useful to generate lists automatically from data.
	pterm.DefaultBulletList.WithItems([]pterm.BulletListItem{
		{Level: 0, Text: "Level 0"},
		{Level: 1, Text: "Level 1"},
		{Level: 2, Text: "Level 2"},
	}).Render()

	// Convert a text to a list and print it.
	putils.BulletListFromString(`0
 1
  2
   3`, " ").Render()
}

center/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	pterm.DefaultCenter.Println("This text is centered!\nIt centeres the whole block by default.\nIn that way you can do stuff like this:")

	// Generate BigLetters
	s, _ := pterm.DefaultBigText.WithLetters(pterm.NewLettersFromString("PTerm")).Srender()
	pterm.DefaultCenter.Println(s) // Print BigLetters with the default CenterPrinter

	pterm.DefaultCenter.WithCenterEachLineSeparately().Println("This text is centered!\nBut each line is\ncentered\nseparately")
}

coloring/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print all colors

	pterm.DefaultTable.WithData([][]string{
		{pterm.FgBlack.Sprint("Black"), pterm.FgRed.Sprint("Red"), pterm.FgGreen.Sprint("Green"), pterm.FgYellow.Sprint("Yellow")},
		{"", pterm.FgLightRed.Sprint("Light Red"), pterm.FgLightGreen.Sprint("Light Green"), pterm.FgLightYellow.Sprint("Light Yellow")},
		{pterm.BgBlack.Sprint("Black"), pterm.BgRed.Sprint("Red"), pterm.BgGreen.Sprint("Green"), pterm.BgYellow.Sprint("Yellow")},
		{"", pterm.BgLightRed.Sprint("Light Red"), pterm.BgLightGreen.Sprint("Light Green"), pterm.BgLightYellow.Sprint("Light Yellow")},
		{pterm.FgBlue.Sprint("Blue"), pterm.FgMagenta.Sprint("Magenta"), pterm.FgCyan.Sprint("Cyan"), pterm.FgWhite.Sprint("White")},
		{pterm.FgLightBlue.Sprint("Light Blue"), pterm.FgLightMagenta.Sprint("Light Magenta"), pterm.FgLightCyan.Sprint("Light Cyan"), pterm.FgLightWhite.Sprint("Light White")},
		{pterm.BgBlue.Sprint("Blue"), pterm.BgMagenta.Sprint("Magenta"), pterm.BgCyan.Sprint("Cyan"), pterm.BgWhite.Sprint("White")},
		{pterm.BgLightBlue.Sprint("Light Blue"), pterm.BgLightMagenta.Sprint("Light Magenta"), pterm.BgLightCyan.Sprint("Light Cyan"), pterm.BgLightWhite.Sprint("Light White")},
	}).Render()

	pterm.Println()

	// Print 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!"))

	pterm.Println()

	// Or print colors as a style
	style := pterm.NewStyle(pterm.BgRed, pterm.FgLightGreen, pterm.Bold)
	style.Println("This text uses a style and is bold and light green with a red background!")
}

coloring/disable-output

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	for i := 0; i < 15; i++ {
		switch i {
		case 5:
			pterm.Info.Println("Disabled Output!")
			pterm.DisableOutput()
		case 10:
			pterm.EnableOutput()
			pterm.Info.Println("Enabled Output!")
		}

		pterm.Printf("Printing something... [%d/%d]\n", i, 15)
	}
}

coloring/fade-colors

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	// Print info.
	pterm.Info.Println("RGB colors only work in Terminals which support TrueColor.")

	from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point.
	to := pterm.NewRGB(255, 0, 255)   // This RGB value is used as the gradients end point.

	// For loop over the range of the terminal height.
	for i := 0; i < pterm.GetTerminalHeight()-2; i++ {
		// Print string which is colored with the faded RGB value.
		from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to).Println("Hello, World!")
	}
}

coloring/fade-multiple-colors

Animation

SHOW SOURCE
package main

import (
	"strings"

	"github.com/pterm/pterm"
)

func main() {
	from := pterm.NewRGB(0, 255, 255)  // This RGB value is used as the gradients start point.
	to := pterm.NewRGB(255, 0, 255)    // This RGB value is used as the gradients first point.
	to2 := pterm.NewRGB(255, 0, 0)     // This RGB value is used as the gradients second point.
	to3 := pterm.NewRGB(0, 255, 0)     // This RGB value is used as the gradients third point.
	to4 := pterm.NewRGB(255, 255, 255) // This RGB value is used as the gradients end point.

	str := "RGB colors only work in Terminals which support TrueColor."
	strs := strings.Split(str, "")
	var fadeInfo string // String which will be used to print info.
	// For loop over the range of the string length.
	for i := 0; i < len(str); i++ {
		// Append faded letter to info string.
		fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i])
	}

	// Print info.
	pterm.Info.Println(fadeInfo)

	// For loop over the range of the terminal height.
	for i := 0; i < pterm.GetTerminalHeight()-2; i++ {
		// Print string which is colored with the faded RGB value.
		from.Fade(0, float32(pterm.GetTerminalHeight()-2), float32(i), to, to2, to3, to4).Println("Hello, World!")
	}
}

coloring/override-default-printers

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

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

	// Customize default error.
	pterm.Error.Prefix = pterm.Prefix{
		Text:  "OVERRIDE",
		Style: pterm.NewStyle(pterm.BgCyan, pterm.FgRed),
	}

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

coloring/print-color-rgb

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print strings with a custom RGB color.
	// NOTICE: This only works with terminals which support TrueColor.
	pterm.NewRGB(178, 44, 199).Println("This text is printed with a custom RGB!")
	pterm.NewRGB(15, 199, 209).Println("This text is printed with a custom RGB!")
	pterm.NewRGB(201, 144, 30).Println("This text is printed with a custom RGB!")
}

demo/demo

Animation

SHOW SOURCE
package main

import (
	"flag"
	"math/rand"
	"reflect"
	"strconv"
	"strings"
	"time"

	"github.com/pterm/pterm"
	"github.com/pterm/pterm/putils"
)

// Speed the demo up, by setting this flag.
// Usefull for debugging.
// Example:
//   go run main.go -speedup
var speedup = flag.Bool("speedup", false, "Speed up the demo")
var skipIntro = flag.Bool("skip-intro", false, "Skips the intro")
var second = time.Second

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

func main() {
	setup() // Setup the demo (flags etc.)

	// Show intro
	if !*skipIntro {
		introScreen()
		clear()
	}

	showcase("Progress bar", 2, func() {
		pb, _ := pterm.DefaultProgressbar.WithTotal(len(pseudoProgramList)).WithTitle("Installing stuff").Start()
		for i := 0; i < pb.Total; i++ {
			pb.UpdateTitle("Installing " + pseudoProgramList[i])
			if pseudoProgramList[i] == "pseudo-minecraft" {
				pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.")
			} else {
				pterm.Success.Println("Installing " + pseudoProgramList[i])
			}
			pb.Increment()
			time.Sleep(second / 2)
		}
		pb.Stop()
	})

	showcase("Spinner", 2, func() {
		list := pseudoProgramList[7:]
		spinner, _ := pterm.DefaultSpinner.Start("Installing stuff")
		for i := 0; i < len(list); i++ {
			spinner.UpdateText("Installing " + list[i])
			if list[i] == "pseudo-minecraft" {
				pterm.Warning.Println("Could not install pseudo-minecraft\nThe company policy forbids games.")
			} else {
				pterm.Success.Println("Installing " + list[i])
			}
			time.Sleep(second)
		}
		spinner.Success()
	})

	showcase("Live Output", 2, func() {
		pterm.Info.Println("You can use an Area to display changing output:")
		pterm.Println()
		area, _ := pterm.DefaultArea.WithCenter().Start() // Start the Area printer, with the Center option.
		for i := 0; i < 10; i++ {
			str, _ := pterm.DefaultBigText.WithLetters(putils.LettersFromString(time.Now().Format("15:04:05"))).Srender() // Save current time in str.
			area.Update(str)                                                                                              // Update Area contents.
			time.Sleep(time.Second)
		}
		area.Stop()
	})

	showcase("Tables", 4, func() {
		for i := 0; i < 3; i++ {
			pterm.Println()
		}
		td := [][]string{
			{"Library", "Description"},
			{"PTerm", "Make beautiful CLIs"},
			{"Testza", "Programmer friendly test framework"},
			{"Cursor", "Move the cursor around the terminal"},
		}
		table, _ := pterm.DefaultTable.WithHasHeader().WithData(td).Srender()
		boxedTable, _ := pterm.DefaultTable.WithHasHeader().WithData(td).WithBoxed().Srender()
		pterm.DefaultCenter.Println(table)
		pterm.DefaultCenter.Println(boxedTable)
	})

	showcase("Default Prefix Printers", 5, func() {
		// Enable debug messages.
		pterm.EnableDebugMessages() // Temporarily set debug output to true, to display the debug printer.

		pterm.Debug.Println("Hello, World!") // Print Debug.
		time.Sleep(second / 2)
		pterm.Info.Println("Hello, World!") // Print Info.
		time.Sleep(second / 2)
		pterm.Success.Println("Hello, World!") // Print Success.
		time.Sleep(second / 2)
		pterm.Warning.Println("Hello, World!") // Print Warning.
		time.Sleep(second / 2)
		pterm.Error.Println("Errors show the filename and linenumber inside the terminal!") // Print Error.
		time.Sleep(second / 2)
		pterm.Info.WithShowLineNumber().Println("Other PrefixPrinters can do that too!") // Print Error.
		time.Sleep(second / 2)
		// Temporarily set Fatal to false, so that the CI won't panic.
		pterm.Fatal.WithFatal(false).Println("Hello, World!") // Print Fatal.

		pterm.DisableDebugMessages() // Disable debug output again.
	})

	showcase("TrueColor Support", 7, func() {
		from := pterm.NewRGB(0, 255, 255) // This RGB value is used as the gradients start point.
		to := pterm.NewRGB(255, 0, 255)   // This RGB value is used as the gradients first point.

		str := "If your terminal has TrueColor support, you can use RGB colors!\nYou can even fade them :)\n\nLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
		strs := strings.Split(str, "")
		var fadeInfo string // String which will be used to print info.
		// For loop over the range of the string length.
		for i := 0; i < len(str); i++ {
			// Append faded letter to info string.
			fadeInfo += from.Fade(0, float32(len(str)), float32(i), to).Sprint(strs[i])
		}
		pterm.DefaultCenter.WithCenterEachLineSeparately().Println(fadeInfo)
	})

	showcase("Themes", 2, func() {
		pterm.Info.Println("You can change the color theme of PTerm easily to fit your needs!\nThis is the default one:")
		time.Sleep(second / 2)
		// Print every value of the default theme with its own style.
		v := reflect.ValueOf(pterm.ThemeDefault)
		typeOfS := v.Type()

		if typeOfS == reflect.TypeOf(pterm.Theme{}) {
			for i := 0; i < v.NumField(); i++ {
				field, ok := v.Field(i).Interface().(pterm.Style)
				if ok {
					field.Println(typeOfS.Field(i).Name)
				}
				time.Sleep(time.Millisecond * 250)
			}
		}
	})

	showcase("Fully Customizale", 2, func() {
		for i := 0; i < 4; i++ {
			pterm.Println()
		}
		text := "All printers are fully customizable!"
		area := pterm.DefaultArea.WithCenter()
		area.Update(pterm.DefaultBox.Sprintln(text))
		time.Sleep(second)
		area.Update(pterm.DefaultBox.WithTopPadding(1).Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleTopLeft().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleTopCenter().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleTopRight().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleBottomRight().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleBottomCenter().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithTitle("Some title!").WithTitleBottomLeft().Sprintln(text))
		time.Sleep(second / 3)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithBoxStyle(pterm.NewStyle(pterm.FgCyan)).Sprintln(text))
		time.Sleep(second / 5)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithBoxStyle(pterm.NewStyle(pterm.FgRed)).Sprintln(text))
		time.Sleep(second / 5)
		area.Update(pterm.DefaultBox.WithTopPadding(1).WithBottomPadding(1).WithLeftPadding(1).WithRightPadding(1).WithBoxStyle(pterm.NewStyle(pterm.FgGreen)).Sprintln(text))
		time.Sleep(second / 5)
		area.Update(pterm.DefaultBox.WithTopPadding(1).
			WithBottomPadding(1).
			WithLeftPadding(1).
			WithRightPadding(1).
			WithHorizontalString("โ•").
			WithVerticalString("โ•‘").
			WithBottomLeftCornerString("โ•—").
			WithBottomRightCornerString("โ•”").
			WithTopLeftCornerString("โ•").
			WithTopRightCornerString("โ•š").
			Sprintln(text))
		area.Stop()
	})

	showcase("And much more!", 3, func() {
		for i := 0; i < 4; i++ {
			pterm.Println()
		}
		box := pterm.DefaultBox.
			WithBottomPadding(1).
			WithTopPadding(1).
			WithLeftPadding(3).
			WithRightPadding(3).
			Sprintf("Have fun exploring %s!", pterm.Cyan("PTerm"))
		pterm.DefaultCenter.Println(box)
	})
}

func setup() {
	flag.Parse()
	if *speedup {
		second = time.Millisecond * 200
	}
}

func introScreen() {
	ptermLogo, _ := pterm.DefaultBigText.WithLetters(
		putils.LettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan)),
		putils.LettersFromStringWithStyle("Term", pterm.NewStyle(pterm.FgLightMagenta))).
		Srender()

	pterm.DefaultCenter.Print(ptermLogo)

	pterm.DefaultCenter.Print(pterm.DefaultHeader.WithFullWidth().WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithMargin(10).Sprint("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.WithShowTimer(false).WithRemoveWhenDone(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()
}

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

func showcase(title string, seconds int, content func()) {
	pterm.DefaultHeader.WithBackgroundStyle(pterm.NewStyle(pterm.BgLightBlue)).WithFullWidth().Println(title)
	pterm.Println()
	time.Sleep(second / 2)
	content()
	time.Sleep(second * time.Duration(seconds))
	print("\033[H\033[2J")
}

func randomInt(min, max int) int {
	rand.Seed(time.Now().UnixNano())
	return rand.Intn(max-min+1) + min
}

header/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print a default header.
	pterm.DefaultHeader.Println("This is the default header!")
	pterm.Println() // spacer
	pterm.DefaultHeader.WithFullWidth().Println("This is a full-width header.")
}

header-custom/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// All available options: https://pkg.go.dev/github.com/pterm/pterm#HeaderPrinter

	// Build on top of DefaultHeader
	pterm.DefaultHeader. // Use DefaultHeader as base
				WithMargin(15).
				WithBackgroundStyle(pterm.NewStyle(pterm.BgCyan)).
				WithTextStyle(pterm.NewStyle(pterm.FgBlack)).
				Println("This is a custom header!")
	// Instead of printing the header you can set it to a variable.
	// You can then reuse your custom header.

	// Making a completely new HeaderPrinter
	newHeader := pterm.HeaderPrinter{
		TextStyle:       pterm.NewStyle(pterm.FgBlack),
		BackgroundStyle: pterm.NewStyle(pterm.BgRed),
		Margin:          20,
	}

	// Print header.
	newHeader.Println("This is a custom header!")
}

interactive_confirm/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	result, _ := pterm.DefaultInteractiveConfirm.Show()
	pterm.Println() // Blank line
	pterm.Info.Printfln("You answered: %s", boolToText(result))
}

func boolToText(b bool) string {
	if b {
		return pterm.Green("Yes")
	}
	return pterm.Red("No")
}

interactive_continue/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	result, _ := pterm.DefaultInteractiveContinue.Show()
	pterm.Println() // Blank line
	pterm.Info.Printfln("You answered: %s", result)
}

interactive_multiselect/custom-keys

Animation

SHOW SOURCE
package main

import (
	"fmt"

	"atomicgo.dev/keyboard/keys"
	"github.com/pterm/pterm"
)

func main() {
	var options []string

	for i := 0; i < 5; i++ {
		options = append(options, fmt.Sprintf("Option %d", i))
	}

	printer := pterm.DefaultInteractiveMultiselect.WithOptions(options)
	printer.Filter = false
	printer.KeyConfirm = keys.Enter
	printer.KeySelect = keys.Space
	selectedOptions, _ := printer.Show()
	pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions))
}

interactive_multiselect/demo

Animation

SHOW SOURCE
package main

import (
	"fmt"

	"github.com/pterm/pterm"
)

func main() {
	var options []string

	for i := 0; i < 100; i++ {
		options = append(options, fmt.Sprintf("Option %d", i))
	}

	for i := 0; i < 5; i++ {
		options = append(options, fmt.Sprintf("You can use fuzzy searching (%d)", i))
	}

	selectedOptions, _ := pterm.DefaultInteractiveMultiselect.WithOptions(options).Show()
	pterm.Info.Printfln("Selected options: %s", pterm.Green(selectedOptions))
}

interactive_select/demo

Animation

SHOW SOURCE
package main

import (
	"fmt"

	"github.com/pterm/pterm"
)

func main() {
	var options []string

	for i := 0; i < 100; i++ {
		options = append(options, fmt.Sprintf("Option %d", i))
	}

	for i := 0; i < 5; i++ {
		options = append(options, fmt.Sprintf("You can use fuzzy searching (%d)", i))
	}

	selectedOption, _ := pterm.DefaultInteractiveSelect.WithOptions(options).Show()
	pterm.Info.Printfln("Selected option: %s", pterm.Green(selectedOption))
}

interactive_textinput/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	result, _ := pterm.DefaultInteractiveTextInput.WithMultiLine(false).Show()
	pterm.Println() // Blank line
	pterm.Info.Printfln("You answered: %s", result)
}

interactive_textinput/multi-line

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
)

func main() {
	result, _ := pterm.DefaultInteractiveTextInput.WithMultiLine().Show() // Text input with multi line enabled
	pterm.Println()                                                       // Blank line
	pterm.Info.Printfln("You answered: %s", result)
}

panel/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Declare panels in a two dimensional grid system.
	panels := pterm.Panels{
		{{Data: "This is the first panel"}, {Data: pterm.DefaultHeader.Sprint("Hello, World!")}, {Data: "This\npanel\ncontains\nmultiple\nlines"}},
		{{Data: pterm.Red("This is another\npanel line")}, {Data: "This is the second panel\nwith a new line"}},
	}

	// Print panels.
	_ = pterm.DefaultPanel.WithPanels(panels).WithPadding(5).Render()
}

paragraph/customized

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print a paragraph with a custom maximal width.
	pterm.DefaultParagraph.WithMaxWidth(60).Println("This is a custom paragraph printer. As you can see, no words are separated, " +
		"but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." +
		"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam")

	// Print one line space.
	pterm.Println()

	// Print text without a paragraph printer.
	pterm.Println("This text is written with the default Println() function. No intelligent splitting here." +
		"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam")
}

paragraph/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print long text with default paragraph printer.
	pterm.DefaultParagraph.Println("This is the default paragraph printer. As you can see, no words are separated, " +
		"but the text is split at the spaces. This is useful for continuous text of all kinds. You can manually change the line width if you want to." +
		"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam")

	// Print one line space.
	pterm.Println()

	// Print long text without paragraph printer.
	pterm.Println("This text is written with the default Println() function. No intelligent splitting here." +
		"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam")
}

prefix/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Enable debug messages.
	pterm.EnableDebugMessages()

	pterm.Debug.Println("Hello, World!")                                                // Print Debug.
	pterm.Info.Println("Hello, World!")                                                 // Print Info.
	pterm.Success.Println("Hello, World!")                                              // Print Success.
	pterm.Warning.Println("Hello, World!")                                              // Print Warning.
	pterm.Error.Println("Errors show the filename and linenumber inside the terminal!") // Print Error.
	pterm.Info.WithShowLineNumber().Println("Other PrefixPrinters can do that too!")    // Print Error.
	// Temporarily set Fatal to false, so that the CI won't crash.
	pterm.Fatal.WithFatal(false).Println("Hello, World!") // Print Fatal.
}

progressbar/demo

Animation

SHOW SOURCE
package main

import (
	"strings"
	"time"

	"github.com/pterm/pterm"
)

// Slice of strings with placeholder text.
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() {
	// Create progressbar as fork from the default progressbar.
	p, _ := pterm.DefaultProgressbar.WithTotal(len(fakeInstallList)).WithTitle("Downloading stuff").Start()

	for i := 0; i < p.Total; i++ {
		p.UpdateTitle("Downloading " + fakeInstallList[i])         // Update the title of the progressbar.
		pterm.Success.Println("Downloading " + fakeInstallList[i]) // If a progressbar is running, each print will be printed above the progressbar.
		p.Increment()                                              // Increment the progressbar by one. Use Add(x int) to increment by a custom amount.
		time.Sleep(time.Millisecond * 350)                         // Sleep 350 milliseconds.
	}
}

section/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Print a section with level one.
	pterm.DefaultSection.Println("This is a section!")
	// Print placeholder.
	pterm.Info.Println("And here is some text.\nThis text could be anything.\nBasically it's just a placeholder")

	// Print a section with level two.
	pterm.DefaultSection.WithLevel(2).Println("This is another section!")
	// Print placeholder.
	pterm.Info.Println("And this is\nmore placeholder text")
}

spinner/demo

Animation

SHOW SOURCE
package main

import (
	"time"

	"github.com/pterm/pterm"
)

func main() {
	// Create and start a fork of the default spinner.
	spinnerInfo, _ := pterm.DefaultSpinner.Start("Some informational action...")
	time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
	spinnerInfo.Info()          // Resolve spinner with error message.

	// Create and start a fork of the default spinner.
	spinnerSuccess, _ := pterm.DefaultSpinner.Start("Doing something important... (will succeed)")
	time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
	spinnerSuccess.Success()    // Resolve spinner with success message.

	// Create and start a fork of the default spinner.
	spinnerWarning, _ := pterm.DefaultSpinner.Start("Doing something important... (will warn)")
	time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
	spinnerWarning.Warning()    // Resolve spinner with warning message.

	// Create and start a fork of the default spinner.
	spinnerFail, _ := pterm.DefaultSpinner.Start("Doing something important... (will fail)")
	time.Sleep(time.Second * 2) // Simulate 3 seconds of processing something.
	spinnerFail.Fail()          // Resolve spinner with error message.

	// Create and start a fork of the default spinner.
	spinnerNochange, _ := pterm.DefaultSpinner.Start("Checking something important... (will result in no change)")
	// Replace the InfoPrinter with a custom "NOCHG" one
	spinnerNochange.InfoPrinter = &pterm.PrefixPrinter{
		MessageStyle: &pterm.Style{pterm.FgLightBlue},
		Prefix: pterm.Prefix{
			Style: &pterm.Style{pterm.FgBlack, pterm.BgLightBlue},
			Text:  " NOCHG ",
		},
	}
	time.Sleep(time.Second * 2)                     // Simulate 3 seconds of processing something.
	spinnerNochange.Info("No change were required") // Resolve spinner with error message.

	// Create and start a fork of the default spinner.
	spinnerLiveText, _ := pterm.DefaultSpinner.Start("Doing a lot of stuff...")
	time.Sleep(time.Second)                          // Simulate 2 seconds of processing something.
	spinnerLiveText.UpdateText("It's really much")   // Update spinner text.
	time.Sleep(time.Second)                          // Simulate 2 seconds of processing something.
	spinnerLiveText.UpdateText("We're nearly done!") // Update spinner text.
	time.Sleep(time.Second)                          // Simulate 2 seconds of processing something.
	spinnerLiveText.Success("Finally!")              // Resolve spinner with success message.
}

style/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Create styles as new variables
	primary := pterm.NewStyle(pterm.FgLightCyan, pterm.BgGray, pterm.Bold)
	secondary := pterm.NewStyle(pterm.FgLightGreen, pterm.BgWhite, pterm.Italic)

	// Use created styles
	primary.Println("Hello, World!")
	secondary.Println("Hello, World!")
}

table/demo

Animation

SHOW SOURCE
package main

import "github.com/pterm/pterm"

func main() {
	// Create a fork of the default table, fill it with data and print it.
	// Data can also be generated and inserted later.
	pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{
		{"Firstname", "Lastname", "Email", "Note"},
		{"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk", ""},
		{"Callie", "Mckay", "egestas.nunc.sed@est.com", "่ฟ™ๆ˜ฏไธ€ไธชๆต‹่ฏ•, haha!"},
		{"Libby", "Camacho", "aliquet.lobortis@semper.com", "just a test, hey!"},
	}).Render()

	pterm.Println() // Blank line

	// Create a table with right alignment.
	pterm.DefaultTable.WithHasHeader().WithData(pterm.TableData{
		{"Firstname", "Lastname", "Email"},
		{"Paul", "Dean", "nisi.dictum.augue@velitAliquam.co.uk"},
		{"Callie", "Mckay", "egestas.nunc.sed@est.com"},
		{"Libby", "Camacho", "aliquet.lobortis@semper.com"},
		{"ๅผ ", "ๅฐๅฎ", "zhang@example.com"},
	}).WithRightAlignment().Render()
}

theme/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
	"reflect"
	"time"
)

func main() {
	// Print info.
	pterm.Info.Println("These are the default theme styles.\n" +
		"You can modify them easily to your personal preference,\n" +
		"or create new themes from scratch :)")

	pterm.Println() // Print one line space.

	// Print every value of the default theme with its own style.
	v := reflect.ValueOf(pterm.ThemeDefault)
	typeOfS := v.Type()

	if typeOfS == reflect.TypeOf(pterm.Theme{}) {
		for i := 0; i < v.NumField(); i++ {
			field, ok := v.Field(i).Interface().(pterm.Style)
			if ok {
				field.Println(typeOfS.Field(i).Name)
			}
			time.Sleep(time.Millisecond * 250)
		}
	}
}

tree/demo

Animation

SHOW SOURCE
package main

import (
	"github.com/pterm/pterm"
	"github.com/pterm/pterm/putils"
)

func main() {
	// You can use a LeveledList here, for easy generation.
	leveledList := pterm.LeveledList{
		pterm.LeveledListItem{Level: 0, Text: "C:"},
		pterm.LeveledListItem{Level: 1, Text: "Users"},
		pterm.LeveledListItem{Level: 1, Text: "Windows"},
		pterm.LeveledListItem{Level: 1, Text: "Programs"},
		pterm.LeveledListItem{Level: 1, Text: "Programs(x86)"},
		pterm.LeveledListItem{Level: 1, Text: "dev"},
		pterm.LeveledListItem{Level: 0, Text: "D:"},
		pterm.LeveledListItem{Level: 0, Text: "E:"},
		pterm.LeveledListItem{Level: 1, Text: "Movies"},
		pterm.LeveledListItem{Level: 1, Text: "Music"},
		pterm.LeveledListItem{Level: 2, Text: "LinkinPark"},
		pterm.LeveledListItem{Level: 1, Text: "Games"},
		pterm.LeveledListItem{Level: 2, Text: "Shooter"},
		pterm.LeveledListItem{Level: 3, Text: "CallOfDuty"},
		pterm.LeveledListItem{Level: 3, Text: "CS:GO"},
		pterm.LeveledListItem{Level: 3, Text: "Battlefield"},
		pterm.LeveledListItem{Level: 4, Text: "Battlefield 1"},
		pterm.LeveledListItem{Level: 4, Text: "Battlefield 2"},
		pterm.LeveledListItem{Level: 0, Text: "F:"},
		pterm.LeveledListItem{Level: 1, Text: "dev"},
		pterm.LeveledListItem{Level: 2, Text: "dops"},
		pterm.LeveledListItem{Level: 2, Text: "PTerm"},
	}

	// Generate tree from LeveledList.
	root := putils.TreeFromLeveledList(leveledList)

	// Render TreePrinter
	pterm.DefaultTree.WithRoot(root).Render()
}


GitHub @pterm ย ยทย  Author @MarvinJWendt | PTerm.sh

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.

Official docs are available at: https://docs.pterm.sh

View the animated examples here: https://github.com/pterm/pterm#-examples

Index ยถ

Constants ยถ

This section is empty.

Variables ยถ

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 (
	// 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")
)
View Source
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",
		},
	}
)
View Source
var (
	// Output completely disables output from pterm if set to false. Can be used in CLI application quiet mode.
	Output = true

	// PrintDebugMessages sets if messages printed by the DebugPrinter should be printed.
	PrintDebugMessages = false

	// RawOutput is set to true if pterm.DisableStyling() was called.
	// The variable indicates that PTerm will not add additional styling to text.
	// Use pterm.DisableStyling() or pterm.EnableStyling() to change this variable.
	// Changing this variable directly, will disable or enable the output of colored text.
	RawOutput = false
)
View Source
var ActiveProgressBarPrinters []*ProgressbarPrinter

ActiveProgressBarPrinters contains all running ProgressbarPrinters. Generally, there should only be one active ProgressbarPrinter at a time.

View Source
var DefaultArea = AreaPrinter{}

DefaultArea is the default area printer.

View Source
var (
	// DefaultBarChart is the default BarChartPrinter.
	DefaultBarChart = BarChartPrinter{
		Horizontal:             false,
		VerticalBarCharacter:   "โ–ˆโ–ˆ",
		HorizontalBarCharacter: "โ–ˆ",

		Height: GetTerminalHeight() * 2 / 3,
		Width:  GetTerminalWidth() * 2 / 3,
	}
)
View Source
var (
	// DefaultBasicText returns a default BasicTextPrinter, which can be used to print text as is.
	// No default style is present for BasicTextPrinter.
	DefaultBasicText = BasicTextPrinter{}
)
View Source
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.

View Source
var DefaultBox = BoxPrinter{
	VerticalString:          "|",
	TopRightCornerString:    "โ””",
	TopLeftCornerString:     "โ”˜",
	BottomLeftCornerString:  "โ”",
	BottomRightCornerString: "โ”Œ",
	HorizontalString:        "โ”€",
	BoxStyle:                &ThemeDefault.BoxStyle,
	TextStyle:               &ThemeDefault.BoxTextStyle,
	RightPadding:            1,
	LeftPadding:             1,
	TopPadding:              0,
	BottomPadding:           0,
	TitleTopLeft:            true,
}

DefaultBox is the default BoxPrinter.

View Source
var DefaultBulletList = BulletListPrinter{
	Bullet:      "โ€ข",
	TextStyle:   &ThemeDefault.BulletListTextStyle,
	BulletStyle: &ThemeDefault.BulletListBulletStyle,
}

DefaultBulletList contains standards, which can be used to print a BulletListPrinter.

View Source
var DefaultCenter = CenterPrinter{
	CenterEachLineSeparately: false,
}

DefaultCenter is the default CenterPrinter.

View Source
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,
	}
)
View Source
var (
	// DefaultInteractiveConfirm is the default InteractiveConfirm printer.
	// Pressing "y" will return true, "n" will return false.
	// Pressing enter without typing "y" or "n" will return the configured default value (by default set to "no").
	DefaultInteractiveConfirm = InteractiveConfirmPrinter{
		DefaultValue: false,
		DefaultText:  "Please confirm",
		TextStyle:    &ThemeDefault.PrimaryStyle,
		ConfirmText:  "Yes",
		ConfirmStyle: &ThemeDefault.SuccessMessageStyle,
		RejectText:   "No",
		RejectStyle:  &ThemeDefault.ErrorMessageStyle,
		SuffixStyle:  &ThemeDefault.SecondaryStyle,
	}
)
View Source
var (
	// DefaultInteractiveContinue is the default InteractiveContinue printer.
	// Pressing "y" will return yes, "n" will return no, "a" returns all and "s" returns stop.
	// Pressing enter without typing any letter will return the configured default value (by default set to "yes", the fisrt option).
	DefaultInteractiveContinue = InteractiveContinuePrinter{
		DefaultValueIndex: 0,
		DefaultText:       "Do you want to continue",
		TextStyle:         &ThemeDefault.PrimaryStyle,
		Options:           []string{"yes", "no", "all", "cancel"},
		OptionsStyle:      &ThemeDefault.SuccessMessageStyle,
		SuffixStyle:       &ThemeDefault.SecondaryStyle,
	}
)
View Source
var (
	// DefaultInteractiveMultiselect is the default InteractiveMultiselect printer.
	DefaultInteractiveMultiselect = InteractiveMultiselectPrinter{
		TextStyle:      &ThemeDefault.PrimaryStyle,
		DefaultText:    "Please select your options",
		Options:        []string{},
		OptionStyle:    &ThemeDefault.DefaultText,
		DefaultOptions: []string{},
		MaxHeight:      5,
		Selector:       ">",
		SelectorStyle:  &ThemeDefault.SecondaryStyle,
		Filter:         true,
		KeySelect:      keys.Enter,
		KeyConfirm:     keys.Tab,
	}
)
View Source
var (
	// DefaultInteractiveSelect is the default InteractiveSelect printer.
	DefaultInteractiveSelect = InteractiveSelectPrinter{
		TextStyle:     &ThemeDefault.PrimaryStyle,
		DefaultText:   "Please select an option",
		Options:       []string{},
		OptionStyle:   &ThemeDefault.DefaultText,
		DefaultOption: "",
		MaxHeight:     5,
		Selector:      ">",
		SelectorStyle: &ThemeDefault.SecondaryStyle,
	}
)
View Source
var (
	// DefaultInteractiveTextInput is the default InteractiveTextInput printer.
	DefaultInteractiveTextInput = InteractiveTextInputPrinter{
		DefaultText: "Input text",
		TextStyle:   &ThemeDefault.PrimaryStyle,
	}
)
View Source
var DefaultPanel = PanelPrinter{
	Padding: 1,
}

DefaultPanel is the default PanelPrinter.

View Source
var DefaultParagraph = ParagraphPrinter{
	MaxWidth: GetTerminalWidth(),
}

DefaultParagraph contains the default values for a ParagraphPrinter.

View Source
var (
	// DefaultProgressbar is the default ProgressbarPrinter.
	DefaultProgressbar = ProgressbarPrinter{
		Total:                     100,
		BarCharacter:              "โ–ˆ",
		LastCharacter:             "โ–ˆ",
		ElapsedTimeRoundingFactor: time.Second,
		BarStyle:                  &ThemeDefault.ProgressbarBarStyle,
		TitleStyle:                &ThemeDefault.ProgressbarTitleStyle,
		ShowTitle:                 true,
		ShowCount:                 true,
		ShowPercentage:            true,
		ShowElapsedTime:           true,
		BarFiller:                 " ",
		MaxWidth:                  80,
	}
)
View Source
var DefaultSection = SectionPrinter{
	Style:           &ThemeDefault.SectionStyle,
	Level:           1,
	TopPadding:      1,
	BottomPadding:   1,
	IndentCharacter: "#",
}

DefaultSection is the default section printer.

View Source
var DefaultSpinner = SpinnerPrinter{
	Sequence:            []string{"โ–€ ", " โ–€", " โ–„", "โ–„ "},
	Style:               &ThemeDefault.SpinnerStyle,
	Delay:               time.Millisecond * 200,
	ShowTimer:           true,
	TimerRoundingFactor: time.Second,
	TimerStyle:          &ThemeDefault.TimerStyle,
	MessageStyle:        &ThemeDefault.SpinnerTextStyle,
	InfoPrinter:         &Info,
	SuccessPrinter:      &Success,
	FailPrinter:         &Error,
	WarningPrinter:      &Warning,
}

DefaultSpinner is the default SpinnerPrinter.

View Source
var DefaultTable = TablePrinter{
	Style:                   &ThemeDefault.TableStyle,
	HeaderStyle:             &ThemeDefault.TableHeaderStyle,
	HeaderRowSeparator:      "",
	HeaderRowSeparatorStyle: &ThemeDefault.TableSeparatorStyle,
	Separator:               " | ",
	SeparatorStyle:          &ThemeDefault.TableSeparatorStyle,
	RowSeparator:            "",
	RowSeparatorStyle:       &ThemeDefault.TableSeparatorStyle,
	LeftAlignment:           true,
	RightAlignment:          false,
}

DefaultTable contains standards, which can be used to print a TablePrinter.

View Source
var DefaultTree = TreePrinter{
	TreeStyle:            &ThemeDefault.TreeStyle,
	TextStyle:            &ThemeDefault.TreeTextStyle,
	TopRightCornerString: "โ””",
	HorizontalString:     "โ”€",
	TopRightDownString:   "โ”œ",
	VerticalString:       "โ”‚",
	RightDownLeftString:  "โ”ฌ",
	Indent:               2,
}

DefaultTree contains standards, which can be used to render a TreePrinter.

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 PrintColor = true

PrintColor is false if PTerm should not print colored output.

View Source
var (
	// ThemeDefault is the default theme used by PTerm.
	// If this variable is overwritten, the new value is used as default theme.
	ThemeDefault = Theme{
		DefaultText:             Style{FgDefault, BgDefault},
		PrimaryStyle:            Style{FgLightCyan},
		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},
		BoxStyle:                Style{FgDefault},
		BoxTextStyle:            Style{FgDefault},
		BarLabelStyle:           Style{FgLightCyan},
		BarStyle:                Style{FgCyan},
		TimerStyle:              Style{FgGray},
	}
)

Functions ยถ

func DisableColor ยถ added in v0.9.2

func DisableColor()

DisableColor disables colors.

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 DisableStyling ยถ added in v0.12.15

func DisableStyling()

DisableStyling sets PTerm to RawOutput mode and disables all of PTerms styling. You can use this to print to text files etc. This also calls DisableColor.

func EnableColor ยถ added in v0.9.2

func EnableColor()

EnableColor enables colors.

func EnableDebugMessages ยถ added in v0.9.0

func EnableDebugMessages()

EnableDebugMessages enables the output of debug printers.

func EnableOutput ยถ added in v0.10.0

func EnableOutput()

EnableOutput enables the output of PTerm.

func EnableStyling ยถ added in v0.12.15

func EnableStyling()

EnableStyling enables the default PTerm styling. This also calls EnableColor.

func Fprint ยถ added in v0.1.0

func Fprint(writer io.Writer, a ...interface{})

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

func Fprintln(writer io.Writer, a ...interface{})

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 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 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 PrintOnError ยถ added in v0.12.19

func PrintOnError(a ...interface{})

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func PrintOnErrorf ยถ added in v0.12.33

func PrintOnErrorf(format string, a ...interface{})

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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 Printfln ยถ added in v0.12.14

func Printfln(format string, a ...interface{})

Printfln formats according to a format specifier 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 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. Example:

pterm.Printo("Hello, World")
time.Sleep(time.Second)
pterm.Printo("Hello, Earth!")

func RecalculateTerminalSize ยถ added in v0.12.34

func RecalculateTerminalSize()

RecalculateTerminalSize updates already initialized terminal dimensions. Has to be called after a termina resize to guarantee proper rendering. Applies only to new instances.

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

func SetDefaultOutput(w io.Writer)

SetDefaultOutput sets the default output of pterm.

func SetForcedTerminalSize ยถ added in v0.12.34

func SetForcedTerminalSize(width int, height int)

setForcedTerminalSize turns off terminal size autodetection. Usuful for unified tests.

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.

func Sprintf ยถ

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

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

func Sprintfln ยถ added in v0.12.14

func Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func Sprintln ยถ added in v0.2.0

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

Sprintln returns what Println would print to the terminal.

func Sprinto ยถ added in v0.2.3

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

Sprinto returns what Printo would print.

Types ยถ

type AreaPrinter ยถ added in v0.12.18

type AreaPrinter struct {
	RemoveWhenDone bool
	Fullscreen     bool
	Center         bool
	// contains filtered or unexported fields
}

AreaPrinter prints an area which can be updated easily. use this printer for live output like charts, algorithm visualizations, simulations and even games.

func (*AreaPrinter) Clear ยถ added in v0.12.32

func (p *AreaPrinter) Clear()

Wrapper function that clears the content of the Area. Moves the cursor to the bottom of the terminal, clears n lines upwards from the current position and moves the cursor again.

func (*AreaPrinter) GenericStart ยถ added in v0.12.18

func (p *AreaPrinter) 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 (*AreaPrinter) GenericStop ยถ added in v0.12.18

func (p *AreaPrinter) 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 (*AreaPrinter) GetContent ยถ added in v0.12.18

func (p *AreaPrinter) GetContent() string

GetContent returns the current area content.

func (*AreaPrinter) Start ยถ added in v0.12.18

func (p *AreaPrinter) Start(text ...interface{}) (*AreaPrinter, error)

Start the AreaPrinter.

func (*AreaPrinter) Stop ยถ added in v0.12.18

func (p *AreaPrinter) Stop() error

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

func (*AreaPrinter) Update ยถ added in v0.12.18

func (p *AreaPrinter) Update(text ...interface{})

Update overwrites the content of the AreaPrinter. Can be used live.

func (AreaPrinter) WithCenter ยถ added in v0.12.18

func (p AreaPrinter) WithCenter(b ...bool) *AreaPrinter

WithCenter centers the AreaPrinter content to the terminal.

func (AreaPrinter) WithFullscreen ยถ added in v0.12.18

func (p AreaPrinter) WithFullscreen(b ...bool) *AreaPrinter

WithFullscreen sets the AreaPrinter height the same height as the terminal, making it fullscreen.

func (AreaPrinter) WithRemoveWhenDone ยถ added in v0.12.18

func (p AreaPrinter) WithRemoveWhenDone(b ...bool) *AreaPrinter

WithRemoveWhenDone removes the AreaPrinter content after it is stopped.

type Bar ยถ added in v0.12.7

type Bar struct {
	Label      string
	Value      int
	Style      *Style
	LabelStyle *Style
}

Bar is used in bar charts.

func (Bar) WithLabel ยถ added in v0.12.7

func (p Bar) WithLabel(s string) *Bar

WithLabel returns a new Bar with a specific option.

func (Bar) WithLabelStyle ยถ added in v0.12.7

func (p Bar) WithLabelStyle(style *Style) *Bar

WithLabelStyle returns a new Bar with a specific option.

func (Bar) WithStyle ยถ added in v0.12.7

func (p Bar) WithStyle(style *Style) *Bar

WithStyle returns a new Bar with a specific option.

func (Bar) WithValue ยถ added in v0.12.7

func (p Bar) WithValue(value int) *Bar

WithValue returns a new Bar with a specific option.

type BarChartPrinter ยถ added in v0.12.7

type BarChartPrinter struct {
	Writer     io.Writer
	Bars       Bars
	Horizontal bool
	ShowValue  bool
	// Height sets the maximum height of a vertical bar chart.
	// The default is calculated to fit into the terminal.
	// Ignored if Horizontal is set to true.
	Height int
	// Width sets the maximum width of a horizontal bar chart.
	// The default is calculated to fit into the terminal.
	// Ignored if Horizontal is set to false.
	Width                  int
	VerticalBarCharacter   string
	HorizontalBarCharacter string
}

BarChartPrinter is used to print bar charts.

func (BarChartPrinter) Render ยถ added in v0.12.7

func (p BarChartPrinter) Render() error

Render prints the Template to the terminal.

func (BarChartPrinter) Srender ยถ added in v0.12.7

func (p BarChartPrinter) Srender() (string, error)

Srender renders the BarChart as a string.

func (BarChartPrinter) WithBars ยถ added in v0.12.7

func (p BarChartPrinter) WithBars(bars Bars) *BarChartPrinter

WithBars returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHeight ยถ added in v0.12.7

func (p BarChartPrinter) WithHeight(value int) *BarChartPrinter

WithHeight returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHorizontal ยถ added in v0.12.7

func (p BarChartPrinter) WithHorizontal(b ...bool) *BarChartPrinter

WithHorizontal returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithHorizontalBarCharacter ยถ added in v0.12.7

func (p BarChartPrinter) WithHorizontalBarCharacter(char string) *BarChartPrinter

WithHorizontalBarCharacter returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithShowValue ยถ added in v0.12.7

func (p BarChartPrinter) WithShowValue(b ...bool) *BarChartPrinter

WithShowValue returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithVerticalBarCharacter ยถ added in v0.12.7

func (p BarChartPrinter) WithVerticalBarCharacter(char string) *BarChartPrinter

WithVerticalBarCharacter returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithWidth ยถ added in v0.12.7

func (p BarChartPrinter) WithWidth(value int) *BarChartPrinter

WithWidth returns a new BarChartPrinter with a specific option.

func (BarChartPrinter) WithWriter ยถ added in v0.12.40

func (p BarChartPrinter) WithWriter(writer io.Writer) *BarChartPrinter

WithWriter sets the custom Writer.

type Bars ยถ added in v0.12.7

type Bars []Bar

Bars is used to display multiple Bar.

type BasicTextPrinter ยถ added in v0.6.0

type BasicTextPrinter struct {
	Style  *Style
	Writer io.Writer
}

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 provided writer. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func (*BasicTextPrinter) PrintOnError ยถ added in v0.12.19

func (p *BasicTextPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*BasicTextPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p *BasicTextPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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 provided writer. It returns the number of bytes written and any write error encountered.

func (*BasicTextPrinter) Printfln ยถ added in v0.12.14

func (p *BasicTextPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier and writes to provided writer. 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) 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 provided writer. 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) Sprintfln ยถ added in v0.12.14

func (p BasicTextPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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.

func (BasicTextPrinter) WithWriter ยถ added in v0.12.40

func (p BasicTextPrinter) WithWriter(writer io.Writer) *BasicTextPrinter

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
	Writer        io.Writer
}

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

func (BigTextPrinter) WithWriter ยถ added in v0.12.40

func (p BigTextPrinter) WithWriter(writer io.Writer) *BigTextPrinter

WithWriter sets the custom Writer.

type BoxPrinter ยถ added in v0.12.8

type BoxPrinter struct {
	Title                   string
	TitleTopLeft            bool
	TitleTopRight           bool
	TitleTopCenter          bool
	TitleBottomLeft         bool
	TitleBottomRight        bool
	TitleBottomCenter       bool
	TextStyle               *Style
	VerticalString          string
	BoxStyle                *Style
	HorizontalString        string
	TopRightCornerString    string
	TopLeftCornerString     string
	BottomLeftCornerString  string
	BottomRightCornerString string
	TopPadding              int
	BottomPadding           int
	RightPadding            int
	LeftPadding             int
	Writer                  io.Writer
}

BoxPrinter is able to render a box around printables.

func (BoxPrinter) Print ยถ added in v0.12.8

func (p BoxPrinter) 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 (BoxPrinter) PrintOnError ยถ added in v0.12.19

func (p BoxPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (BoxPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p BoxPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (BoxPrinter) Printf ยถ added in v0.12.8

func (p BoxPrinter) 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 (BoxPrinter) Printfln ยถ added in v0.12.14

func (p BoxPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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 (BoxPrinter) Println ยถ added in v0.12.8

func (p BoxPrinter) 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 (BoxPrinter) Sprint ยถ added in v0.12.8

func (p BoxPrinter) 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 (BoxPrinter) Sprintf ยถ added in v0.12.8

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

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

func (BoxPrinter) Sprintfln ยถ added in v0.12.14

func (p BoxPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (BoxPrinter) Sprintln ยถ added in v0.12.8

func (p BoxPrinter) 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 (BoxPrinter) WithBottomLeftCornerString ยถ added in v0.12.8

func (p BoxPrinter) WithBottomLeftCornerString(str string) *BoxPrinter

WithBottomLeftCornerString returns a new box with a specific BottomLeftCornerString.

func (BoxPrinter) WithBottomPadding ยถ added in v0.12.8

func (p BoxPrinter) WithBottomPadding(padding int) *BoxPrinter

WithBottomPadding returns a new box with a specific BottomPadding.

func (BoxPrinter) WithBottomRightCornerString ยถ added in v0.12.8

func (p BoxPrinter) WithBottomRightCornerString(str string) *BoxPrinter

WithBottomRightCornerString returns a new box with a specific BottomRightCornerString.

func (BoxPrinter) WithBoxStyle ยถ added in v0.12.8

func (p BoxPrinter) WithBoxStyle(style *Style) *BoxPrinter

WithBoxStyle returns a new box with a specific box Style.

func (BoxPrinter) WithHorizontalString ยถ added in v0.12.8

func (p BoxPrinter) WithHorizontalString(str string) *BoxPrinter

WithHorizontalString returns a new box with a specific HorizontalString.

func (BoxPrinter) WithLeftPadding ยถ added in v0.12.8

func (p BoxPrinter) WithLeftPadding(padding int) *BoxPrinter

WithLeftPadding returns a new box with a specific LeftPadding.

func (BoxPrinter) WithRightPadding ยถ added in v0.12.8

func (p BoxPrinter) WithRightPadding(padding int) *BoxPrinter

WithRightPadding returns a new box with a specific RightPadding.

func (BoxPrinter) WithTextStyle ยถ added in v0.12.8

func (p BoxPrinter) WithTextStyle(style *Style) *BoxPrinter

WithTextStyle returns a new box with a specific text Style.

func (BoxPrinter) WithTitle ยถ added in v0.12.24

func (p BoxPrinter) WithTitle(str string) *BoxPrinter

WithTitle returns a new box with a specific Title.

func (BoxPrinter) WithTitleBottomCenter ยถ added in v0.12.24

func (p BoxPrinter) WithTitleBottomCenter(b ...bool) *BoxPrinter

WithTitleBottomCenter returns a new box with a specific Title alignment.

func (BoxPrinter) WithTitleBottomLeft ยถ added in v0.12.24

func (p BoxPrinter) WithTitleBottomLeft(b ...bool) *BoxPrinter

WithTitleBottomLeft returns a new box with a specific Title alignment.

func (BoxPrinter) WithTitleBottomRight ยถ added in v0.12.24

func (p BoxPrinter) WithTitleBottomRight(b ...bool) *BoxPrinter

WithTitleBottomRight returns a new box with a specific Title alignment.

func (BoxPrinter) WithTitleTopCenter ยถ added in v0.12.24

func (p BoxPrinter) WithTitleTopCenter(b ...bool) *BoxPrinter

WithTitleTopCenter returns a new box with a specific Title alignment.

func (BoxPrinter) WithTitleTopLeft ยถ added in v0.12.24

func (p BoxPrinter) WithTitleTopLeft(b ...bool) *BoxPrinter

WithTitleTopLeft returns a new box with a specific Title alignment.

func (BoxPrinter) WithTitleTopRight ยถ added in v0.12.24

func (p BoxPrinter) WithTitleTopRight(b ...bool) *BoxPrinter

WithTitleTopRight returns a new box with a specific Title alignment.

func (BoxPrinter) WithTopLeftCornerString ยถ added in v0.12.8

func (p BoxPrinter) WithTopLeftCornerString(str string) *BoxPrinter

WithTopLeftCornerString returns a new box with a specific TopLeftCornerString.

func (BoxPrinter) WithTopPadding ยถ added in v0.12.8

func (p BoxPrinter) WithTopPadding(padding int) *BoxPrinter

WithTopPadding returns a new box with a specific TopPadding.

func (BoxPrinter) WithTopRightCornerString ยถ added in v0.12.8

func (p BoxPrinter) WithTopRightCornerString(str string) *BoxPrinter

WithTopRightCornerString returns a new box with a specific TopRightCornerString.

func (BoxPrinter) WithVerticalString ยถ added in v0.12.8

func (p BoxPrinter) WithVerticalString(str string) *BoxPrinter

WithVerticalString returns a new box with a specific VerticalString.

func (BoxPrinter) WithWriter ยถ added in v0.12.40

func (p BoxPrinter) WithWriter(writer io.Writer) *BoxPrinter

WithWriter sets the custom Writer.

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 deprecated 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.

Deprecated: use putils.BulletListItemFromString instead.

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 BulletListPrinter ยถ added in v0.12.0

type BulletListPrinter struct {
	Items       []BulletListItem
	TextStyle   *Style
	Bullet      string
	BulletStyle *Style
	Writer      io.Writer
}

BulletListPrinter is able to render a list.

func NewBulletListFromString deprecated added in v0.9.0

func NewBulletListFromString(s string, padding string) BulletListPrinter

NewBulletListFromString returns a BulletListPrinter with Text using the NewTreeListItemFromString method, splitting after return (\n).

Deprecated: use putils.BulletListFromString instead.

func NewBulletListFromStrings deprecated added in v0.9.0

func NewBulletListFromStrings(s []string, padding string) BulletListPrinter

NewBulletListFromStrings returns a BulletListPrinter with Text using the NewTreeListItemFromString method.

Deprecated: use putils.BulletListFromStrings instead.

func (BulletListPrinter) Render ยถ added in v0.12.0

func (l BulletListPrinter) Render() error

Render prints the list to the terminal.

func (BulletListPrinter) Srender ยถ added in v0.12.0

func (l BulletListPrinter) Srender() (string, error)

Srender renders the list as a string.

func (BulletListPrinter) WithBullet ยถ added in v0.12.0

func (l BulletListPrinter) WithBullet(bullet string) *BulletListPrinter

WithBullet returns a new list with a specific bullet.

func (BulletListPrinter) WithBulletStyle ยถ added in v0.12.0

func (l BulletListPrinter) WithBulletStyle(style *Style) *BulletListPrinter

WithBulletStyle returns a new list with a specific bullet style.

func (BulletListPrinter) WithItems ยถ added in v0.12.0

func (l BulletListPrinter) WithItems(items []BulletListItem) *BulletListPrinter

WithItems returns a new list with specific Items.

func (BulletListPrinter) WithTextStyle ยถ added in v0.12.0

func (l BulletListPrinter) WithTextStyle(style *Style) *BulletListPrinter

WithTextStyle returns a new list with a specific text style.

func (BulletListPrinter) WithWriter ยถ added in v0.12.40

func (l BulletListPrinter) WithWriter(writer io.Writer) *BulletListPrinter

WithWriter sets the custom Writer.

type CenterPrinter ยถ added in v0.10.1

type CenterPrinter struct {
	CenterEachLineSeparately bool
	Writer                   io.Writer
}

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) PrintOnError ยถ added in v0.12.19

func (p CenterPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (CenterPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p CenterPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p CenterPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

func (p CenterPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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.

func (CenterPrinter) WithWriter ยถ added in v0.12.40

func (p CenterPrinter) WithWriter(writer io.Writer) *CenterPrinter

WithWriter sets the custom Writer.

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{}) *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. Input will be colored with the parent Color.

func (Color) PrintOnError ยถ added in v0.12.19

func (c Color) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (Color) PrintOnErrorf ยถ added in v0.12.33

func (c Color) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (Color) Printf ยถ

func (c Color) 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. Input will be colored with the parent Color.

func (Color) Printfln ยถ added in v0.12.14

func (c Color) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) Println ยถ

func (c Color) 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. 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) Sprintfln ยถ added in v0.12.14

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

Sprintfln formats according to a format specifier 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) 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 HeaderPrinter ยถ added in v0.0.1

type HeaderPrinter struct {
	TextStyle       *Style
	BackgroundStyle *Style
	Margin          int
	FullWidth       bool
	Writer          io.Writer
}

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) PrintOnError ยถ added in v0.12.19

func (p *HeaderPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*HeaderPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p *HeaderPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p *HeaderPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

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

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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

func (HeaderPrinter) WithWriter ยถ added in v0.12.40

func (p HeaderPrinter) WithWriter(writer io.Writer) *HeaderPrinter

WithWriter sets the custom Writer.

type InteractiveConfirmPrinter ยถ added in v0.12.42

type InteractiveConfirmPrinter struct {
	DefaultValue bool
	DefaultText  string
	TextStyle    *Style
	ConfirmText  string
	ConfirmStyle *Style
	RejectText   string
	RejectStyle  *Style
	SuffixStyle  *Style
}

InteractiveConfirmPrinter is a printer for interactive confirm prompts.

func (InteractiveConfirmPrinter) Show ยถ added in v0.12.42

func (p InteractiveConfirmPrinter) Show(text ...string) (bool, error)

Show shows the confirm prompt.

Example:

result, _ := pterm.DefaultInteractiveConfirm.Show("Are you sure?")
pterm.Println(result)

func (InteractiveConfirmPrinter) WithConfirmStyle ยถ added in v0.12.42

func (p InteractiveConfirmPrinter) WithConfirmStyle(style *Style) *InteractiveConfirmPrinter

WithConfirmStyle sets the confirm style.

func (InteractiveConfirmPrinter) WithConfirmText ยถ added in v0.12.42

WithConfirmText sets the confirm text.

func (InteractiveConfirmPrinter) WithDefaultText ยถ added in v0.12.42

WithDefaultText sets the default text.

func (InteractiveConfirmPrinter) WithDefaultValue ยถ added in v0.12.42

func (p InteractiveConfirmPrinter) WithDefaultValue(value bool) *InteractiveConfirmPrinter

WithDefaultValue sets the default value, which will be returned when the user presses enter without typing "y" or "n".

func (InteractiveConfirmPrinter) WithRejectStyle ยถ added in v0.12.42

func (p InteractiveConfirmPrinter) WithRejectStyle(style *Style) *InteractiveConfirmPrinter

WithRejectStyle sets the reject style.

func (InteractiveConfirmPrinter) WithRejectText ยถ added in v0.12.42

WithRejectText sets the reject text.

func (InteractiveConfirmPrinter) WithSuffixStyle ยถ added in v0.12.42

func (p InteractiveConfirmPrinter) WithSuffixStyle(style *Style) *InteractiveConfirmPrinter

WithSuffixStyle sets the suffix style.

func (InteractiveConfirmPrinter) WithTextStyle ยถ added in v0.12.42

WithTextStyle sets the text style.

type InteractiveContinuePrinter ยถ added in v0.12.47

type InteractiveContinuePrinter struct {
	DefaultValueIndex int
	DefaultText       string
	TextStyle         *Style
	Options           []string
	OptionsStyle      *Style
	Handles           []string
	ShowShortHandles  bool
	SuffixStyle       *Style
}

InteractiveContinuePrinter is a printer for interactive continue prompts.

func (InteractiveContinuePrinter) Show ยถ added in v0.12.47

func (p InteractiveContinuePrinter) Show(text ...string) (string, error)

Show shows the continue prompt.

Example:

result, _ := pterm.DefaultInteractiveContinue.Show("Do you want to apply the changes?")
pterm.Println(result)

func (InteractiveContinuePrinter) WithDefaultText ยถ added in v0.12.47

WithDefaultText sets the default text.

func (InteractiveContinuePrinter) WithDefaultValue ยถ added in v0.12.47

WithDefaultValue sets the default value, which will be returned when the user presses enter without typing any letter.

func (InteractiveContinuePrinter) WithDefaultValueIndex ยถ added in v0.12.47

func (p InteractiveContinuePrinter) WithDefaultValueIndex(value int) *InteractiveContinuePrinter

WithDefaultValueIndex sets the default value, which will be returned when the user presses enter without typing any letter.

func (InteractiveContinuePrinter) WithHandles ยถ added in v0.12.47

WithHandles allows you to customize the short handles for the answers.

func (InteractiveContinuePrinter) WithOptions ยถ added in v0.12.47

WithOptions sets the options.

func (InteractiveContinuePrinter) WithOptionsStyle ยถ added in v0.12.47

func (p InteractiveContinuePrinter) WithOptionsStyle(style *Style) *InteractiveContinuePrinter

WithOptionsStyle sets the continue style.

func (InteractiveContinuePrinter) WithShowShortHandles ยถ added in v0.12.47

func (p InteractiveContinuePrinter) WithShowShortHandles(b ...bool) *InteractiveContinuePrinter

WithShowShortHandles will set ShowShortHandles to true this makes the printer display the shorthand options instead their shorthand version.

func (InteractiveContinuePrinter) WithSuffixStyle ยถ added in v0.12.47

func (p InteractiveContinuePrinter) WithSuffixStyle(style *Style) *InteractiveContinuePrinter

WithSuffixStyle sets the suffix style.

func (InteractiveContinuePrinter) WithTextStyle ยถ added in v0.12.47

WithTextStyle sets the text style.

type InteractiveMultiselectPrinter ยถ added in v0.12.42

type InteractiveMultiselectPrinter struct {
	DefaultText    string
	TextStyle      *Style
	Options        []string
	OptionStyle    *Style
	DefaultOptions []string
	MaxHeight      int
	Selector       string
	SelectorStyle  *Style
	Filter         bool

	KeySelect  keys.KeyCode
	KeyConfirm keys.KeyCode
	// contains filtered or unexported fields
}

InteractiveMultiselectPrinter is a printer for interactive multiselect menus.

func (*InteractiveMultiselectPrinter) Show ยถ added in v0.12.42

func (p *InteractiveMultiselectPrinter) Show(text ...string) ([]string, error)

Show shows the interactive multiselect menu and returns the selected entry.

func (InteractiveMultiselectPrinter) WithDefaultOptions ยถ added in v0.12.42

func (p InteractiveMultiselectPrinter) WithDefaultOptions(options []string) *InteractiveMultiselectPrinter

WithDefaultOptions sets the default options.

func (InteractiveMultiselectPrinter) WithDefaultText ยถ added in v0.12.42

WithDefaultText sets the default text.

func (InteractiveMultiselectPrinter) WithFilter ยถ added in v0.12.48

WithFilter sets the Filter option

func (InteractiveMultiselectPrinter) WithKeyConfirm ยถ added in v0.12.48

WithKeyConfirm sets the confirm key

func (InteractiveMultiselectPrinter) WithKeySelect ยถ added in v0.12.48

WithKeySelect sets the confirm key

func (InteractiveMultiselectPrinter) WithMaxHeight ยถ added in v0.12.42

WithMaxHeight sets the maximum height of the select menu.

func (InteractiveMultiselectPrinter) WithOptions ยถ added in v0.12.42

WithOptions sets the options.

type InteractiveSelectPrinter ยถ added in v0.12.42

type InteractiveSelectPrinter struct {
	TextStyle     *Style
	DefaultText   string
	Options       []string
	OptionStyle   *Style
	DefaultOption string
	MaxHeight     int
	Selector      string
	SelectorStyle *Style
	// contains filtered or unexported fields
}

InteractiveSelectPrinter is a printer for interactive select menus.

func (*InteractiveSelectPrinter) Show ยถ added in v0.12.42

func (p *InteractiveSelectPrinter) Show(text ...string) (string, error)

Show shows the interactive select menu and returns the selected entry.

func (InteractiveSelectPrinter) WithDefaultOption ยถ added in v0.12.42

func (p InteractiveSelectPrinter) WithDefaultOption(option string) *InteractiveSelectPrinter

WithDefaultOption sets the default options.

func (InteractiveSelectPrinter) WithDefaultText ยถ added in v0.12.42

func (p InteractiveSelectPrinter) WithDefaultText(text string) *InteractiveSelectPrinter

WithDefaultText sets the default text.

func (InteractiveSelectPrinter) WithMaxHeight ยถ added in v0.12.42

func (p InteractiveSelectPrinter) WithMaxHeight(maxHeight int) *InteractiveSelectPrinter

WithMaxHeight sets the maximum height of the select menu.

func (InteractiveSelectPrinter) WithOptions ยถ added in v0.12.42

func (p InteractiveSelectPrinter) WithOptions(options []string) *InteractiveSelectPrinter

WithOptions sets the options.

type InteractiveTextInputPrinter ยถ added in v0.12.42

type InteractiveTextInputPrinter struct {
	TextStyle   *Style
	DefaultText string
	MultiLine   bool
	// contains filtered or unexported fields
}

InteractiveTextInputPrinter is a printer for interactive select menus.

func (InteractiveTextInputPrinter) Show ยถ added in v0.12.42

func (p InteractiveTextInputPrinter) Show(text ...string) (string, error)

Show shows the interactive select menu and returns the selected entry.

func (InteractiveTextInputPrinter) WithDefaultText ยถ added in v0.12.42

WithDefaultText sets the default text.

func (InteractiveTextInputPrinter) WithMultiLine ยถ added in v0.12.42

func (p InteractiveTextInputPrinter) WithMultiLine(multiLine ...bool) *InteractiveTextInputPrinter

WithMultiLine sets the multi line flag.

func (InteractiveTextInputPrinter) WithTextStyle ยถ added in v0.12.42

WithTextStyle sets the text style.

type Letter ยถ added in v0.8.0

type Letter struct {
	String string
	Style  *Style
	RGB    RGB
}

Letter is an object, which holds a string and a specific Style for it.

func (Letter) WithRGB ยถ added in v0.12.38

func (l Letter) WithRGB(rgb RGB) *Letter

WithRGB returns a new Letter with a specific RGB color (overwrites style).

func (Letter) WithString ยถ added in v0.8.0

func (l Letter) WithString(s string) *Letter

WithString returns a new Letter with a specific String.

func (Letter) WithStyle ยถ added in v0.8.0

func (l Letter) WithStyle(style *Style) *Letter

WithStyle returns a new Letter with a specific Style.

type Letters ยถ added in v0.8.0

type Letters []Letter

Letters is a slice of Letter.

func NewLettersFromString deprecated added in v0.8.0

func NewLettersFromString(text string) Letters

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.

Deprecated: use putils.LettersFromString instead.

func NewLettersFromStringWithRGB deprecated added in v0.12.38

func NewLettersFromStringWithRGB(text string, rgb RGB) Letters

NewLettersFromStringWithRGB creates a Letters object from a string and applies an RGB color to it (overwrites style).

Deprecated: use putils.LettersFromStringWithRGB instead.

func NewLettersFromStringWithStyle deprecated added in v0.8.0

func NewLettersFromStringWithStyle(text string, style *Style) Letters

NewLettersFromStringWithStyle creates a Letters object from a string and applies a Style to it.

Deprecated: use putils.LettersFromStringWithStyle instead.

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

type LeveledListItem struct {
	Level int
	Text  string
}

LeveledListItem combines a text with a specific level. The level is the indent, which would normally be seen in a BulletListPrinter.

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

type PanelPrinter struct {
	Panels          Panels
	Padding         int
	BottomPadding   int
	SameColumnWidth bool
	BoxPrinter      BoxPrinter
	Writer          io.Writer
}

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) WithBottomPadding ยถ added in v0.12.0

func (p PanelPrinter) WithBottomPadding(bottomPadding int) *PanelPrinter

WithBottomPadding returns a new PanelPrinter with specific options.

func (PanelPrinter) WithBoxPrinter ยถ added in v0.12.8

func (p PanelPrinter) WithBoxPrinter(boxPrinter BoxPrinter) *PanelPrinter

WithBoxPrinter returns a new PanelPrinter with specific options.

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.

func (PanelPrinter) WithSameColumnWidth ยถ added in v0.12.0

func (p PanelPrinter) WithSameColumnWidth(b ...bool) *PanelPrinter

WithSameColumnWidth returns a new PanelPrinter with specific options.

func (PanelPrinter) WithWriter ยถ added in v0.12.40

func (p PanelPrinter) WithWriter(writer io.Writer) *PanelPrinter

WithWriter sets the custom Writer.

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
	Writer   io.Writer
}

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) PrintOnError ยถ added in v0.12.19

func (p *ParagraphPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*ParagraphPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p *ParagraphPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p *ParagraphPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

func (p ParagraphPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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

func (ParagraphPrinter) WithWriter ยถ added in v0.12.40

func (p ParagraphPrinter) WithWriter(writer io.Writer) *ParagraphPrinter

WithWriter sets the custom Writer.

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
	ShowLineNumber   bool
	LineNumberOffset int
	Writer           io.Writer
	// 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) PrintOnError ยถ added in v0.12.15

func (p *PrefixPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

Note: Use WithFatal(true) or Fatal to panic after first non nil error.

func (*PrefixPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p *PrefixPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p *PrefixPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

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

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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) WithLineNumberOffset ยถ added in v0.12.31

func (p PrefixPrinter) WithLineNumberOffset(offset int) *PrefixPrinter

WithLineNumberOffset can be used to exclude a specific amount of calls in the call stack. If you make a wrapper function for example, you can set this to one. The printed line number will then be the line number where your wrapper function 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.

func (PrefixPrinter) WithShowLineNumber ยถ added in v0.12.12

func (p PrefixPrinter) WithShowLineNumber(b ...bool) *PrefixPrinter

WithShowLineNumber sets if the printer should print the line number from where it's called in a go file.

func (PrefixPrinter) WithWriter ยถ added in v0.12.40

func (p PrefixPrinter) WithWriter(writer io.Writer) *PrefixPrinter

WithWriter sets the custom Writer.

type ProgressbarPrinter ยถ added in v0.12.0

type ProgressbarPrinter struct {
	Title                     string
	Total                     int
	Current                   int
	BarCharacter              string
	LastCharacter             string
	ElapsedTimeRoundingFactor time.Duration
	BarFiller                 string
	MaxWidth                  int

	ShowElapsedTime bool
	ShowCount       bool
	ShowTitle       bool
	ShowPercentage  bool
	RemoveWhenDone  bool

	TitleStyle *Style
	BarStyle   *Style

	IsActive bool

	Writer io.Writer
	// contains filtered or unexported fields
}

ProgressbarPrinter shows a progress animation in the terminal.

func (*ProgressbarPrinter) Add ยถ added in v0.12.0

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

Add to current value.

func (ProgressbarPrinter) GenericStart ยถ added in v0.12.0

func (p ProgressbarPrinter) 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 (ProgressbarPrinter) GenericStop ยถ added in v0.12.0

func (p ProgressbarPrinter) 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 (*ProgressbarPrinter) GetElapsedTime ยถ added in v0.12.0

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

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

func (*ProgressbarPrinter) Increment ยถ added in v0.12.0

func (p *ProgressbarPrinter) Increment() *ProgressbarPrinter

Increment current value by one.

func (ProgressbarPrinter) Start ยถ added in v0.12.0

Start the ProgressbarPrinter.

func (*ProgressbarPrinter) Stop ยถ added in v0.12.0

Stop the ProgressbarPrinter.

func (*ProgressbarPrinter) UpdateTitle ยถ added in v0.12.33

func (p *ProgressbarPrinter) UpdateTitle(title string) *ProgressbarPrinter

UpdateTitle updates the title and re-renders the progressbar

func (ProgressbarPrinter) WithBarCharacter ยถ added in v0.12.0

func (p ProgressbarPrinter) WithBarCharacter(char string) *ProgressbarPrinter

WithBarCharacter sets the bar character of the ProgressbarPrinter.

func (ProgressbarPrinter) WithBarFiller ยถ added in v0.12.37

func (p ProgressbarPrinter) WithBarFiller(char string) *ProgressbarPrinter

WithBarFiller sets the filler character for the ProgressbarPrinter.

func (ProgressbarPrinter) WithBarStyle ยถ added in v0.12.0

func (p ProgressbarPrinter) WithBarStyle(style *Style) *ProgressbarPrinter

WithBarStyle sets the style of the bar.

func (ProgressbarPrinter) WithCurrent ยถ added in v0.12.0

func (p ProgressbarPrinter) WithCurrent(current int) *ProgressbarPrinter

WithCurrent sets the current value of the ProgressbarPrinter.

func (ProgressbarPrinter) WithElapsedTimeRoundingFactor ยถ added in v0.12.0

func (p ProgressbarPrinter) WithElapsedTimeRoundingFactor(duration time.Duration) *ProgressbarPrinter

WithElapsedTimeRoundingFactor sets the rounding factor of the elapsed time.

func (ProgressbarPrinter) WithLastCharacter ยถ added in v0.12.0

func (p ProgressbarPrinter) WithLastCharacter(char string) *ProgressbarPrinter

WithLastCharacter sets the last character of the ProgressbarPrinter.

func (ProgressbarPrinter) WithMaxWidth ยถ added in v0.12.37

func (p ProgressbarPrinter) WithMaxWidth(maxWidth int) *ProgressbarPrinter

WithMaxWidth sets the maximum width of the ProgressbarPrinter. If the terminal is smaller than the given width, the terminal width will be used instead. If the width is set to zero, or below, the terminal width will be used.

func (ProgressbarPrinter) WithRemoveWhenDone ยถ added in v0.12.0

func (p ProgressbarPrinter) WithRemoveWhenDone(b ...bool) *ProgressbarPrinter

WithRemoveWhenDone sets if the ProgressbarPrinter should be removed when it is done.

func (ProgressbarPrinter) WithShowCount ยถ added in v0.12.0

func (p ProgressbarPrinter) WithShowCount(b ...bool) *ProgressbarPrinter

WithShowCount sets if the total and current count should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowElapsedTime ยถ added in v0.12.0

func (p ProgressbarPrinter) WithShowElapsedTime(b ...bool) *ProgressbarPrinter

WithShowElapsedTime sets if the elapsed time should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowPercentage ยถ added in v0.12.0

func (p ProgressbarPrinter) WithShowPercentage(b ...bool) *ProgressbarPrinter

WithShowPercentage sets if the completed percentage should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithShowTitle ยถ added in v0.12.0

func (p ProgressbarPrinter) WithShowTitle(b ...bool) *ProgressbarPrinter

WithShowTitle sets if the title should be displayed in the ProgressbarPrinter.

func (ProgressbarPrinter) WithTitle ยถ added in v0.12.0

func (p ProgressbarPrinter) WithTitle(name string) *ProgressbarPrinter

WithTitle sets the name of the ProgressbarPrinter.

func (ProgressbarPrinter) WithTitleStyle ยถ added in v0.12.0

func (p ProgressbarPrinter) WithTitleStyle(style *Style) *ProgressbarPrinter

WithTitleStyle sets the style of the title.

func (ProgressbarPrinter) WithTotal ยถ added in v0.12.0

func (p ProgressbarPrinter) WithTotal(total int) *ProgressbarPrinter

WithTotal sets the total value of the ProgressbarPrinter.

func (ProgressbarPrinter) WithWriter ยถ added in v0.12.42

func (p ProgressbarPrinter) WithWriter(writer io.Writer) *ProgressbarPrinter

WithWriter sets the custom Writer.

type RGB ยถ added in v0.5.1

type RGB struct {
	R uint8
	G uint8
	B uint8
}

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 NewRGB ยถ added in v0.5.1

func NewRGB(r, g, b uint8) RGB

NewRGB returns a new RGB.

func NewRGBFromHEX deprecated added in v0.5.1

func NewRGBFromHEX(hex string) (RGB, error)

NewRGBFromHEX converts a HEX and returns a new RGB.

Deprecated: use putils.RGBFromHEX instead.

func (RGB) Fade ยถ added in v0.5.1

func (p RGB) Fade(min, max, current float32, end ...RGB) RGB

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) GetValues ยถ added in v0.5.1

func (p RGB) GetValues() (r, g, b uint8)

GetValues returns the RGB values separately.

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) PrintOnError ยถ added in v0.12.19

func (p RGB) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (RGB) PrintOnErrorf ยถ added in v0.12.33

func (p RGB) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p RGB) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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

func (p RGB) 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 (RGB) Sprintf ยถ added in v0.5.1

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

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

func (RGB) Sprintfln ยถ added in v0.12.14

func (p RGB) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

func (RGB) Sprintln ยถ added in v0.5.1

func (p RGB) 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 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 ยถ

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 SectionPrinter ยถ added in v0.3.2

type SectionPrinter struct {
	Style           *Style
	Level           int
	IndentCharacter string
	TopPadding      int
	BottomPadding   int
	Writer          io.Writer
}

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) PrintOnError ยถ added in v0.12.19

func (p *SectionPrinter) PrintOnError(a ...interface{}) *TextPrinter

PrintOnError prints every error which is not nil. If every error is nil, nothing will be printed. This can be used for simple error checking.

func (*SectionPrinter) PrintOnErrorf ยถ added in v0.12.33

func (p *SectionPrinter) PrintOnErrorf(format string, a ...interface{}) *TextPrinter

PrintOnErrorf wraps every error which is not nil and prints it. If every error is nil, nothing will be printed. This can be used for simple error checking.

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) Printfln ยถ added in v0.12.14

func (p *SectionPrinter) Printfln(format string, a ...interface{}) *TextPrinter

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

func (p SectionPrinter) Sprintfln(format string, a ...interface{}) string

Sprintfln formats according to a format specifier and returns the resulting string. Spaces are always added between operands and a newline is appended.

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.

func (SectionPrinter) WithWriter ยถ added in v0.12.40

func (p SectionPrinter) WithWriter(writer io.Writer) *SectionPrinter

WithWriter sets the custom Writer.

type SpinnerPrinter ยถ added in v0.12.0

type SpinnerPrinter struct {
	Text                string
	Sequence            []string
	Style               *Style
	Delay               time.Duration
	MessageStyle        *Style
	InfoPrinter         TextPrinter
	SuccessPrinter      TextPrinter
	FailPrinter         TextPrinter
	WarningPrinter      TextPrinter
	RemoveWhenDone      bool
	ShowTimer           bool
	TimerRoundingFactor time.Duration
	TimerStyle          *Style

	IsActive bool

	Writer io.Writer
	// contains filtered or unexported fields
}

SpinnerPrinter 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 SpinnerPrinter is done.

func (*SpinnerPrinter) Fail ยถ added in v0.12.0

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

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

func (*SpinnerPrinter) GenericStart ยถ added in v0.12.0

func (s *SpinnerPrinter) 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 (*SpinnerPrinter) GenericStop ยถ added in v0.12.0

func (s *SpinnerPrinter) 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 (*SpinnerPrinter) Info ยถ added in v0.12.44

func (s *SpinnerPrinter) Info(message ...interface{})

Info displays an info message If no message is given, the text of the SpinnerPrinter will be reused as the default message.

func (SpinnerPrinter) Start ยถ added in v0.12.0

func (s SpinnerPrinter) Start(text ...interface{}) (*SpinnerPrinter, error)

Start the SpinnerPrinter.

func (*SpinnerPrinter) Stop ยถ added in v0.12.0

func (s *SpinnerPrinter) Stop() error

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

func (*SpinnerPrinter) Success ยถ added in v0.12.0

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

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

func (*SpinnerPrinter) UpdateText ยถ added in v0.12.0

func (s *SpinnerPrinter) UpdateText(text string)

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

func (*SpinnerPrinter) Warning ยถ added in v0.12.0

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

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

func (SpinnerPrinter) WithDelay ยถ added in v0.12.0

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

WithDelay adds a delay to the SpinnerPrinter.

func (SpinnerPrinter) WithMessageStyle ยถ added in v0.12.0

func (s SpinnerPrinter) WithMessageStyle(style *Style) *SpinnerPrinter

WithMessageStyle adds a style to the SpinnerPrinter message.

func (SpinnerPrinter) WithRemoveWhenDone ยถ added in v0.12.0

func (s SpinnerPrinter) WithRemoveWhenDone(b ...bool) *SpinnerPrinter

WithRemoveWhenDone removes the SpinnerPrinter after it is done.

func (SpinnerPrinter) WithSequence ยถ added in v0.12.0

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

WithSequence adds a sequence to the SpinnerPrinter.

func (SpinnerPrinter) WithShowTimer ยถ added in v0.12.28

func (s SpinnerPrinter) WithShowTimer(b ...bool) *SpinnerPrinter

WithShowTimer shows how long the spinner is running.

func (SpinnerPrinter) WithStyle ยถ added in v0.12.0

func (s SpinnerPrinter) WithStyle(style *Style) *SpinnerPrinter

WithStyle adds a style to the SpinnerPrinter.

func (SpinnerPrinter) WithText ยถ added in v0.12.0

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

WithText adds a text to the SpinnerPrinter.

func (SpinnerPrinter) WithTimerRoundingFactor ยถ added in v0.12.28

func (s SpinnerPrinter) WithTimerRoundingFactor(factor time.Duration) *SpinnerPrinter

WithTimerRoundingFactor sets the rounding factor for the timer.

func (SpinnerPrinter) WithTimerStyle ยถ added in v0.12.28

func (s SpinnerPrinter) WithTimerStyle(style *Style) *SpinnerPrinter

WithTimerStyle adds a style to the SpinnerPrinter timer.

func (SpinnerPrinter) WithWriter ยถ added in v0.12.42

func (p SpinnerPrinter) WithWriter(writer io.Writer) *SpinnerPrinter

WithWriter sets the custom Writer.

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) Add ยถ added in v0.4.0

func (s Style) Add(styles ...Style) Style

Add styles to the current Style.

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) Printfln ยถ added in v0.12.14

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

Printfln formats according to a format specifier 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) 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) Sprintfln ยถ added in v0.12.14

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

Sprintfln formats according to a format specifier 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) 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".

type TableData ยถ added in v0.5.0

type TableData [][]string

TableData is the type that contains the data of a TablePrinter.

type TablePrinter ยถ added in v0.12.0

type TablePrinter struct {
	Style                   *Style
	HasHeader               bool
	HeaderStyle             *Style
	HeaderRowSeparator      string
	HeaderRowSeparatorStyle *Style
	Separator               string
	SeparatorStyle          *Style
	RowSeparator            string
	RowSeparatorStyle       *Style
	Data                    TableData
	Boxed                   bool
	LeftAlignment           bool
	RightAlignment          bool
	Writer                  io.Writer
}

TablePrinter is able to render tables.

func (TablePrinter) Render ยถ added in v0.12.0

func (p TablePrinter) Render() error

Render prints the TablePrinter to the terminal.

func (TablePrinter) Srender ยถ added in v0.12.0

func (p TablePrinter) Srender() (string, error)

Srender renders the TablePrinter as a string.

func (TablePrinter) WithBoxed ยถ added in v0.12.25

func (p TablePrinter) WithBoxed(b ...bool) *TablePrinter

WithBoxed returns a new TablePrinter with a box around the table.

func (TablePrinter) WithCSVReader ยถ added in v0.12.0

func (p TablePrinter) WithCSVReader(reader *csv.Reader) *TablePrinter

WithCSVReader return a new TablePrinter with specified Data extracted from CSV.

func (TablePrinter) WithData ยถ added in v0.12.0

func (p TablePrinter) WithData(data [][]string) *TablePrinter

WithData returns a new TablePrinter with specific Data.

func (TablePrinter) WithHasHeader ยถ added in v0.12.0

func (p TablePrinter) WithHasHeader(b ...bool) *TablePrinter

WithHasHeader returns a new TablePrinter, where the first line is marked as a header.

func (TablePrinter) WithHeaderRowSeparator ยถ added in v0.12.36

func (p TablePrinter) WithHeaderRowSeparator(separator string) *TablePrinter

WithHeaderRowSeparator returns a new TablePrinter with a specific header HeaderRowSeparator.

func (TablePrinter) WithHeaderRowSeparatorStyle ยถ added in v0.12.36

func (p TablePrinter) WithHeaderRowSeparatorStyle(style *Style) *TablePrinter

WithHeaderRowSeparatorStyle returns a new TablePrinter with a specific header HeaderRowSeparatorStyle.

func (TablePrinter) WithHeaderStyle ยถ added in v0.12.0

func (p TablePrinter) WithHeaderStyle(style *Style) *TablePrinter

WithHeaderStyle returns a new TablePrinter with a specific HeaderStyle.

func (TablePrinter) WithLeftAlignment ยถ added in v0.12.33

func (p TablePrinter) WithLeftAlignment(b ...bool) *TablePrinter

WithLeftAlignment returns a new TablePrinter with left alignment.

func (TablePrinter) WithRightAlignment ยถ added in v0.12.33

func (p TablePrinter) WithRightAlignment(b ...bool) *TablePrinter

WithRightAlignment returns a new TablePrinter with right alignment.

func (TablePrinter) WithRowSeparator ยถ added in v0.12.36

func (p TablePrinter) WithRowSeparator(separator string) *TablePrinter

WithRowSeparator returns a new TablePrinter with a specific RowSeparator.

func (TablePrinter) WithRowSeparatorStyle ยถ added in v0.12.36

func (p TablePrinter) WithRowSeparatorStyle(style *Style) *TablePrinter

WithRowSeparatorStyle returns a new TablePrinter with a specific RowSeparatorStyle.

func (TablePrinter) WithSeparator ยถ added in v0.12.0

func (p TablePrinter) WithSeparator(separator string) *TablePrinter

WithSeparator returns a new TablePrinter with a specific separator.

func (TablePrinter) WithSeparatorStyle ยถ added in v0.12.0

func (p TablePrinter) WithSeparatorStyle(style *Style) *TablePrinter

WithSeparatorStyle returns a new TablePrinter with a specific SeparatorStyle.

func (TablePrinter) WithStyle ยถ added in v0.12.0

func (p TablePrinter) WithStyle(style *Style) *TablePrinter

WithStyle returns a new TablePrinter with a specific Style.

func (TablePrinter) WithWriter ยถ added in v0.12.40

func (p TablePrinter) WithWriter(writer io.Writer) *TablePrinter

WithWriter sets the Writer.

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

	// Sprintfln formats according to a format specifier and returns the resulting string.
	// Spaces are always added between operands and a newline is appended.
	Sprintfln(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

	// Printfln formats according to a format specifier 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.
	Printfln(format string, a ...interface{}) *TextPrinter

	// PrintOnError prints every error which is not nil.
	// If every error is nil, nothing will be printed.
	// This can be used for simple error checking.
	PrintOnError(a ...interface{}) *TextPrinter

	// PrintOnErrorf wraps every error which is not nil and prints it.
	// If every error is nil, nothing will be printed.
	// This can be used for simple error checking.
	PrintOnErrorf(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 {
	DefaultText             Style
	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
	TimerStyle              Style
	TableStyle              Style
	TableHeaderStyle        Style
	TableSeparatorStyle     Style
	SectionStyle            Style
	BulletListTextStyle     Style
	BulletListBulletStyle   Style
	TreeStyle               Style
	TreeTextStyle           Style
	LetterStyle             Style
	DebugMessageStyle       Style
	DebugPrefixStyle        Style
	BoxStyle                Style
	BoxTextStyle            Style
	BarLabelStyle           Style
	BarStyle                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) WithBarLabelStyle ยถ added in v0.12.7

func (t Theme) WithBarLabelStyle(style Style) Theme

WithBarLabelStyle returns a new theme with overridden value.

func (Theme) WithBarStyle ยถ added in v0.12.7

func (t Theme) WithBarStyle(style Style) Theme

WithBarStyle returns a new theme with overridden value.

func (Theme) WithBoxStyle ยถ added in v0.12.8

func (t Theme) WithBoxStyle(style Style) Theme

WithBoxStyle returns a new theme with overridden value.

func (Theme) WithBoxTextStyle ยถ added in v0.12.8

func (t Theme) WithBoxTextStyle(style Style) Theme

WithBoxTextStyle returns a new theme with overridden value.

func (Theme) WithBulletListBulletStyle ยถ added in v0.10.0

func (t Theme) WithBulletListBulletStyle(style Style) Theme

WithBulletListBulletStyle returns a new theme with overridden value.

func (Theme) WithBulletListTextStyle ยถ added in v0.10.0

func (t Theme) WithBulletListTextStyle(style Style) Theme

WithBulletListTextStyle returns a new theme with overridden value.

func (Theme) WithDebugMessageStyle ยถ added in v0.9.0

func (t Theme) WithDebugMessageStyle(style Style) Theme

WithDebugMessageStyle returns a new theme with overridden value.

func (Theme) WithDebugPrefixStyle ยถ added in v0.9.0

func (t Theme) WithDebugPrefixStyle(style Style) Theme

WithDebugPrefixStyle returns a new theme with overridden value.

func (Theme) WithDescriptionMessageStyle ยถ added in v0.6.0

func (t Theme) WithDescriptionMessageStyle(style Style) Theme

WithDescriptionMessageStyle returns a new theme with overridden value.

func (Theme) WithDescriptionPrefixStyle ยถ added in v0.6.0

func (t Theme) WithDescriptionPrefixStyle(style Style) Theme

WithDescriptionPrefixStyle returns a new theme with overridden value.

func (Theme) WithErrorMessageStyle ยถ added in v0.6.0

func (t Theme) WithErrorMessageStyle(style Style) Theme

WithErrorMessageStyle returns a new theme with overridden value.

func (Theme) WithErrorPrefixStyle ยถ added in v0.6.0

func (t Theme) WithErrorPrefixStyle(style Style) Theme

WithErrorPrefixStyle returns a new theme with overridden value.

func (Theme) WithFatalMessageStyle ยถ added in v0.6.0

func (t Theme) WithFatalMessageStyle(style Style) Theme

WithFatalMessageStyle returns a new theme with overridden value.

func (Theme) WithFatalPrefixStyle ยถ added in v0.6.0

func (t Theme) WithFatalPrefixStyle(style Style) Theme

WithFatalPrefixStyle returns a new theme with overridden value.

func (Theme) WithHighlightStyle ยถ added in v0.6.0

func (t Theme) WithHighlightStyle(style Style) Theme

WithHighlightStyle returns a new theme with overridden value.

func (Theme) WithInfoMessageStyle ยถ added in v0.6.0

func (t Theme) WithInfoMessageStyle(style Style) Theme

WithInfoMessageStyle returns a new theme with overridden value.

func (Theme) WithInfoPrefixStyle ยถ added in v0.6.0

func (t Theme) WithInfoPrefixStyle(style Style) Theme

WithInfoPrefixStyle returns a new theme with overridden value.

func (Theme) WithLetterStyle ยถ added in v0.8.0

func (t Theme) WithLetterStyle(style Style) Theme

WithLetterStyle returns a new theme with overridden value.

func (Theme) WithPrimaryStyle ยถ added in v0.6.0

func (t Theme) WithPrimaryStyle(style Style) Theme

WithPrimaryStyle returns a new theme with overridden value.

func (Theme) WithSecondaryStyle ยถ added in v0.6.0

func (t Theme) WithSecondaryStyle(style Style) Theme

WithSecondaryStyle returns a new theme with overridden value.

func (Theme) WithSuccessMessageStyle ยถ added in v0.6.0

func (t Theme) WithSuccessMessageStyle(style Style) Theme

WithSuccessMessageStyle returns a new theme with overridden value.

func (Theme) WithSuccessPrefixStyle ยถ added in v0.6.0

func (t Theme) WithSuccessPrefixStyle(style Style) Theme

WithSuccessPrefixStyle returns a new theme with overridden value.

func (Theme) WithTreeStyle ยถ added in v0.9.3

func (t Theme) WithTreeStyle(style Style) Theme

WithTreeStyle returns a new theme with overridden value.

func (Theme) WithTreeTextStyle ยถ added in v0.9.3

func (t Theme) WithTreeTextStyle(style Style) Theme

WithTreeTextStyle returns a new theme with overridden value.

func (Theme) WithWarningMessageStyle ยถ added in v0.6.0

func (t Theme) WithWarningMessageStyle(style Style) Theme

WithWarningMessageStyle returns a new theme with overridden value.

func (Theme) WithWarningPrefixStyle ยถ added in v0.6.0

func (t Theme) WithWarningPrefixStyle(style Style) Theme

WithWarningPrefixStyle returns a new theme with overridden value.

type TreeNode ยถ added in v0.9.3

type TreeNode struct {
	Children []TreeNode
	Text     string
}

TreeNode is used as items in a TreePrinter.

func NewTreeFromLeveledList deprecated added in v0.9.3

func NewTreeFromLeveledList(leveledListItems LeveledList) TreeNode

NewTreeFromLeveledList converts a TreeItems list to a TreeNode and returns it.

Deprecated: use putils.TreeFromLeveledList instead.

type TreePrinter ยถ added in v0.12.0

type TreePrinter struct {
	Root                 TreeNode
	TreeStyle            *Style
	TextStyle            *Style
	TopRightCornerString string
	TopRightDownString   string
	HorizontalString     string
	VerticalString       string
	RightDownLeftString  string
	Indent               int
	Writer               io.Writer
}

TreePrinter is able to render a list.

func (TreePrinter) Render ยถ added in v0.12.0

func (p TreePrinter) Render() error

Render prints the list to the terminal.

func (TreePrinter) Srender ยถ added in v0.12.0

func (p TreePrinter) Srender() (string, error)

Srender renders the list as a string.

func (TreePrinter) WithHorizontalString ยถ added in v0.12.0

func (p TreePrinter) WithHorizontalString(s string) *TreePrinter

WithHorizontalString returns a new list with a specific HorizontalString.

func (TreePrinter) WithIndent ยถ added in v0.12.0

func (p TreePrinter) WithIndent(indent int) *TreePrinter

WithIndent returns a new list with a specific amount of spacing between the levels. Indent must be at least 1.

func (TreePrinter) WithRoot ยถ added in v0.12.0

func (p TreePrinter) WithRoot(root TreeNode) *TreePrinter

WithRoot returns a new list with a specific Root.

func (TreePrinter) WithTextStyle ยถ added in v0.12.0

func (p TreePrinter) WithTextStyle(style *Style) *TreePrinter

WithTextStyle returns a new list with a specific text style.

func (TreePrinter) WithTopRightCornerString ยถ added in v0.12.0

func (p TreePrinter) WithTopRightCornerString(s string) *TreePrinter

WithTopRightCornerString returns a new list with a specific TopRightCornerString.

func (TreePrinter) WithTopRightDownStringOngoing ยถ added in v0.12.0

func (p TreePrinter) WithTopRightDownStringOngoing(s string) *TreePrinter

WithTopRightDownStringOngoing returns a new list with a specific TopRightDownString.

func (TreePrinter) WithTreeStyle ยถ added in v0.12.0

func (p TreePrinter) WithTreeStyle(style *Style) *TreePrinter

WithTreeStyle returns a new list with a specific tree style.

func (TreePrinter) WithVerticalString ยถ added in v0.12.0

func (p TreePrinter) WithVerticalString(s string) *TreePrinter

WithVerticalString returns a new list with a specific VerticalString.

func (TreePrinter) WithWriter ยถ added in v0.12.40

func (p TreePrinter) WithWriter(writer io.Writer) *TreePrinter

WithWriter sets the Writer.

Jump to

Keyboard shortcuts

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