Psreadline: In 6.2.3 and above PSReadLine causes 'backspace' in posh-git + Windows Terminal

Created on 29 Sep 2019  Â·  12Comments  Â·  Source: PowerShell/PSReadLine

Environment data

  • posh-git version/path: 1.0.0 beta3 ~\Documents\PowerShell\Modules\posh-git\1.0.0
  • PowerShell version: 6.2.3
  • git version 2.23.0.windows.1
  • OS: Microsoft Windows NT 10.0.18362.0

Steps to reproduce or exception report

Please see this posh-git Issue for more details: https://github.com/dahlbyk/posh-git/issues/704

@rkeithhill

Resolution-External Windows-Terminal

Most helpful comment

Specifically microsoft/terminal#2928 will _enforce_ all ambiguous width chars being one cell wide -- this will fix this bug.

All 12 comments

Quoted from https://github.com/dahlbyk/posh-git/issues/704#issuecomment-536654188

I also noticed this, and posted about it in the Windows Terminal repository. Someone suggested it was caused by the ≡ character; at least where Cascadia Code is concerned, this is currently an "ambiguous-width" character, so the terminal's understanding of the cursor position becomes inconsistent. I think the older console that you get by launching pwsh.exe just forces everything to one character cell.

Then that makes this related to #1054. Character width is determined by the font … I don't know if PSReadLine has anyway it can determine this when its behind a terminal. Can the current character position be polled through a VT sequence? Spit out a character, poll the new cursor position, etc...?

Might be different. The linked issue description mentioned that it happens on Windows Terminal only:

EDIT: This does NOT happen in Hosts other than Windows Terminal. E.g. in the VSCode terminal, cmd.exe, and ConEmu it works fine.

Might be different. The linked issue description mentioned that it happens on Windows Terminal only:

EDIT: This does NOT happen in Hosts other than Windows Terminal. E.g. in the VSCode terminal, cmd.exe, and ConEmu it works fine.

Correct. I was unable to reproduce in any host other than Windows Terminal.

Additionally, while the character width issue may be the culprit, my instincts say this is in PSReadline as @rkeithhill and I tested a PS 6.2.3 session in Windows Terminal WITHOUT PSReadLine loaded...and the font appeared correctly without the backspace issue.

If the issue is in fact that sometimes (some fonts) the ≡ is a different width, then this will affect PSReadLine's ability to estimate where the cursor is. PSReadLine attempts to modify the prompt as you type, so it has to move and move again the cursor while you are typing.

Difference in hosts could simply be the default font, or not demonstrating the issue using the same path and same Posh Git connections.

Also, as you type, PSReadLine may modify the color of previous parts of the command line, more reason that the cursor has to be moved, and why PSReadLine needs an accurate estimate of the cursor position.

See https://github.com/microsoft/terminal/pull/2928 where they are assuming ambiguous width characters are 1 character.

Note that PSReadLine hard codes the characters that are double width here.

Should emoji be / are they part of that list @lzybkr ?

Note in my link above the commented out code for surrogate pairs. Emoji have the same issue I think.

Specifically microsoft/terminal#2928 will _enforce_ all ambiguous width chars being one cell wide -- this will fix this bug.

Specifically microsoft/terminal#2928 will _enforce_ all ambiguous width chars being one cell wide -- this will fix this bug.

Woot. Thanks.

https://github.com/microsoft/terminal/pull/2928 was merged, so closing this issue.

Was this page helpful?
0 / 5 - 0 ratings