-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In Windows Terminal, prompt.spacing
can "eat" lines that contain Unicode surrogate pairs.
#574
Comments
Have you tried it in CMD without Clink? If it's indeed that the prompt prints before output is complete, then I would expect it to behave identically in plain CMD. Clink shows a prompt when CMD tries to show a prompt -- Clink literally intercepts the attempt to print the prompt. UPDATE: It was not printing the prompt before output was complete. I updated the title accordingly. Do you have aliases for dirx and eza? If so, what are the aliases defined as? Or batch scripts for them? If so what are the contents of the batch scripts? The behavior in the screen shots would be expected if dirx or eza were started but CMD regained control before the spawned processes completed. There are a variety of ways that can be done, the easiest being use of (This is likely external to both Clink and flexprompt.) What terminal program are you using? (And what version of it?) |
Also, can you narrow down specific repro steps? Maybe --git or --icons or some other flag(s) might be relevant. |
@bw1faeh0 Good news -- I can reproduce the behavior. But only in Windows Terminal (all versions; 1.19.10573.0, Preview 1.20.10572.0, and Canary 1.20.240124001-llm). Not in legacy conhost, not in ConEmu, not in ConsoleZ. And thank you for including the full sample output, so that I could construct a directory containing files that produce the exact same output; which I then redirected and embedded in a separate C++ program. The following C++ program reproduces the problem, without the need for any special directories or files being present. Interestingly, adding other lines makes it not reproduce the problem. So there's something about these lines. I haven't determined yet whether this is an issue in Windows Terminal, or an issue in Clink, or an issue in clink-flex-prompt. I'm working on narrowing that down further. #include <stdio.h>
#include <windows.h>
static const WCHAR* const c_strings[]
{
L"-a--- 17k 13 Mar 14:38 \U000f15c0 DevCE_Conn_Configuration.xml\r\n",
L"-a--- 11k 13 Mar 14:44 \U000f15c0 DevCE_Conn_Configuration_fm5.xml\r\n",
L"-a--- 10k 13 Mar 14:43 \U000f15c0 DevCE_Conn_Configuration_fm5_future.xml\r\n",
L"-a--- 17k 13 Mar 14:39 \U000f15c0 DevCE_Conn_Engineering.xml\r\n",
L"-a--- 11k 13 Mar 14:44 \U000f15c0 DevCE_Conn_Engineering_fm5.xml\r\n",
};
int _cdecl main(int argc, char const** argv)
{
argc--, argv++;
HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD written;
for (const WCHAR* s : c_strings)
{
WriteConsoleW(h, s, DWORD(wcslen(s)), &written, nullptr);
}
return 0;
} |
I tracked it down. It's due to a change in behavior in Windows Terminal: The problem occurs when The problem will only appear in directories where the final line(s) of output from a program (dirx, eza, or any other program) contains one or more surrogate pairs. Some icons require a surrogate pair, and some icons don't. The icon for .xml files uses a surrogate pair. The icon for .cpp files does not use a surrogate pair. And so on. This is the function that handles clink/clink/app/src/host/host.cpp Lines 332 to 357 in ec90abb
To get the output line from the terminal's screen buffer, the
The Windows Terminal implementation for that console API behaves strangely when a line contains a surrogate pair. It returns "success", with In contrast, the legacy conhost implementation for that console API returns "success", with
The root cause is a difference in behavior that was introduced in Windows Terminal. The API no longer behaves the same as it did before Windows Terminal, so I would say it's a regression. To me, it seems worth fixing in Windows Terminal. I'll open an issue in the WT repo in a few days, with a tiny program that reproduces the problem without Clink or eza or dirx being involved. I'm marking this "external" because the root cause is in Windows Terminal. But, I'll also hack Clink to work around the problem, by considering any line of 0 length to be a line that has content which Windows Terminal fails to return, so that Clink stops walking upwards past a seemingly blank line. Anything else in Clink or scripts that tries to read output from the terminal will still fail to read any output from those lines, because Windows Terminal returns a 0 length string (e.g. the |
prompt.spacing
can "eat" lines that contain Unicode surrogate pairs.
@bw1faeh0 in the meantime, until the workaround is published, you can run |
See issue #574. An API in Windows Terminal behaves differently than in legacy conhost. 1. It fails, but should succeed. 2. It fails, but returns that it succeeded. 3. It claims to have succeeded, but returns that the length was 0. This detects the failure based on the 0 length and treats it as having failed, despite the API claiming to have succeeded. So, at least Clink and Lua scripts can be aware that it failed, instead of thinking it succeeded. Since Clink's Lua API strips trailing spaces, callers have no way to deduce failure, since the returned string is empty, which is consistent with a line that was full of spaces.
Hi,
I'm not sure if it is a clink or a flex-prompt issue, but take a look at this:
Or at this:
In contrast:
This does not happen in all directories. In D:\Temp\ for instance (where I can find a lot more files (34 files, 39 dirs)) I can not reproduce this issue.
The text was updated successfully, but these errors were encountered: