Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 17, 2026·3 min de lectura

PTerm — Beautiful Console Output for Go Applications

A modern Go module for beautifying terminal output with progress bars, tables, trees, spinners, charts, and styled text, fully cross-platform and highly configurable.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
PTerm
Comando de instalación directa
npx -y tokrepo@latest install d63ff55c-8177-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

PTerm is a Go module that provides a rich set of terminal UI components for beautifying console output. It includes progress bars, spinners, tables, trees, panels, styled text, interactive prompts, and more. Every component is cross-platform compatible and works on Linux, macOS, and Windows without terminal-specific configuration.

What PTerm Does

  • Renders styled text with colors, backgrounds, bold, italic, and underline
  • Displays animated progress bars and spinners for long-running operations
  • Formats data as tables, trees, bullet lists, and panel layouts
  • Provides interactive prompts for text input, confirmations, and multi-select
  • Generates bar charts and box elements directly in the terminal

Architecture Overview

PTerm follows a printer-based architecture where each UI component is a printer struct with chainable configuration methods. Printers implement a common interface with Print, Println, and Sprint methods. The rendering layer detects terminal capabilities and falls back gracefully when colors or Unicode are not supported. All output goes through a central writer that can be redirected for testing.

Self-Hosting & Configuration

  • Import pterm and use default printers like pterm.Info, pterm.Success, pterm.Error
  • Chain With methods to customize printers: WithStyle(), WithPrefix(), WithWriter()
  • Use pterm.DisableColor() in CI environments or when piping output
  • Set pterm.SetDefaultOutput to redirect all output to a custom io.Writer
  • Enable or disable styling globally with pterm.EnableStyling() for test compatibility

Key Features

  • 20+ printer types: headers, panels, sections, trees, tables, progress bars, spinners, and more
  • Cross-platform: consistent output on Linux, macOS, Windows Terminal, and legacy cmd.exe
  • Interactive prompts: text input, confirmation, single-select, and multi-select with keyboard navigation
  • Testable: built-in test utilities and output capture for snapshot testing
  • Themeable: customize all colors and styles through the DefaultTheme or custom themes

Comparison with Similar Tools

  • Bubble Tea — full TUI framework with Elm architecture; PTerm focuses on output formatting rather than interactive full-screen apps
  • Charm/Lip Gloss — styling library for terminal output; PTerm includes more ready-made components like tables and progress bars
  • Color (fatih/color) — focused only on colored text output; PTerm extends this with structured components
  • Rich (Python) — similar feature set in Python; PTerm brings equivalent capabilities to Go

FAQ

Q: Does PTerm work on Windows? A: Yes. PTerm supports Windows Terminal, PowerShell, and the legacy cmd.exe console with automatic color fallback.

Q: Can I disable colors for CI/CD environments? A: Yes. Call pterm.DisableColor() or check pterm.RawOutput to skip styling when output is not a TTY.

Q: How do I write tests for PTerm output? A: Use pterm.SetDefaultOutput with a bytes.Buffer, render your output, then assert against the buffer contents. PTerm also provides snapshot testing helpers.

Q: Can I customize the spinner animation? A: Yes. PTerm includes multiple spinner styles and supports custom frame sequences via WithSequence().

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados