Prompt in cmd.exe when using clink is wrapped early #2235

Closed
opened 2026-01-30 22:50:16 +00:00 by claunia · 10 comments
Owner

Originally created by @g0blue on GitHub (Jun 25, 2019).

Environment

Windows build number: Microsoft Windows [Version 10.0.18362.175]
Windows Terminal version (if applicable): 0.2.1715.0

Clink version 0.4.9

Hack font

Steps to reproduce

Use clink with cmd.exe within Windows Terminal.

I have a custom lua script for clink that intends to mimic the prompt produced by "powerline" in bash. See https://powerline.readthedocs.io/en/latest/ for information on powerline.

I've attached all of my clink settings and scripts:
clink.zip

Note: This prompt uses characters not included in most fonts (including Consolas). You must use a powerline compatible font (like "Hack" linked above) for correct prompt display.

Expected behavior

I expect the terminal to look somewhat like this (running inside ConEmu):
image

Actual behavior

Instead I get this:
image

For some reason the size of the terminal as deduced by clink is incorrect and the prompt is wrapped prematurely.

To your credit, Windows Terminal does a better job of color reproduction than ConEmu.

Originally created by @g0blue on GitHub (Jun 25, 2019). <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment Windows build number: Microsoft Windows [Version 10.0.18362.175] Windows Terminal version (if applicable): 0.2.1715.0 Clink version [0.4.9](https://mridgers.github.io/clink/) [Hack font](https://sourcefoundry.org/hack/) # Steps to reproduce <!-- A description of how to trigger this bug. --> Use clink with cmd.exe within Windows Terminal. I have a custom lua script for clink that intends to mimic the prompt produced by "powerline" in bash. See https://powerline.readthedocs.io/en/latest/ for information on powerline. I've attached all of my clink settings and scripts: [clink.zip](https://github.com/microsoft/terminal/files/3326761/clink.zip) > **Note:** This prompt uses characters not included in most fonts (including Consolas). You must use a powerline compatible font (like "Hack" linked above) for correct prompt display. # Expected behavior I expect the terminal to look somewhat like this (running inside ConEmu): ![image](https://user-images.githubusercontent.com/8888327/60122879-07b9ea00-973b-11e9-9e35-aa95832436e2.png) # Actual behavior Instead I get this: ![image](https://user-images.githubusercontent.com/8888327/60122903-1a342380-973b-11e9-9c3c-b932d38f0c09.png) For some reason the size of the terminal as deduced by clink is incorrect and the prompt is wrapped prematurely. To your credit, Windows Terminal does a better job of color reproduction than ConEmu.
Author
Owner

@DHowett-MSFT commented on GitHub (Jun 27, 2019):

It would be really interesting to see what raw VT clink is emitting for the prompt. Would you be able to share that?

@DHowett-MSFT commented on GitHub (Jun 27, 2019): It would be really interesting to see what raw VT clink is emitting for the prompt. Would you be able to share that?
Author
Owner

@g0blue commented on GitHub (Jul 1, 2019):

I don't really know how to get that. If I change the LUA code to print out the generated string I give to clink as the prompt (and replace the escape code with $E) I get the following:

$E[0;38;5;15;48;5;31;1mdjohnsto$E[0;38;5;31;48;5;240m $E[0;38;5;87;48;5;240;1mC|$E[0;38;5;250;48;5;240m Users $E[0;37;1;48;5;240m$E[0;38;5;252;48;5;240;1m djohnsto $E[0;38;5;240m$E[0m

In a non-clink command terminal setting that as the prompt gives the correct result. So, it appears to be something internal to clink.

@g0blue commented on GitHub (Jul 1, 2019): I don't really know how to get that. If I change the LUA code to print out the generated string I give to clink as the prompt (and replace the escape code with $E) I get the following: `$E[0;38;5;15;48;5;31;1mdjohnsto$E[0;38;5;31;48;5;240m $E[0;38;5;87;48;5;240;1mC|$E[0;38;5;250;48;5;240m Users $E[0;37;1;48;5;240m$E[0;38;5;252;48;5;240;1m djohnsto $E[0;38;5;240m$E[0m ` In a non-clink command terminal setting that as the prompt gives the correct result. So, it appears to be something internal to clink.
Author
Owner

@g0blue commented on GitHub (Jul 1, 2019):

Hmm, if I print both the escaped and un-escaped strings from the LUA code, I see the problem.

image

It seems the escaped characters are being used to calculate the length of the line. The escaped and un-escaped prints wrap at the same location in the string. Not sure if this is a clink or terminal issue.

@g0blue commented on GitHub (Jul 1, 2019): Hmm, if I print both the escaped and un-escaped strings from the LUA code, I see the problem. ![image](https://user-images.githubusercontent.com/8888327/60469451-90d89180-9c11-11e9-8c42-f35d93318909.png) It seems the escaped characters are being used to calculate the length of the line. The escaped and un-escaped prints wrap at the same location in the string. Not sure if this is a clink or terminal issue.
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 1, 2019):

Oh no. Oh no no. This only happens if the console host isn't in ENABLE_VIRTUAL_TERMINAL_PROCESSING mode. This legitimately may be a clink bug. Another way it manifests is that you'll see cut off escape sequences around wrapping boundaries.

@DHowett-MSFT commented on GitHub (Jul 1, 2019): Oh no. Oh no no. This only happens if the console host isn't in `ENABLE_VIRTUAL_TERMINAL_PROCESSING` mode. This legitimately may be a clink bug. Another way it manifests is that you'll see cut off escape sequences around wrapping boundaries.
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 1, 2019):

(cmd turns on ENABLE_VIRTUAL_TERMINAL_PROCESSING on its output handle by default.)

@DHowett-MSFT commented on GitHub (Jul 1, 2019): (cmd turns on `ENABLE_VIRTUAL_TERMINAL_PROCESSING` on its output handle by default.)
Author
Owner

@g0blue commented on GitHub (Jul 1, 2019):

Another way it manifests is that you'll see cut off escape sequences around wrapping boundaries.

I've seen that, too. :(

@g0blue commented on GitHub (Jul 1, 2019): > Another way it manifests is that you'll see cut off escape sequences around wrapping boundaries. I've seen that, too. :(
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 1, 2019):

I don't have the necessary info to move this over onto clink, but I do think it belongs there. Printing out VT sequences without ENABLE_VIRTUAL_TERMINAL_PROCESSING turned on "works" in windows terminal, but it goes through the console host and gets horribly mangled before it does. Eventually, we'll change this so that the escape sequences are rendered inert and you actually see ESC[38;41;... just so we stop breaking the screen buffer...

Would you mind reflecting this issue over to clink's repo?

@DHowett-MSFT commented on GitHub (Jul 1, 2019): I don't have the necessary info to move this over onto clink, but I do think it belongs there. Printing out VT sequences without `ENABLE_VIRTUAL_TERMINAL_PROCESSING` turned on "works" in windows terminal, but it goes through the console host and gets horribly mangled before it does. Eventually, we'll change this so that the escape sequences are rendered _inert_ and you actually see `ESC[38;41;...` just so we stop breaking the screen buffer... Would you mind reflecting this issue over to clink's repo?
Author
Owner

@g0blue commented on GitHub (Jul 2, 2019):

Delving into the source it looks like there is only one place where SetConsoleMode is called to initialize stdout. Was able to add this flag and it fixed my issue. :) Thanks for the guidance.

image

Pull request submitted to clink, but it looks like there has been no activity for nearly a year.
https://github.com/mridgers/clink/pull/522

@g0blue commented on GitHub (Jul 2, 2019): Delving into the source it looks like there is only one place where SetConsoleMode is called to initialize stdout. Was able to add this flag and it fixed my issue. :) Thanks for the guidance. ![image](https://user-images.githubusercontent.com/8888327/60482493-a2885c00-9c46-11e9-9507-cf0780786203.png) Pull request submitted to clink, but it looks like there has been no activity for nearly a year. https://github.com/mridgers/clink/pull/522
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 2, 2019):

It's great that you got it fixed! Too bad clink has been radio-silent for a while. 😄

I first saw this issue with Maven, actually -- it would print out a progress bar and redraw it every 200ms or so. Over SSH (one of the first consumers of the pseudoconsole API, long before Windows Terminal existed) that progress bar would just dance all over the screen. Same issue: wrapping VT sequences because they hadn't turned on VT processing and through some fluke it was just working for them in conhost proper.

@DHowett-MSFT commented on GitHub (Jul 2, 2019): It's great that you got it fixed! Too bad clink has been radio-silent for a while. :smile: I first saw this issue with Maven, actually -- it would print out a progress bar and redraw it every 200ms or so. Over SSH (one of the first consumers of the pseudoconsole API, long before Windows Terminal existed) that progress bar would just _dance_ all over the screen. Same issue: wrapping VT sequences because they hadn't turned on VT processing and through some fluke it was just working for them in conhost proper.
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 14, 2019):

Just circling back: I learned that we support a global registry setting that enables VIRTUAL_TERMINAL_PROCESSING for all consoles by default. I'm almost certain that you have it turned on, and because it was on, clink didn't need to enable VT processing per session.

We introduced a regression in 19H1 that made conhost ignore that flag only for pseudoconsole hosts (like ssh, windows terminal, etc.), and suddenly applications that were relying on it being turned on started to act weird.

Thanks for the original report!

@DHowett-MSFT commented on GitHub (Jul 14, 2019): Just circling back: I learned that we support a global registry setting that enables `VIRTUAL_TERMINAL_PROCESSING` for all consoles by default. I'm almost certain that you have it turned on, and because it was on, clink _didn't need to enable VT processing per session._ We introduced a regression in 19H1 that made conhost ignore that flag _only for pseudoconsole hosts_ (like ssh, windows terminal, etc.), and suddenly applications that were relying on it being turned on started to act weird. Thanks for the original report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2235