Configs2026年7月17日·1 分钟阅读

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.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
PTerm
直接安装命令
npx -y tokrepo@latest install d63ff55c-8177-11f1-9bc6-00163e2b0d79 --target codex

先 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

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产