MCPcopy
hub / github.com/pterm/pterm

github.com/pterm/pterm @v0.12.83 sqlite

repository ↗ · DeepWiki ↗ · release v0.12.83 ↗
1,225 symbols 4,754 edges 201 files 618 documented · 50%
README

💻 PTerm | Pretty Terminal Printer

A modern Go framework to make beautiful CLIs

Latest Release

Stars

Forks

License: MIT

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

⭐ 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 28774 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)

Feature Feature Feature Feature Feature
Area

(Examples) |Barchart

(Examples) |Basictext

(Examples) |Bigtext

(Examples) |Box

(Examples) | | Bulletlist

(Examples) |Center

(Examples) |Coloring

(Examples) |Header

(Examples) |Heatmap

(Examples) | | Interactive confirm

(Examples) |Interactive continue

(Examples) |Interactive multiselect

(Examples) |Interactive select

(Examples) |Interactive textinput

(Examples) | | Logger

(Examples) |Multiple-live-printers

(Examples) |Panel

(Examples) |Paragraph

(Examples) |Prefix

(Examples) | | Progressbar

(Examples) |Section

(Examples) |Slog

(Examples) |Spinner

(Examples) |Style

(Examples) | | Table

(Examples) |Test.sh

(Examples) |Theme

(Examples) |Tree

(Examples) | |


🦸‍♂️ Sponsors


🧪 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"
    "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()
}

area/center

Animation

SHOW SOURCE

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 time-consuming task.
        time.Sleep(time.Second)
    }

    // Stop the area after all updates are done.
    area.Stop()
}

area/default

Animation

SHOW SOURCE

package main

import (
    "time"

    "github.com/pterm/pterm"
)

func main() {
    // Start a new default area and get a reference to it.
    // The second return value is an error which is ignored here.
    area, _ := pterm.DefaultArea.Start()

    // Loop 5 times
    for i := 0; i < 5; i++ {
        // Update the content of the area dynamically.
        // Here we're just displaying the current count.
        area.Update(pterm.Sprintf("Current count: %d\nAreas can update their content dynamically!", i))

        // Pause for a second before the next update.
        time.Sleep(time.Second)
    }

    // Stop the area after all updates are done.
    // This will clean up and free resources used by the area.
    area.Stop()
}

area/dynamic-chart

Animation

SHOW SOURCE

package main

import (
    "time"

    "github.com/pterm/pterm"
)

func main() {
    // Start a new fullscreen centered area.
    // This area will be used to display the bar chart.
    area, _ := pterm.DefaultArea.WithFullscreen().WithCenter().Start()
    // Ensure the area stops updating when we're done.
    defer area.Stop()

    // Loop to update the bar chart 10 times.
    for i := 0; i < 10; i++ {
        // Create a new bar chart with dynamic bars.
        // The bars will change based on the current iteration.
        barchart := pterm.DefaultBarChart.WithBars(dynamicBars(i))
        // Render the bar chart to a string.
        // This string will be used to update the area.
        content, _ := barchart.Srender()
        // Update the area with the new bar chart.
        area.Update(content)
        // Wait for half a second before the next update.
        time.Sleep(500 * time.Millisecond)
    }
}

// dynamicBars generates a set of bars for the bar chart.
// The bars will change based on the current iteration.
func dynamicBars(i int) pterm.Bars {
    return pterm.Bars{
        {Label: "A", Value: 10},     // A static bar.
        {Label: "B", Value: 20 * i}, // A bar that grows with each iteration.
        {Label: "C", Value: 30},     // Another static bar.
        {Label: "D", Value: 40 + i}, // A bar that grows slowly with each iteration.
    }
}

area/fullscreen

Animation

SHOW SOURCE

package main

import (
    "time"

    "github.com/pterm/pterm"
)

func main() {
    // Start a new fullscreen area. This will return an area instance and an error.
    // The underscore (_) is used to ignore the error.
    area, _ := pterm.DefaultArea.WithFullscreen().Start()

    // Loop 5 times to update the area content.
    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 before the next update.
        time.Sleep(time.Second)
    }

    // Stop the area after all updates are done.
    area.Stop()
}

area/fullscreen-center

Animation

SHOW SOURCE

```go package main

import ( "time"

"github.com/pterm/pterm"

)

func main() { // Initialize a new PTerm area with fullscreen and center options // The Start() function returns the created area and an error (ignored here) area, _ := pterm.DefaultArea.WithFullscreen().WithCenter().Start()

// Loop 5 times to demonstrate dynamic content update
for i := 0; i < 5; i++ {
    // Update the content of the area with the curr

Extension points exported contracts — how you extend this code

RenderPrinter (Interface)
RenderPrinter is used to display renderable content. Example for renderable content is a Table. [7 implementers]
interface_renderable_printer.go
TextPrinter (Interface)
TextPrinter contains methods to print formatted text to the console or return it as a string. [9 implementers]
interface_text_printer.go
LivePrinter (Interface)
LivePrinter is a printer which can update it's output live. [4 implementers]
interface_live_printer.go
ExitFuncType (FuncType)
ExitFuncType is the type of function used to exit the program.
internal/exit.go

Core symbols most depended-on inside this repo

Sprint
called by 263
interface_text_printer.go
NewStyle
called by 154
color.go
Println
called by 107
interface_text_printer.go
Render
called by 61
interface_renderable_printer.go
Sprintf
called by 58
interface_text_printer.go
Start
called by 55
area_printer.go
Sprint
called by 52
print.go
Sprintf
called by 50
print.go

Shape

Function 669
Method 491
Struct 51
TypeAlias 10
Interface 3
FuncType 1

Languages

Go100%

Modules by API surface

heatmap_printer.go37 symbols
box_printer_test.go35 symbols
logger.go34 symbols
box_printer.go34 symbols
progressbar_printer.go32 symbols
progressbar_printer_test.go30 symbols
color.go30 symbols
prefix_printer_test.go29 symbols
rgb.go28 symbols
theme.go27 symbols
theme_test.go26 symbols
spinner_printer_test.go25 symbols

Dependencies from manifests, versioned

atomicgo.dev/assertv0.0.2 · 1×
atomicgo.dev/cursorv0.2.0 · 1×
atomicgo.dev/schedulev0.1.0 · 1×
github.com/MarvinJWendt/testzav0.5.2 · 1×
github.com/clipperhouse/uax29/v2v2.7.0 · 1×
github.com/containerd/consolev1.0.5 · 1×
github.com/davecgh/go-spewv1.1.1 · 1×
github.com/gookit/colorv1.6.0 · 1×
github.com/klauspost/cpuid/v2v2.2.3 · 1×
github.com/lithammer/fuzzysearchv1.1.8 · 1×
github.com/mattn/go-runewidthv0.0.20 · 1×

For agents

$ claude mcp add pterm \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact