Skip to content

ANSI control characters not treated as zero width #24

@stuhood

Description

@stuhood

Hey folks!

According to the README.md, control characters should be treated as zero width, but it seems like ANSI color sequences are not currently. Code like the following (using strip_ansi_escapes) will fail for strings containing ANSI control characters:

fn assert_width(s: String) {
    let stripped_width = std::str::from_utf8(&strip_ansi_escapes::strip(s.as_bytes()).unwrap())
        .unwrap()
        .width() as u16;
    let unicode_width = s.width() as u16;
    assert_eq!(
        stripped_width, unicode_width,
        "Mismatched width ({} vs {}) for `{:?}`",
        stripped_width, unicode_width, s
    );
}

...such as:

"\u{1b}[1m========\u{1b}[0m"

Is this expected?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions