Skip to content

Backspace character is ignored when calculating string widths #8277

@lilyball

Description

@lilyball

Fish treats BS (\b or 0x08 or U+8) as having zero width, even though it should reduce the width by 1 (as long as it's non-zero). This affects both prompt calculations and string length -V.

> string length -V a\bb
2
> function fish_prompt; printf "x\b> "; end
>  |

(the | represents the cursor)

Notice how the prompt renders as though it had two spaces (>  ) when it should have just had one (> ).

I believe BS should just be treated as a width of -1, I don't think there's any context to have here (experimentally, printing a two-column character such as an emoji followed by a backspace results in the cursor advancing one column even if the terminal skips rendering the emoji, so the backspace is indeed treated as "go backwards by one column" and not "go backwards by whatever the width of the preceding character is").

The only complication is I'm not aware of any other "width is -1" character, so we'd have to make sure code that calculates string widths is aware that a character width can be negative and ensures that the incremental string width never goes below zero.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions