chrisant996 / clink

Bash's powerful command line editing in cmd.exe
https://chrisant996.github.io/clink/
GNU General Public License v3.0
3.44k stars 135 forks source link

The last character of a right-aligned prompt gets erased #618

Closed stanio closed 3 months ago

stanio commented 3 months ago

Using:

Unsure if it is strictly a Clink problem. Using oh-my-posh and a right-aligned block in the prompt, the character in the last column gets erased:

wt-clink

For comparison, the same prompt in Bash appears fine:

wt-bash

OMP theme fragment ```jsonc "blocks": [ { "alignment": "right", "segments": [ { "foreground": "green", "style": "plain", "template": "{{ if .SSHSession }}\uf817 {{ end }}{{ .UserName }}@{{ .HostName }}", "type": "session" }, { "foreground": "red", "properties": { "root_icon": "root" }, "style": "plain", "template": " as \uf0e7", "type": "root" } ], "type": "prompt" }, ... ```

As a workaround, I'm using an extra space character at the end of this right-aligned block.

chrisant996 commented 3 months ago

@stanio Can you share the OMP theme? Without that, I can't attempt to reproduce or analyze what's happening.

Or, if you prefer not to share the OMP theme, then you could do these steps instead:

  1. Run clink set debug.log_terminal true to turn on logging of everything that's printed by Clink.
  2. Confirm that after step 1 the prompt gets displayed and has the problem.
  3. Attach the clink.log file from your Clink profile directory into a reply here (the file's location can be found via clink info).
  4. Run clink set debug.log_terminal false to turn off logging again.
chrisant996 commented 3 months ago

@stanio Never mind -- I made a custom prompt that prints text all the way to the right edge, and it reproduces the issue.

Note that printing text all the way to the right edge means resizing the terminal window will behave strangely (it will try to wrap the line strangely upon resize). Since I avoid letting prompts do that, I didn't notice the issue.

chrisant996 commented 3 months ago

This seems to be an issue in how Windows Terminal and/or the Windows console subsystem implements the EraseInLine (EL) escape code ESC [ K.

Clink appends ESC [ K to the end of each line, to clear any leftover text on the line.

Mintty handles the ESC [ K correctly when the cursor is past the right edge of the screen.

It seems that if text is printed up to the right edge of the screen, then Windows Terminal doesn't recognize that the cursor is actually past the right edge, and the ESC [ K ends up also accidentally clearing the last character in the line.

The same issue seems to happen in the legacy conhost. So it seems like this is a very long-standing issue in the implementation of EraseInLine in the Windows console subsystem.

Since it's been around for a very long time, it isn't a recent regression. So, I'll make a change in Clink to work around this issue in the console subsystem.

stanio commented 3 months ago

The same issue seems to happen in the legacy conhost. So it seems like this is a very long-standing issue in the implementation of EraseInLine in the Windows console subsystem.

Sorry for the late reply. Thank you very much for looking into and providing a fix for it.