π» PTerm | Pretty Terminal Printer
A modern Go framework to make beautiful CLIs
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
β Main Features
| Feature |
Description |
| πͺ Easy to use |
PTerm emphasizes ease of use, with examples and consistent component design. |
| π€ΉββοΈ Cross-Platform |
PTerm works on various OS and terminals, including Windows CMD, macOS iTerm2, and in CI systems like GitHub Actions. |
| π§ͺ Well tested |
A high test coverage and 1538 automated tests ensure PTerm's reliability. |
| β¨ Consistent Colors |
PTerm uses the ANSI color scheme for uniformity and supports TrueColor for advanced terminals. |
| π Component system |
PTerm's flexible Printers can be used individually or combined to generate beautiful console output. |
| π Configurable |
PTerm is ready to use without configuration but allows easy customization for unique terminal output. |
| β Documentation |
Access comprehensive docs on pkg.go.dev and view practical examples in the examples section. |
Printers (Components)
π¦ΈββοΈ Sponsors
π§ͺ Examples
area/demo

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
)
func main() {
// A live clock: only the area redraws, anything printed before it stays put.
pterm.Info.Println("The previous text will stay in place, while the area updates.")
pterm.Print("\n\n")
area, _ := pterm.DefaultArea.WithCenter().Start()
for range 10 {
// Render the current time as big letters into a string, then swap it
// into the area. Srender returns the output instead of printing it.
str, _ := pterm.DefaultBigText.WithLetters(putils.LettersFromString(time.Now().Format("15:04:05"))).Srender()
area.Update(str)
time.Sleep(time.Second)
}
area.Stop()
}
area/center

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// WithCenter horizontally centers the area's content in the terminal.
area, _ := pterm.DefaultArea.WithCenter().Start()
// Each Update redraws the area in place instead of appending new lines.
for i := range 5 {
area.Update(pterm.Sprintfln("Current count: %d\nAreas can update their content dynamically!", i))
time.Sleep(time.Second)
}
area.Stop()
}
area/default

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
area, _ := pterm.DefaultArea.Start()
// Each Update redraws the area in place instead of appending new lines.
for i := range 5 {
area.Update(pterm.Sprintfln("Current count: %d\nAreas can update their content dynamically!", i))
time.Sleep(time.Second)
}
area.Stop()
}
area/dynamic-chart

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// A live bar chart: render the chart to a string each tick and let the
// area redraw it in place. Fullscreen gives the area the whole terminal.
area, _ := pterm.DefaultArea.WithFullscreen().WithCenter().Start()
defer area.Stop()
for i := range 10 {
barchart := pterm.DefaultBarChart.WithBars(dynamicBars(i))
content, _ := barchart.Srender()
area.Update(content)
time.Sleep(500 * time.Millisecond)
}
}
// dynamicBars returns the chart data for the given tick. B and D grow over
// time, A and C stay constant.
func dynamicBars(i int) pterm.Bars {
return pterm.Bars{
{Label: "A", Value: 10},
{Label: "B", Value: 20 * i},
{Label: "C", Value: 30},
{Label: "D", Value: 40 + i},
}
}
area/fullscreen

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// Fullscreen clears the terminal and gives the area the whole screen.
area, _ := pterm.DefaultArea.WithFullscreen().Start()
// Each Update redraws the area in place instead of appending new lines.
for i := range 5 {
area.Update(pterm.Sprintf("Current count: %d\nAreas can update their content dynamically!", i))
time.Sleep(time.Second)
}
// Stop clears the area and restores the terminal.
area.Stop()
}
area/fullscreen-center

SHOW SOURCE
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// Fullscreen takes over the whole terminal; WithCenter centers the
// content within it.
area, _ := pterm.DefaultArea.WithFullscreen().WithCenter().Start()
// Each Update redraws the area in place instead of appending new lines.
for i := range 5 {
area.Update(pterm.Sprintf("Current count: %d\nAreas can update their content dynamically!", i))
time.Sleep(time.Second)
}
// Stop clears the area and restores the terminal.
area.Stop()
}
barchart/demo

SHOW SOURCE
package main
import (
"github.com/pterm/pterm"
)
func main() {
// One deliberately longer label shows how the horizontal chart
// aligns all bars to the widest label.
bars := []pterm.Bar{
{Label: "Go", Value: 5},
{Label: "Rust", Value: 3},
{Label: "TypeScript", Value: 7},
}
pterm.Info.Println("Chart example with positive values only (bars use the full chart area)")
pterm.DefaultBarChart.WithBars(bars).Render()
// The same data rendered horizontally.
pterm.DefaultBarChart.WithHorizontal().WithBars(bars).Render()
}
barchart/custom-height

SHOW SOURCE
package main
import "github.com/pterm/pterm"
func main() {
bars := []pterm.Bar{
{Label: "A", Value: 10},
{Label: "B", Value: 20},
{Label: "C", Value: 30},
{Label: "D", Value: 40},
{Label: "E", Value: 50},
{Label: "F", Value: 40},
{Label: "G", Value: 30},
{Label: "H", Value: 20},
{Label: "I", Value: 10},
}
// WithHeight caps the chart at 5 rows; the bar values are scaled to fit.
pterm.DefaultBarChart.WithBars(bars).WithHeight(5).Render()
}