Skip to content

Backspace character is ignored when calculating string widths #8277

Closed

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.

Activity

  1. added this to the fish-future milestone on Sep 17, 2021
  2. modified the milestones: fish-future, fish 3.4.0 on Sep 23, 2021
  3. added a commit that references this issue on Dec 12, 2021
  4. locked as resolved and limited conversation to collaborators on Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions