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
Consider implicitly activating VT / ANSI escape-sequence support for native programs in conhost.exe
console windows on Windows
#19101
Comments
As I remember the colored output was by default from win-10 or early. Perhaps you mean this setting? I didn't touch this checkbox. But I'm not sure if this is true with a clean install and not with an upgrade to a newer version. The only thing I don't like about the old console is the lack of support for hyperlinks and *.otf fonts. |
No, the registry setting that enables VT support applies only to the "modern" implementation of # Enclose in (...) as a workaround to enable VT support even without turning it on via the registry.
python -c 'print(''It ain\''t easy being \x1b[32mgreen\x1b[m.'')' (I realize that my calling |
No, I have not. There is full set (256) of |
I don't know what The Try after Long story short: It is unreasonable to expect all CLIs to explicitly opt-into VT support, and, clearly, Windows Terminal and Visual Studio Code already have made the sensible choice to enable it for all programs. |
conhost.exe
legacy console windows on Windowsconhost.exe
console windows on Windows
by it. resolved microsoft/vscode#173241 |
@237dmitry, good to know.
Try with |
@mozhuanzuojing, I'm glad to hear it, though I'm still baffled as to why that is required on your system. On my Windows 11 22H2 system with Visual Studio Code 1.75, I do not have to use this setting - VT support is always on in the integrated terminal (irrespective of what shell is running there). |
Is it an application specific setting ( as the settings for 'pwsh' above suggests) or a machine wide setting? Installing one program should not change the behaviour of others. A simple user option if they want the behaviour sounds like running PowerShell under Windows Terminal. |
I have no this parameter in
I'm not a developer and not from IT at all. I just see that everything is working. |
@rhubarb-geek-nz, the registry value is a persistent, user-specific setting that affects all (non-legacy) (I've removed my loose, contrast-with-Windows-Terminal uses of the term "legacy" from the initial post and previous comments, and now refer to it in the narrow senses of pre-VT-support older implementations of You were the one to introduce the |
Ok, I gave a few working examples, talked about the settings. I see you are looking for something else. |
@237dmitry, I conclude from your response that you are either unable or unwilling to engage with the specific arguments that have been made. The latter is what I am looking for. If there's something unclear about my arguments, ask for clarification. If you're unable or unwilling to personally verify repro steps, do not make claims such as "everything is working". |
@rhubarb-geek-nz, to be clear, what this proposal is saying is:
|
@mklement0 I'm pretty sure that |
@SteveL-MSFT, PowerShell already does override it, for PowerShell-native commands - and seemingly relies on VT support for its own colored output (right?) There's no reason not to enable it unconditionally, given that there are only downsides to having it disabled (garbled output) - am I missing something? In other words:
given that the exact same string is emitted in both cases. I see no benefit to printing |
@mklement0 perhaps you can open an issue in https://github.com/microsoft/terminal and see what arguments they would have to NOT have that registry setting enabled by default? It would seem like those would be reasons we should't override it? (I understand you're example with Python, but would defer to the conhost team to enumerate potential problem).
|
Is it a local powershell only specific setting or is it global affecting all applications whether pwsh is being used or not? In general installing an application should not change global settings without giving the user the option or even visibility. Installing one application should not change the behaviour of an existing app. |
@rhubarb-geek-nz, it would affect PowerShell (and applications run in it) only - no persistent setting involved, just an application-internal call to |
Excellent, and of course it will then revert the console mode to the original value when the pwsh.exe process exits? |
@rhubarb-geek-nz, PowerShell already does that (of necessity, given that it already always turns it on for itself). |
Cool. The reason I mention is is that "git" on Windows 10 does not play nicely with the console and often changes the behaviour of the backspace key to delete word when it exits, and the way to reset it is to run git again with no arguments and it sets it back correctly again. |
Note that we currently explicitly turn off VT prior to invoking a native command, and then turn it back on after we have finished. (Technically we're setting all "Console Mode" settings, so it's possible that VT is incidental but from the comments it doesn't seem to be (though not conclusive)) Not arguing for or against, I don't actually know why we do it. Very interested in what Dustin comes back with |
Thanks, @SeeminglyScience. It seems that this behavior - which was recently tinkered with (#16612) - is the cause of the bug in #18771. Leaving VT support consistently enabled in-session would make such bugs go away, and I do hope that Dustin's response will indicate that it is safe to do so. For now, I suggest reopening #18771, which was inappropriately closed. |
Perhaps we should think about Terminal mode and compatibility (conhost) mode for pwsh. This would essentially mean creating a modern ConsoleHost, which would follow Terminal entirely without any tricks. |
Lets suggest a few goals.
So given that the current behaviour is apparently to turn VT mode off while running child programs this behaviour should be maintained in order to adhere to rule 2, a consistent execution environment. |
I have a better idea for consistency:
In this day and age, VT support should be the default, and especially cross-platform CLIs cannot reasonable assumed - nor should they be expected to - make WinAPI calls just to enable it. Clearly, Windows Terminal has already made that choice and - at least based on my experience - so has Visual Studio Code. The only reason not to do that would be to prevent bad things from happening due to @iSazonov, can you say a bit more about creating a modern ConsoleHost? So if that were done, the above concern would be moot? |
As stated in the Terminal repository, the main goal of |
pwsh.exe is a classic console application ( although written in dotnet ) it should work in any console/terminal environment, it does not need to provide its own. For example you can log into Windows using SSH from Linux or MacOS and run pwsh.exe, what effect does the VT flag now have? |
@rhubarb-geek-nz pwsh can have many ConsoleHost implementations. I guess you think the new host will work only as tab in Terminal. No, I say about using Terminal (shared) components. If they are not present on computer pwsh will use current host for compatibility. If they present (Terminal was installed) you automatically get all benefits in any scenario where it makes sense. |
@SeeminglyScience @mklement0 Perhaps Dustin has already answered this question microsoft/terminal#6634 (comment) |
That's a good find, @o-sdn-o, thank you.
In other words: Windows Terminal has already broken backward compatibility. |
Perhaps in the vast majority of cases, the statement "print raw control characters directly to the screen" means printing Null-characters as whitespaces . Null |
Consider the following example #include <iostream>
int main()
{
auto x = '\0';
std::cout << "@" << x << "@\n";
} VT disabled case output:
VT enabled case output:
|
Thanks, @o-sdn-o - that strikes me as something we needn't worry about: such |
Another example of hastily crafted cli app #include <iostream>
#include <cstring>
int main()
{
using namespace std;
char buffer[80] = {};
auto values = { "Attribute1", "Attribute2", "Attribute3" };
auto offset = buffer + 5;
for (auto v : values)
{
memcpy(offset, v, strlen(v));
offset += 15;
}
cout << string{ buffer, sizeof(buffer) } << "\n";
} VT disabled output:
VT enabled output:
|
Given that this is just a variation of your initial The question is: What raw control sequences designed specifically for for-display formatting (again, you wouldn't use Separately, if such CLIs must still be supported, a per call opt-out could be provided via the proposed |
Rough representation of possible differences. The following glyphs are printed when VT support is disabled (nothing printed if VT support is enabled)
Formatting (in terms of cursor positioning)
|
Just checking the implementation has no effect on Don’t parse the pipeline as text when it is directed from an EXE to another EXE or file. Keep the bytes as-is. |
Great stuff, @o-sdn-o, thank you. @rhubarb-geek-nz, processing in a pipeline is incidental to this issue (which indeed is a problem if the PowerShell pipeline is expected to relay raw bytes, which it currently cannot) - this is about direct-to-display output. |
@mklement0 - Thank you. The registry setting you're seeking is best set by the Windows team. the WG would recommend that you open an issue with them. Use the Windows Feedback Hub.
|
Either way, the problem described in #19395 must be fixed. |
Please write a summary that users can understand while closing a ticket. |
Indeed, this is the exact work around for using powershell (default) command window and python, when VT is not enabled. You have to send a # python.exe -qu -X utf8=1 -c "import os; os.system(''); m='\x1b[30;41m YOUR_TEXT_HERE \x1b[0m'; print(m);"
# YOUR_TEXT_HERE <-- In Color!
# python.exe -qu -X utf8=1 -c "m='\x1b[30;41m YOUR_TEXT_HERE \x1b[0m'; print(m);"
#_[30;41m YOUR_TEXT_HERE_ [0m <-- ANSI garabage
|
This is how magic happens:
|
Thanks for linking that. I forgot it was using the native ctypes there. So I don't see why we can't implement one/both of these following:
|
Perhaps this is due to the following:
|
Summary of the new feature / enhancement
The following environments on Windows already automatically (and invariably) support VT / ANSI escape sequences in output from native (external) programs, notably to produce colored output.
By contrast, in console windows (provided by
conhost.exe
) the support depends on a registry setting that is OFF by default (Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1
enables it).(Note: Some CLIs explicitly enable VT support for themselves, using the WinAPI,
pwsh.exe
andwsl.exe
being examples; these do not depend on the registry setting, but all other ones do.)Making VT support implicit (independent of the registry setting) even for native programs seems worthwhile, to align with user expectations and a modern terminal user experience.
Given that the change only affects how data is displayed, there shouldn't be a backward-compatibility concern.
Implicitly enabling support would also:
simplify the code, given that VT support is currently turned off and on demand, given that it must be enabled for PowerShell commands.
remove bugs in that context, such as Streamed executable output prints Ansi Escaping in Write-* Commandlets #18771 (which was inappropriately closed; a perhaps better repro is
cmd /c | Select-String Microsoft
)Proposed technical implementation details (optional)
No response
The text was updated successfully, but these errors were encountered: