Skip to content

[BUG] cell_len doesn't account for control characters #3950

@TomJGooding

Description

@TomJGooding

The overhaul of cell_len in Rich v14.3.0 doesn't seem to account for control characters.

from rich.cells import cell_len

for i in range(32):
    char = chr(i)
    char_len = cell_len(char)
    print(f"{repr(char):6}  {char_len}")

Previously it looks like there was special handling for these codepoints, but now it reports a cell width of 1.

CELL_WIDTHS = [
(0, 0, 0),
(1, 31, -1),
(127, 159, -1),

I'm surprised this change didn't break any tests, but I've not investigated Rich itself. I found this bug while investigating a problem in Textual:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions