Skip to content

Reset is added/removed in various cases #2

@ehuss

Description

@ehuss

After d228a29, there are a number of cases where the reset code is not passed through, or added. In some cases, it doesn't matter too much, others it causes incorrect rendering.

The first case (that doesn't matter too much, but broke Cargo's CI), is two resets in a row, which for some reason rustc likes to generate. These get squashed to one reset.

Input \u{1b}[0m\u{1b}[0m
Output \u{1b}[0m

The next is when a string starts with a color without a reset, a reset gets added:

Input \u{1b}[1mbold\u{1b}[31mred\u{1b}[0m
Output \u{1b}[0m\u{1b}[1mbold\u{1b}[0m\u{1b}[31mred\u{1b}[0m

This causes rendering changes:
image

Another case is when reset codes are in the middle of a series of codes:

Input \u{1b}[42m\u{1b}[0m\u{1b}[31mred?\u{1b}[0m
Output \u{1b}[0m\u{1b}[31m\u{1b}[42mred?\u{1b}[0m

image

This is somewhat due to how termcolor works. ANSI is stateful, but termcolor does not track the current state, and so each color change resets everything. But fwdansi is now partially stateful, and doesn't quite match what I would expect.

It would be ideal if fwdansi was completely idempotent when emitting ANSI. It would also be ideal if it handled colors on Win 7/8 in such a way to simulate ANSI stateful behavior. These two issues might be in conflict with one another, since termcolor works fundamentally differently from ANSI. ☹️

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions