-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Official API to create a third-party console host (like pty in Unix) #57
Comments
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. |
My wishlist for this feature:
|
It would be really good to get some input from the authors of terminal emulators like Maximus5/ConEmu and zeit/hyper. |
Cc: @Maximus5, not sure of a good contact from hyper. |
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. |
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. |
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. |
@parkovski |
@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. |
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 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. |
Hey all, I just want you to know that we're definitely going to be CLOSELY following this discussion. A "PTY Implementation" is one of the highest items on the backlog, and it will likely be one of the most important things to get right the first time. What I'm getting from this discussion:
Would these things satisfy most people? What am I missing, what could be improved, etc. |
It would be good if we could provide a callback as a "layout function," i.e., the API would call this callback function to fill a string into the character matrix. It would be useful for multi-language support since the layout is a hard task. |
My requirements:
|
@be5invis I think it's important to differentiate between a Pty, which is terminal/layout agnostic and only handles data and extra messages/signals and a terminal, which handles the visual layout. |
@zadjii-msft I think you described proper requirements. There is also some craziness with ReadFile called on console handle. In some cases it behaves like ReadConsoleA (returns a line, processing Enter, arrows for history, Tab for completion...), but in other cases it just return ANSI characters one by one. It's hardly possible to find documentation and requirements for console modes ReadFile depends on... |
@Maximus5 How would you feel if the input "API" was sane on how it was handled, but didn't support certain keystrokes? For example, Ctrl-M, Ctrl-J and Enter. Do we really care about differentiating between Ctrl-M and Enter, or would it be okay to map Ctrl-M to Enter (As long as it's documented as such)? They're different keystrokes on the keyboard, sure, but for any *nix style terminals, we can't differentiate those keys. |
@zadjii-msft If we are talking about future POSIX PTY API it's OK, because indeed in Unix many keystrokes are mapped to one sequence. Personally I consider this as lack of interface, but compatibility makes the rules. But proposed API in this topic is supposed to let us ability to implement "third-party conhost" windows. And I believe it must not be limited to neither Unix nor Windows limitations! By Windows limitations I mean features like
If we (third-party devs) may create real console handles which may be used with native console API functions I believe we would be able to implement any emulation type - POSIX or Windows. |
Clarify the title. |
@be5invis agree in the title change, that this should be a PTY-like layer. Additionally, I feel that we should separate these two things:
In this way there is no interference between existing windows console apps and the *nix things because the former leverages only 1) and the latter leverages 1) and 2). |
A few thoughts on complications:
|
I do want to make a note, whatever we end up implementing is going to allow existing client applications to continue using the full Win32 console API, and ideally it's going to be without forcing 3rd party terminals from implementing the entire console API surface themselves. We'd love to hide the "black magic", and expose only a sane surface to implement on top of. P.S. This discussion is my favorite of all of them, a lot of good thoughts in here. |
Just echoing @Eugeny's thoughts; this would both greatly simplify and improve the stability of the terminal within VS Code, or where ever node-pty/winpty is used. Currently there's no way forward for many of the VS Code terminal Windows issues due to the way it's implemented. A proper pty API (with legacy emulation on conhost's side) would have massive impact. |
@mintty This would take the place of winpty or wslbridge - allows you to act as conhost without any hacks or workarounds. The console apps on the other end don't have to be modified, just the terminal app taking the place of conhost. Presumably |
Well, we don't have real, official documentation on it ready quite yet, but I'll share some details:
In conclusion:
|
How much easier does this make native |
@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 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 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. @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! |
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! |
@zadjii-msft Nice! Definitely strange to see but not in a bad way. |
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 ;) |
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/ |
Thanks @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 ;) |
Ctrl+C is not configured for Windows, as it does not work (yet): microsoft/vscode#9347 microsoft/terminal#57
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).
The text was updated successfully, but these errors were encountered: