ansi-aware-terminal-text-utils

Measure, truncate, pad, and strip ANSI codes in terminal text.

Updated May 15, 2026
One-click install
npx skills add https://github.com/ruskibeats/t1d --skill ansi-aware-terminal-text-utils
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ansi-aware-terminal-text-utils
Source: https://github.com/ruskibeats/t1d/tree/main/.pi/skills-archive/ansi-aware-terminal-text-utils
Command: npx skills add https://github.com/ruskibeats/t1d --skill ansi-aware-terminal-text-utils

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

This Skill addresses the challenge of formatting terminal UI tables correctly, especially when dealing with ANSI escape codes and wide characters.

Core Features & Use Cases

  • ANSI Code Handling: Correctly measures and handles strings with ANSI escape codes for consistent visual display.
  • Wide Character Support: Counts CJK ideographs and emoji as two visual columns for accurate table layout.
  • Utility Functions: Provides functions like visualWidth, truncate, pad, padOnly, and stripAnsi for flexible text manipulation.
  • Use Case: When building a CLI tool or terminal-based application that requires precise text formatting, such as a table renderer or board view.

Quick Start

Use the ansi-aware-terminal-text-utils skill to calculate the visual width of a string containing ANSI codes: visualWidth("Hello\x1b[31mWorld\x1b[0m").

Frequently Asked Questions about ansi-aware-terminal-text-utils

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I calculate the visual width of a string with ANSI escape codes for terminal table formatting?

To calculate the visual width of a string with ANSI escape codes, use a utility function like `visualWidth` that strips hidden control sequences and counts wide characters, ensuring accurate terminal table column alignment.

Why does my CLI tool display misaligned table columns when rendering CJK ideographs and emoji?

Table columns become misaligned when CJK ideographs and emoji are counted as single columns. Using an ANSI-aware text utility resolves this by correctly counting wide characters as two visual columns for accurate layout.

What is the best way to truncate and pad text containing terminal color codes without breaking the layout?

The best way to truncate and pad text with terminal color codes is using dedicated functions like `truncate` and `pad` that recognize ANSI escape sequences, ensuring visual spacing remains consistent in CLI applications.

Can I format terminal UI tables with ANSI-aware text utilities without adding external dependencies?

Yes, you can format terminal UI tables with ANSI-aware text utilities without adding external dependencies. These functions operate standalone, requiring no external libraries to handle string measurement, padding, or ANSI code stripping.

How do I strip ANSI escape codes from a string before measuring its length in a CLI application?

To strip ANSI escape codes from a string before measuring its length in a CLI application, use the `stripAnsi` function. This removes terminal control sequences, allowing accurate string measurement and truncation for text formatting.