Wrapped text style preservation

From ychampion/cskill-agents · View interactive version

Wrapped text style preservation is an AI agent skill from the GitHub repository ychampion/cskill-agents. Track per-character segments so wrapped or truncated text keeps its original colors and emphasis.

How to use this skill

Skill file

SKILL: Wrapped Text Style Preservation

Domain: terminal-ui

Trigger: When you must wrap or truncate a styled text run but cannot afford to lose per-segment colors, links, or emphasis, especially inside terminals that split lines at wrap boundaries.

Source Pattern: Distilled from reviewed terminal rendering, layout, animation, and accessibility implementations.

Core Method

Before wrapping, convert the styled segments into a char to segment map so each output character still references its originating segment. After wrapping with wrap text, walk the wrapped lines and reapply the original segment colors by mapping the wrapped character index back into the segment list; skip whitespace that was trimmed when wrap is in trim mode so you don’t leak palette data.

Key Rules

Example Application

Render a paragraph where each sentence is a different color link: wrap the paragraph via the existing renderer, then use the char-to-segment map to repaint each wrapped character, ensuring the link color and underline persist even though the text spans multiple lines.

Anti-Patterns (What NOT to do)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.