Skip to content

Conversation

@jquast
Copy link
Owner

@jquast jquast commented Jan 15, 2026

Justify text with control-code and sequence-awareness, requires #166

Example,

    >>> wcwidth.center('hi', 6)
    '  hi  '
    >>> wcwidth.center('\\x1b[31mhi\\x1b[0m', 6)
    '  \\x1b[31mhi\\x1b[0m  '
    >>> wcwidth.center('\\U0001F468\\u200D\\U0001F469\\u200D\\U0001F467', 6)
    '  👨‍👩‍👧  '

jquast added 17 commits January 14, 2026 16:34
New width() function handles:
- Terminal escape sequences (SGR, OSC, CSI, etc.)
- Control codes with parse/strict/ignore modes
- Tab stops and cursor movement
- Always returns non-negative integer (never -1)

New exports: width
its a private function, anyway, still ok.

Below the turtles, 0/1 is very much the definition of Falsey and Truthy.
- Test lone ESC character handling in iter_sequences and width
- Test backspace at column 0 (no negative position)
- Test carriage return column reset
- Test tab with tabstop=0 in parse mode
- Test vertical control (LF) in parse mode
@jquast jquast changed the base branch from master to jq/new-width-function January 15, 2026 18:22
@jquast jquast changed the base branch from jq/new-width-function to jq/next-new-width January 15, 2026 18:23
@jquast jquast marked this pull request as ready for review January 15, 2026 18:24
@jquast jquast merged commit 6668301 into master Jan 17, 2026
36 checks passed
@jquast jquast deleted the jq/next-new-ljust-rjust-center2 branch January 17, 2026 18:51
jquast added a commit that referenced this pull request Jan 17, 2026
New ``wrap()`` function is an emoji, control and terminal sequence, wide, zero-width, and grapheme-aware version of textwrap.wrap(). This PR builds on #168 and #165 combined

    >>> # Wrapping CJK text (each character is 2 cells wide)
    >>> wrap('コンニチハ', 4)
    ['コン', 'ニチ', 'ハ']

    >>> # Text with ANSI color sequences
    >>> wrap('\x1b[31mhello world\x1b[0m', 5)
    ['\x1b[31mhello', 'world\x1b[0m']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants