-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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 setting environment variable when Terminal hosts cmd / powershell #840
Comments
This is a good idea. We've previously had discussions about the terminal setting I know there are plans of getting the DxRenderer that the Terminal uses in to conhost properly, once it's bugs are worked out. In that case, the emoji would render correctly. That however would be harder to detect, because I'm sure conhost isn't going to set some variable to @miniksa for his thoughts. |
I’d like to have this too, actually, but for a different reason. If you look at Terminal.app and iTerm, they expose a “session” environment variable. It’s a way for a client process to both detect the presence of the terminal emulator and associate session-specific data. This is really useful when it comes to automatic restart, where the shell can be somewhat complicit in resuming where you left off. Overall, we need something here: we should probably set |
Yes, I would like to switch conhost.exe over to the DX renderer by default which would eliminate some of the pressure of this change because it would understand emoji on the other side of the fence too. It's just probably going to be a longer-term thing because switching that over will probably cause a stream of bugs from the OS product that I don't want to deal with right now because I want to focus on the out-of-box GitHub work in the short-term. However, I am not opposed to setting environment variables to provide some semblance of understanding over the environment that the client application is living within. I would almost think we would do And then perhaps we do |
Just so y'all know, there is already a WinTerm out there: https://sourceforge.net/projects/winterm/ |
Crap. OK. Think of something else. |
I was considering just setting ‘WT_SESSION=<random uuid>‘ |
Where should this be done? From poking at the code, my best hacky guess is something like this just before the CreateProcessW call in Entrypoints::StartConsoleForCmdLine: // Set unique session identifier.
GUID sessionGUID;
RETURN_IF_FAILED(CoCreateGuid(&sessionGUID));
WCHAR wszSessionGUID[MAX_PATH]{};
(void)StringFromGUID2(sessionGUID, wszSessionGUID, static_cast<int>(std::size(wszSessionGUID)));
wszSessionGUID[wcslen(wszSessionGUID) - 1] = '\0';
WCHAR* pwszSessionGUID{&wszSessionGUID[1]};
RETURN_IF_WIN32_BOOL_FALSE(SetEnvironmentVariableW(L"WT_SESSION", pwszSessionGUID)); However, I suspect there's a better place to put this. Also, even if that is the right place, it seems wrong somehow to set WT_SESSION directly there. I haven't been able to figure out the execution flow from when a new tab is created to StartConsoleForCmdLine. I also suspect a cleaner implementation here would be to extend ConsoleArguments to include environment variables and have the caller pass it. I could use some hints on where this is best done. |
You might have the In the Then since the ConPTY/Conhost won't be otherwise messing with Pinging @zadjii-msft for confirmation that this sounds correct. |
Yea that sounds right to me |
In the future, we'll probably want to support a generic "connection arguments" type that can be pushed down into each connection. |
Im guessing this was implimented for this purpose as I have seen it and tried using it for this purpose however, if i launch an applicaiton with embeded terminals they are also getting a random WT_SESSION value. Is there any way to stop nested processes from inheriting this WT_SESSION ? eg. to replicate
|
Windows Terminal has support for unicode character display, etc. that the old cmd / powershell windows do not. This makes it difficult to create a shell profile (such as Microsoft.Powershell_profile.ps1) that works compatibly with both the old cmd / powershell windows and the new Windows Terminal.
If an environment variable was set by Terminal when hosting cmd / powershell / wsl, etc. it would allow users to detect they are hosted by the new Terminal and then enable use of unicode character display, etc. compatibly.
For example, my powershell profile prompt has been altered to include some emojis. In the old powershell window, this happens:
In the new Windows Terminal:
I could make my profile compatible with both if I had an environment variable to check.
The text was updated successfully, but these errors were encountered: