Pterm
β¨ PTerm is a modern Go module to easily beautify console output. Featuring charts, progressbars, tables, trees, text input, select menus and much more π It's completely configurable and 100% cross-platform compatible.
Install / Use
/learn @pterm/PtermREADME
<p align="center"> <strong><a href="https://pterm.sh">PTerm.sh</a></strong> | <strong><a href="#-installation">Installation</a></strong> | <strong><a href="https://docs.pterm.sh/getting-started">Getting Started</a></strong> | <strong><a href="https://docs.pterm.sh/">Documentation</a></strong> | <strong><a href="https://github.com/pterm/pterm/tree/master/_examples">Examples</a></strong> | <strong><a href="https://github.com/pterm/pterm/discussions?discussions_q=category%3AQ%26A">Q&A</a></strong> | <strong><a href="https://discord.gg/vE2dNkfAmF">Discord</a></strong> </p>
π¦ 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 <!-- unittestcount2:start -->28774<!-- unittestcount2:end --> 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)
<div align="center"> <!-- printers:start -->| Feature | Feature | Feature | Feature | Feature | | :-------: | :-------: | :-------: | :-------: | :-------: | | Area <br/> (Examples) |Barchart <br/> (Examples) |Basictext <br/> (Examples) |Bigtext <br/> (Examples) |Box <br/> (Examples) | | Bulletlist <br/> (Examples) |Center <br/> (Examples) |Coloring <br/> (Examples) |Header <br/> (Examples) |Heatmap <br/> (Examples) | | Interactive confirm <br/> (Examples) |Interactive continue <br/> (Examples) |Interactive multiselect <br/> (Examples) |Interactive select <br/> (Examples) |Interactive textinput <br/> (Examples) | | Logger <br/> (Examples) |Multiple-live-printers <br/> (Examples) |Panel <br/> (Examples) |Paragraph <br/> (Examples) |Prefix <br/> (Examples) | | Progressbar <br/> (Examples) |Section <br/> (Examples) |Slog <br/> (Examples) |Spinner <br/> (Examples) |Style <br/> (Examples) | | Table <br/> (Examples) |Test.sh <br/> (Examples) |Theme <br/> (Examples) |Tree <br/> (Examples) | |
<!-- printers:end --> </div><div align="center">
π¦ΈββοΈ Sponsors
<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg" /></div>
π§ͺ Examples
<p align="center"> <table> <tbody> <td align="center"> <img width="2000" height="0"><br> <a href="https://github.com/pterm/pterm/tree/master/_examples">βΌοΈ You can find all the examples, in a much better structure and their source code, in "_examples" βΌοΈ</a><br> <sub>Click on the link above to show the examples folder.</sub> <img width="2000" height="0"> </td> </tbody> </table> </p> <!-- examples:start -->area/demo
package main
import (
"time"
"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
)
func main() {
// Print an informational message using PTerm's Info printer.
// This message will stay in place while the area updates.
pterm.Info.Println("The previous text will stay in place, while the area updates.")
// Print two new lines as spacer.
pterm.Print("\n\n")
// Start the Area printer from PTerm's DefaultArea, with the Center option.
// The Area printer allows us to update a specific area of the console output.
// The returned 'area' object is used to control the area updates.
area, _ := pterm.DefaultArea.WithCenter().Start()
// Loop 10 times to update the area with the current time.
for i := 0; i < 10; i++ {
// Get the current time, format it as "15:04:05" (hour:minute:second), and convert it to a string.
// Then, create a BigText from the time string using PTerm's DefaultBigText and putils NewLettersFromString.
// The Srender() function is used to save the BigText as a string.
str, _ := pterm.DefaultBigText.WithLetters(putils.LettersFromString(time.Now().Format("15:04:05"))).Srender()
// Update the Area contents with the current time string.
area.Update(str)
// Sleep for a second before the next update.
time.Sleep(time.Second)
}
// Stop the Area printer after all updates are done.
area.Stop()
}
</details>
area/center
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// Start a new default area in the center of the terminal.
// The Start() function returns the created area and an error.
area, _ := pterm.DefaultArea.WithCenter().Start()
// Loop 5 times to simulate a dynamic update.
for i := 0; i < 5; i++ {
// Update the content of the area with the current count.
// The Sprintf function is used to format the string.
area.Update(pterm.Sprintf("Current count: %d\nAreas can update their content dynamically!", i))
// Pause for a second to simulate a t
