module RatatuiRuby::Text

Namespace for rich text components (Span, Line) and text utilities. Distinct from canvas shapes and other Line usages.

Text Measurement

The Text module provides a utility method for calculating the display width of strings in terminal cells. This accounts for unicode complexity:

This is essential for layout calculations in TUI applications, where you need to know how much space a string will occupy on the screen, not just its byte or character length.

Use Cases

Examples

# Simple ASCII text
RatatuiRuby::Text.width("Hello")        # => 5

# With emoji
RatatuiRuby::Text.width("Hello 👍")     # => 8 (5 + space + 2-width emoji)

# With CJK characters
RatatuiRuby::Text.width("你好")         # => 4 (each CJK char is 2 cells)

# Mixed content
RatatuiRuby::Text.width("Hi 你好 👍")   # => 11 (2 + space + 4 + space + 2)