You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Official API to create a third-party console host (like pty in Unix) #57
Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Product-ConhostFor issues in the Console codebaseResolution-Fix-AvailableIt's available in an Insiders build or a release
Yes, a full, comprehensive pty API. It should be able to handle all kinds of console applications that run in Conhost (WSL, Win32, UWP, even 16-bit DOS programs).
Reacted by Joel Handwell, Tristano Ajmone, mattn, Tim Haintz, Parker Snell, nickcox, Yatao Li, Maksim Moisiuk, Daniel Imms, Dirk Bäumer and 50 more
Reacted by Bodie, Mustafa Mohamad, MOZGIII, Davy, Laxman Damera, Josema and ExE Boss
I've definitely heard this ask more than a few times before.
"Official pty API for Conhost" does seem like a bit of a broad feature request. I'm not saying that it's totally impossible, but lets entertain the hypothetical for a bit here.
If I were to go about implementing this, what would be the most important things for me to implement? What kind of surface would this API have? How would you expect it to behave?
Well you know, CONHOST internally has a char matrix that places all the characters. So the API should output such things without opening a CONHOST window.
Provide a way to create a pair of console handles without going through conhost.
Document "implement" a function, let's call it ConsoleControl, that lets you generate the events a console client would expect to receive.
Make WSL tty interop handles translate to these.
Document what kind of black magic you have to use to make cmd.exe respond to a ^C.
Bonus for 3rd party console authors: an official way to set these handles as "this process' console" so when someone calls AttachConsole it works (and similar for GetConsoleWindow).
Reacted by Joel Handwell, jonocosa , su21, ExE Boss and xrh0905
It's a real pain to implement ConEmu via official console API. I have to use detours to hook almost all available functions. And what for? Linux provides pty functions and signals for decades and they have many terminals for any taste.
Reacted by Serhii Olendarenko, fpqc, Mike MacCana, gurpreetshanky, Roy Ivy III, isRyven, Joel Handwell, su21, ExE Boss, Corbin Crutchley and 8 more
Both Hyper and Terminus use node-pty as a PTY backend, which in turn uses the winpty project to provide a pty API on Windows, which is basically a ton of black magic that runs a hidden conhost window and reads its contents.
Having an API identical to the POSIX pty controls would allow cutting the amount of code in node-pty in half and dropping winpty.
Reacted by Joel Handwell, Mike MacCana, ives and Yang Hanlin
The hooking issues are why I think this is important. I don't think it's even possible to create console handles without opening a conhost window. You can't even make a custom driver that acts like a console without hooking all the APIs.
I think it's great that the built-in console window is improving, but it shouldn't be this hard and hacky to implement a third party terminal. I don't think the exact shape of the API is that important, because if the functionality is there somebody will make a pty wrapper API.
This (for tmux) and a sudo command that doesn't go through UAC are the last pieces I need to make the Windows console the dev environment I want. I'm not familiar with the headless Windows server, but I'd imagine these things would be pretty important there too.
Parker Snell (@parkovski)
Historically the CONHOST has a deep link with the Kernel, and it is simulating a 1980s video adapter's text mode. I remember that in Windows Vista, all windows are in the glass-style material, but only the console is still in the old look and feel. You can even draw text outside the console window.
Perhaps we could move all the legacy compatibility into the "old" console, and provide PTY APY only for the "new" console.
Belleve (@be5invis) does the pty features conflict with the legacy console? If not, we can regard the features as an "extension". For example, report terminal type as "VT-MSCMD" which allows things like, actively changing the size of the window. In this way both legacy apps (which ignore the PTY stuff) and the terminal bits will be happy.
If PTY mode is activated, behaviors outside the range of PTY feature set can be translated into escape codes specific to VT-MSCMD, just like how SIXEL cooperates with xterm.
And of course, a PTY program can ignore these escape codes or just write them to STDOUT..
The implementation has changed a lot since then - the console window used to live in csrss, which is why it missed out on theming. There's a good overview of this here, but basically whenever a console subsystem program is launched or you call AllocConsole, csrss creates a new connection to the console driver and passes the handle to conhost.exe.
Conhost is now a regular user-land program, it's just blessed with the ability to be given new console handles and an API that we don't have. When I run WinAPIOverride on it, I see a bunch of calls to DeviceIoControl (undocumented flags) and ConsoleControl (undocumented function). The rest of the console APIs look like they call NtDeviceIoControlFile directly. If we could create new console handles and use these APIs without going through conhost, I think we'd have what we need to make a Unix pty wrapper. Basically, I think the functionality is there, it's just not exposed to anyone other than conhost right now.
Well, we don't have real, official documentation on it ready quite yet, but I'll share some details:
No, existing console apps do not have to be modified. They will run just as they always have, attached to a full-featured conhost who is acting as the console API server.
case in point: WSL's interop in insider builds uses an early version of this feature, and I use that as my daily driver. Being able to run cmd.exe inside of tmux is bliss
Terminal applications will be able to create a pseudoconsole by passing a read/write pair of handles to CreatePseudoConosle. This function will give you back a handle you can then use to attach a client commandline application to. Stay tuned for documentation on how to do this, but essentially, the terminal app is now capable of launching commandline apps attached to a pseudoconsole instead of a windowed conhost.
With the other side of the read/write handles supplied to the pseudoconsole, callers will be able to provide input to the commandline application and read the output of the terminal. These work as streams of utf-8 characters and embedded VT sequences.
yes we are hoping this might be able to replace wslbridge/winpty
it is backwards compatible with existing console apps
yes there will still be weirdness in RS5; hopefully with feedback from partners and the community we will be able to resolve any strange quirks you might see
Reacted by WSLUser, Parker Snell, Zac Pullar-Strecker, Joel Handwell, Dmitrii Miroshnichenko and Borek Bernard
How much easier does this make native conhost able to perform proper VT sequences and display UTF-8 chars (vice the legacy UTF)? It sounds like it would ensure far faster procurement of new features (such as emojis and Sixel support). If this is the case, then I would think terminal apps like Konsole (which I highly desire to be available on Windows) would be even more easily ported to Windows. Though that would be a bit strange to see a cmd.exe running inside Konsole (not that I'd complain). What would be funnier is if somebody ported Iterm2 to Windows using the API. Sounds like everything that's needed is in place afterall (minus the critical bugs you're squashing).
Nikita Ushakov (@DarthSpock), the latter half of your post there about being able to port other terminals that natively speak VT to Windows is something that should be very possible here when we round all the sharp edges off the feature.
As for conhost.exe itself displaying new things.... that's not super changing here. It's technically capable internally now of holding a lot more stuff within the Unicode planes than it was before to help enable this functionality (big points to adiviness for working on this part!), but we haven't been able to make conhost display all of them correctly on its own surface yet. We need a renderer overhaul for that.... which is on our backlog. That's when you'd see emojis for sure and maybe... MAYBE sixels... show up on conhost's window itself.
Our major focus here has been to engineer a platform that is capable of servicing the content needed by others to "make terminals great again" on Windows. We're the only ones who can change the OS to enable others to succeed in this way, so that's been our focus this release. Making our inbox terminal surface great in conhost is something we'd love to do too.... but there are a lot of great terminals out there and we have limited resources. So we're trying to unblock the world first in a way that only we can and we'll assuredly turn our eyes back to our own terminal surface again in the future.
There's a pending blog post from us to explain what we've done here for this release that should include some of these details and what it is capable of and what it is not capable of. Rich Turner (@bitcrazed) already has a draft of the post in our inboxes for review. We're currently sassing him about the diagrams and some of the wording, so it will take a little more time before it rolls out.
That's totally understandable and think it's great what you've done! I'm just thinking there will be environments where even with this API, ported terminals may not be available (authorized) for download so if it can be leveraged for native conhost, that would be great news as well.
I always keep on eye on the commandline blog for new posts and have been following along the console series (which are great btw). Looking forward to seeing the docs updated. Enjoy the bug bashing!
I have two new posts in this series in-progress as I type :) Firsts discussing Console Internals is nearing completion. The next talks PTYs. Stand by ;)
Reacted by Parker Snell, gurpreetshanky, Joel Handwell, Daniel Imms, Yatao Li, Laxman Damera, WSLUser, Mohi, Arkady Shapkin, karliss and 5 more
Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Product-ConhostFor issues in the Console codebaseResolution-Fix-AvailableIt's available in an Insiders build or a release
Activity
zadjii-msft commentedon Feb 2, 2018
I've definitely heard this ask more than a few times before.
"Official pty API for Conhost" does seem like a bit of a broad feature request. I'm not saying that it's totally impossible, but lets entertain the hypothetical for a bit here.
If I were to go about implementing this, what would be the most important things for me to implement? What kind of surface would this API have? How would you expect it to behave?
be5invis commentedon Feb 2, 2018
Well you know, CONHOST internally has a char matrix that places all the characters. So the API should output such things without opening a CONHOST window.
parkovski commentedon Feb 2, 2018
My wishlist for this feature:
Document"implement" a function, let's call it ConsoleControl, that lets you generate the events a console client would expect to receive.Bonus for 3rd party console authors: an official way to set these handles as "this process' console" so when someone calls AttachConsole it works (and similar for GetConsoleWindow).
bgshacklett commentedon Feb 3, 2018
It would be really good to get some input from the authors of terminal emulators like Maximus5/ConEmu and zeit/hyper.
parkovski commentedon Feb 8, 2018
Cc: Maksim Moisiuk (@Maximus5), not sure of a good contact from hyper.
Maximus5 commentedon Feb 8, 2018
It's a real pain to implement ConEmu via official console API. I have to use detours to hook almost all available functions. And what for? Linux provides pty functions and signals for decades and they have many terminals for any taste.
bgshacklett commentedon Feb 9, 2018
Vercel (formerly ZEIT) (@zeit)Leo Lamprecht (@leo) and CHaBou (@chabou) appear to be the most active on Hyper. Also, Eugene (@Eugeny) has the Terminus project.Eugeny commentedon Feb 9, 2018
Both Hyper and Terminus use node-pty as a PTY backend, which in turn uses the winpty project to provide a pty API on Windows, which is basically a ton of black magic that runs a hidden conhost window and reads its contents.
Having an API identical to the POSIX pty controls would allow cutting the amount of code in node-pty in half and dropping winpty.
parkovski commentedon Feb 11, 2018
The hooking issues are why I think this is important. I don't think it's even possible to create console handles without opening a conhost window. You can't even make a custom driver that acts like a console without hooking all the APIs.
I think it's great that the built-in console window is improving, but it shouldn't be this hard and hacky to implement a third party terminal. I don't think the exact shape of the API is that important, because if the functionality is there somebody will make a pty wrapper API.
This (for tmux) and a sudo command that doesn't go through UAC are the last pieces I need to make the Windows console the dev environment I want. I'm not familiar with the headless Windows server, but I'd imagine these things would be pretty important there too.
be5invis commentedon Feb 12, 2018
Parker Snell (@parkovski)
Historically the CONHOST has a deep link with the Kernel, and it is simulating a 1980s video adapter's text mode. I remember that in Windows Vista, all windows are in the glass-style material, but only the console is still in the old look and feel. You can even draw text outside the console window.
Perhaps we could move all the legacy compatibility into the "old" console, and provide PTY APY only for the "new" console.
yatli commentedon Feb 12, 2018
Belleve (@be5invis) does the pty features conflict with the legacy console? If not, we can regard the features as an "extension". For example, report terminal type as "VT-MSCMD" which allows things like, actively changing the size of the window. In this way both legacy apps (which ignore the PTY stuff) and the terminal bits will be happy.
If PTY mode is activated, behaviors outside the range of PTY feature set can be translated into escape codes specific to VT-MSCMD, just like how SIXEL cooperates with xterm.
And of course, a PTY program can ignore these escape codes or just write them to STDOUT..
parkovski commentedon Feb 12, 2018
The implementation has changed a lot since then - the console window used to live in csrss, which is why it missed out on theming. There's a good overview of this here, but basically whenever a console subsystem program is launched or you call
AllocConsole, csrss creates a new connection to the console driver and passes the handle toconhost.exe.Conhost is now a regular user-land program, it's just blessed with the ability to be given new console handles and an API that we don't have. When I run WinAPIOverride on it, I see a bunch of calls to DeviceIoControl (undocumented flags) and ConsoleControl (undocumented function). The rest of the console APIs look like they call NtDeviceIoControlFile directly. If we could create new console handles and use these APIs without going through conhost, I think we'd have what we need to make a Unix pty wrapper. Basically, I think the functionality is there, it's just not exposed to anyone other than conhost right now.
54 remaining items
zadjii-msft commentedon Jul 10, 2018
Well, we don't have real, official documentation on it ready quite yet, but I'll share some details:
CreatePseudoConosle. This function will give you back a handle you can then use to attach a client commandline application to. Stay tuned for documentation on how to do this, but essentially, the terminal app is now capable of launching commandline apps attached to a pseudoconsole instead of a windowed conhost.In conclusion:
WSLUser commentedon Jul 11, 2018
How much easier does this make native
conhostable to perform proper VT sequences and display UTF-8 chars (vice the legacy UTF)? It sounds like it would ensure far faster procurement of new features (such as emojis and Sixel support). If this is the case, then I would think terminal apps like Konsole (which I highly desire to be available on Windows) would be even more easily ported to Windows. Though that would be a bit strange to see acmd.exerunning inside Konsole (not that I'd complain). What would be funnier is if somebody ported Iterm2 to Windows using the API. Sounds like everything that's needed is in place afterall (minus the critical bugs you're squashing).miniksa commentedon Jul 11, 2018
Nikita Ushakov (@DarthSpock), the latter half of your post there about being able to port other terminals that natively speak VT to Windows is something that should be very possible here when we round all the sharp edges off the feature.
As for
conhost.exeitself displaying new things.... that's not super changing here. It's technically capable internally now of holding a lot more stuff within the Unicode planes than it was before to help enable this functionality (big points to adiviness for working on this part!), but we haven't been able to makeconhostdisplay all of them correctly on its own surface yet. We need a renderer overhaul for that.... which is on our backlog. That's when you'd see emojis for sure and maybe... MAYBE sixels... show up onconhost'swindow itself.Our major focus here has been to engineer a platform that is capable of servicing the content needed by others to "make terminals great again" on Windows. We're the only ones who can change the OS to enable others to succeed in this way, so that's been our focus this release. Making our inbox terminal surface great in
conhostis something we'd love to do too.... but there are a lot of great terminals out there and we have limited resources. So we're trying to unblock the world first in a way that only we can and we'll assuredly turn our eyes back to our own terminal surface again in the future.There's a pending blog post from us to explain what we've done here for this release that should include some of these details and what it is capable of and what it is not capable of. Rich Turner (@bitcrazed) already has a draft of the post in our inboxes for review. We're currently sassing him about the diagrams and some of the wording, so it will take a little more time before it rolls out.
I recommend you watch https://blogs.msdn.microsoft.com/commandline/ for our posts on the Windows Command-Line to find out more. Rich has really started to get the flywheel moving on pushing blog posts out. The devs are also chomping at the bit to start sharing some more of our workings with you via that platform as soon as we get the boilerplate series of articles out.
And I promise you we'll get to filling out docs for this at https://docs.microsoft.com/en-us/windows/console/ in the next few months. We're just at the peak of bug bashing time right now. When bugs slow down, we will spend more time on writing up the detailed documentation. We wish we had more hours in every day! Thanks for your patience and interest!
zadjii-msft commentedon Jul 11, 2018
Nikita Ushakov (@DarthSpock)
xterm close enough for you?

No? Maybe you want to set your default shell in

gnome-terminaltocmd.exe?WSLUser commentedon Jul 11, 2018
That's totally understandable and think it's great what you've done! I'm just thinking there will be environments where even with this API, ported terminals may not be available (authorized) for download so if it can be leveraged for native conhost, that would be great news as well.
I always keep on eye on the commandline blog for new posts and have been following along the console series (which are great btw). Looking forward to seeing the docs updated. Enjoy the bug bashing!
WSLUser commentedon Jul 11, 2018
Mike Griese (@zadjii-msft) Nice! Definitely strange to see but not in a bad way.
bitcrazed commentedon Jul 11, 2018
I have two new posts in this series in-progress as I type :) Firsts discussing Console Internals is nearing completion. The next talks PTYs. Stand by ;)
Tyriar commentedon Aug 15, 2018
The blog post announcing "ConPTY" went out 🎉 https://blogs.msdn.microsoft.com/commandline/2018/08/02/windows-command-line-introducing-the-windows-pseudo-console-conpty/
bitcrazed commentedon Aug 15, 2018
Thanks Daniel Imms (@Tyriar) - AT LAST, right? ;)
And with the public announcement of ConPTY API in current Insiders builds, and coming to this fall's release of Windows 10, I am closing this issue.
Thanks for your patience everyone ;)
Metrics UI: Tell Windows users how to stop zcashd
Metrics UI: Tell Windows users how to stop zcashd
Metrics UI: Tell Windows users how to stop zcashd