Skip to content

Official API to create a third-party console host (like pty in Unix) #57

Closed

Description

@be5invis

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).

Activity

  1. added
    Issue-Feature
    Product-Conhost
    on Feb 2, 2018
  2. zadjii-msft commented on Feb 2, 2018

    @zadjii-msft
    Member

    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?

  3. be5invis commented on Feb 2, 2018

    @be5invis
    Author

    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.

  4. parkovski commented on Feb 2, 2018

    @parkovski

    My wishlist for this feature:

    • 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).
  5. bgshacklett commented on Feb 3, 2018

    @bgshacklett

    It would be really good to get some input from the authors of terminal emulators like Maximus5/ConEmu and zeit/hyper.

  6. parkovski commented on Feb 8, 2018

    @parkovski

    Cc: Maksim Moisiuk (@Maximus5), not sure of a good contact from hyper.

  7. Maximus5 commented on Feb 8, 2018

    @Maximus5

    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.

  8. bgshacklett commented on Feb 9, 2018

    @bgshacklett

    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.

  9. Eugeny commented on Feb 9, 2018

    @Eugeny

    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.

  10. parkovski commented on Feb 11, 2018

    @parkovski

    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.

  11. be5invis commented on Feb 12, 2018

    @be5invis
    Author

    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.

  12. yatli commented on Feb 12, 2018

    @yatli

    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..

  13. parkovski commented on Feb 12, 2018

    @parkovski

    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.

  14. 54 remaining items

  15. zadjii-msft commented on Jul 10, 2018

    @zadjii-msft
    Member

    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.

    In conclusion:

    • Parker Snell (@parkovski) was almost exactly correct
    • 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
  16. WSLUser commented on Jul 11, 2018

    @WSLUser
    Contributor

    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).

  17. miniksa commented on Jul 11, 2018

    @miniksa
    Contributor

    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.

    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!

  18. zadjii-msft commented on Jul 11, 2018

    @zadjii-msft
    Member

    Nikita Ushakov (@DarthSpock)

    Though that would be a bit strange to see a cmd.exe running inside Konsole

    xterm close enough for you?
    image

    No? Maybe you want to set your default shell in gnome-terminal to cmd.exe?
    image

  19. WSLUser commented on Jul 11, 2018

    @WSLUser
    Contributor

    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!

  20. WSLUser commented on Jul 11, 2018

    @WSLUser
    Contributor

    Mike Griese (@zadjii-msft) Nice! Definitely strange to see but not in a bad way.

  21. bitcrazed commented on Jul 11, 2018

    @bitcrazed
    Contributor

    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 ;)

  22. Tyriar commented on Aug 15, 2018

    @Tyriar
  23. added
    Resolution-Fix-Available
    on Aug 15, 2018
  24. bitcrazed commented on Aug 15, 2018

    @bitcrazed
    Contributor

    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 ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-FeatureProduct-ConhostResolution-Fix-Available

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions