Skip to content

ConPTY Passthrough mode  #1173

Closed
Closed

Description

@be5invis

Modern apps won’t read the hidden character grid and do everything in VT. So why not an API/console mode to tell Console Host to completely throw away that?

Activity

  1. added
    Issue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.
    on Jun 8, 2019
  2. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jun 8, 2019
  3. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Jun 8, 2019
  4. DHowett-MSFT commented on Jun 8, 2019

    @DHowett-MSFT
    Contributor

    Mike Griese (@zadjii-msft) was looking into this. The main issue, if I recall correctly, is that we need to trash the entire buffer when something enters or exits “passthrough” mode. It’s also only truly applicable when there is a connected pseudoconsole session.

  5. DHowett-MSFT commented on Jun 8, 2019

    @DHowett-MSFT
    Contributor

    And the reason one console might enter and exit passthrough mode multiple times is that you may run coolNewThing.exe from CMD, and perhaps it might launch a further process that needs legacy support.

    Additional concerns: if you have a tree of four processes, each of which wants passthrough to be different, should the ones that are doing ReadConsoleOutput be able to read the buffers from the other legacy/non-passthrough ones?

    It’s complicated when you get into compatibility discussions. 😄

  6. ghost removed
    Needs-Tag-FixDoesn't match tag requirements
    on Jun 8, 2019
  7. zadjii-msft commented on Jun 10, 2019

    @zadjii-msft
    Member

    Yea, I tried getting this working for like a day last year, but it's something I've wanted to work on for a while.

    As Dustin mentioned, there'd be real weirdness moving between passthrough mode and non-passthrough mode. However, I think it might still be something good to investigate.

  8. zadjii-msft commented on Jul 16, 2019

    @zadjii-msft
    Member

    From #1985:

    I've discussed this a couple times on different threads before, but I think I never made a real issue for it.

    The idea of conpty passthrough mode is that a commandline client application
    that knows it's only going to use VT sequences (and not the API) to modify
    the console could set a special mode, ENABLE_PASSTHROUGH_MODE. If conpty is
    active, the console would then stop rendering itself over conpty, and anything
    that was written to the console would go straight to the terminal.

    • This would work especially well for something like wsl, where it's only ever going to be talking VT.
    • It would not work for cmd.exe, because of cmd.exe's heavy reliance on the API.
    • Windows Powershell again needs the API pretty heavily, but maybe Powershell
      Core, which is cross-platform, could make use of it.

    This has some rough edges that need to be sorted out.

    • What happens when the app exits, and passthrough mode is turned off? The
      terminal and conpty's buffers would not be equivalent anymore!
      • I've been toying with the idea of having conpty both pass the sequences
        through, and also process them itself, so that the terminal and conpty stay
        in sync.
    • What happens when someone tries to call Console API's in passthrough mode?
      • I'm thinking we just cause them to fail. All save for Get/SetConsoleMode and reading input / writing output.
      • We'll also probably need to be able to read resize events.

    This needs a real spec written, but it probably needs prototyping done before that.

  9. changed the title [-]Give ability to let console applications to claim that it will never use Console API and do everything with VT, so Console Host can do more optimizations[/-] [+]ConPTY Passthrough mode [/+] on Jul 16, 2019
  10. oising commented on Jul 17, 2019

    @oising
    Collaborator

    We need a SIGWINCH asynchronous signal for resizing somehow.

  11. mintty commented on Jul 19, 2019

    @mintty

    This is an essential feature for opening MS text-mode software (esp. WSL) to 3rd-party environments.
    The current approach seems to tighly connect the Windows terminal implementation with ConPTY, however that limits applications unnecessarily and makes them highly dependent on Windows terminal progress (which may still take years, honestly).

    It would not work for cmd.exe, because of cmd.exe's heavy reliance on the API.

    It should be a combined mode: Whenever a console-API-based application is run, e.g. as started from a pure terminal-based application, the console API calls should be transformed into terminal escape sequences. Note as there are not so many features in the console API, this is a much easier approach than the reverse mapping, trying to squeeze terminal features through the conhost bottleneck.

  12. 83 remaining items

  13. jerch commented on Jul 25, 2023

    @jerch

    Christian Parpart (@christianparpart) I think the buffer read caps are on the annoying side of things - as far as I remember console API allows complete buffer access (in the sense, that the console app "owns" the console and thus the buffer state). Thats almost impossible with non rect-based VT mechanics or at least will be limited to active cursor area only prolly on all TEs. I still think that most buffer access primitives could be mimicked in VT.
    The hard unsolvable problem might be the exclusiveness, that console API kinda provides to apps with a quite strict process IO coupling/isolation - a thing that many ppl also wish for terminals in linux/macos, but it is just not possible there with the current TTY/PTY abstraction (though its not a matter of VT mechanics but POSIX terminal API).

  14. j4james commented on Jul 25, 2023

    @j4james
    Collaborator

    James Holderness (@j4james) hey, I am curious to know what Windows console API offers that doesn't exist as VT sequence or extension just yet.

    You can find a list of the console APIs here:
    https://learn.microsoft.com/en-us/windows/console/console-functions

    If you click through each of them, you should see a "Tip" section which explains which of them do or don't have a VT equivalent. If you think you can convert all of them into VT sequences, please do feel free to contribute PRs. A lot of the framework is already in place to do this.

    it might make sense to introduce VT sequence extensions for those few

    We aren't even at the point where most conpty terminals are supporting the standard VT sequences we would need. The chances of everyone agreeing to a bunch of Windows-specific extensions on top of that doesn't seem very likely.

    I think what some of you really want is just a pass through mode for WSL. If that's the case, you can assumedly build your terminal as a Linux GUI app running on WSL. But ConPTY is specially for Windows console application support. If you aren't interested in that, this isn't the issue for you.

  15. palves commented on Jul 25, 2023

    @palves

    There is a set of Windows console applications that want the feature (in my case, GDB (GNU Debugger) testing), which don't need anything from the console API that the supported subset of standard VT sequences doesn't already provide. IMO, there could be a console API that such applications could call to enable some restrictive/subset of the API, only. Call it "passthrough mode", or "no intermediate buffer mode" or some such, and when that mode is active, the problematic console APIs (like complete buffer access) would just fail with an error.

  16. zadjii-msft commented on Jul 25, 2023

    @zadjii-msft
    Member

    FWIW that's my preferred approach to solving this. A console mode that a client app can enable to say "I solemnly swear I am up to good". Something like WSL would opt-in, because it knows it's only ever going to do VT.

    That doesn't work as well for mixed applications that want to do both. But that would let legacy console apps rely on conpty's regeneration for their own needs, and modern apps just use VT and all the new features that come with it.

  17. j4james commented on Jul 25, 2023

    @j4james
    Collaborator

    If that's the way we want to go, that's fine, but it means the Windows shells don't gain any benefit from it. For example, you wouldn't be able to TYPE a sixel file, or ECHO a Contour-specific escape sequence and expect it to work. Personally I'd consider this a waste of time, but I can accept that's all some people might care about.

  18. jerch commented on Jul 25, 2023

    @jerch

    To avoid rewriting console API into wonky VT pendants, wouldn't the following work:

    • make stream-IO/passthrough VT-mode default
    • additionally make legacy console API fully abstract on both sides (process & TE side)
    • a TE can decide whether to implement the legacy console primitives, if it does - processes can call into console API as before, if not - processes may not call into legacy console (may need special process flags?)
    • TE operates as single source of truth for console buffer primitves - its the TEs resp. to get data from its internal terminal buffer feeding the TE-side of the console API
    • provide a standard TE on OS side fully implementing legacy console primitives, so things like AttachConsole still works
    • last step - retire ConPty 😺

    Ofc there are details to overcome, like the question whether the console primitives can be made blocking or need true memory sharing & possible security implications.

  19. csdvrx commented on Aug 1, 2023

    @csdvrx

    On a sidenote - recently had a similar image forth and back encoding/decoding need for state serialization within xtermjs, and did not vote for sixel, but QOI (reasonably fast in wasm with good enough compression - much better than any PNG handling offered by the browser engines).

    jerch , am I right to say that we had a few standards already existing (sixel, kitty, ...) and now we've got one more?

    I think it's just sad that the desire for technical perfections goes before practical concerns for something that'd work about everywhere, if leveraging the existing ecosystem.

    So like James Holderness (@j4james), I think not being able to reach some baseline level of functionality is waste of time:

    If that's the way we want to go, that's fine, but it means the Windows shells don't gain any benefit from it. For example, you wouldn't be able to TYPE a sixel file, or ECHO a Contour-specific escape sequence and expect it to work. Personally I'd consider this a waste of time

    Actually, I'd consider that not just a waste of time, but a sad waste of time.

  20. jerch commented on Aug 1, 2023

    @jerch

    am I right to say that we had a few standards already existing (sixel, kitty, ...) and now we've got one more?

    Nope, that serialization format is for TE internal usage only, not intended for outside with an explicit sequence. QOI yields the best compression/performance ratio covering RGBA in 32bit. Since xtermjs is browser based, we cannot just store raw bytes somewhere on the disk for session restore, as other desktop TEs would do here.

  21. zadjii-msft commented on Apr 5, 2024

    @zadjii-msft
    Member

    Nothing to share at this time. We'll make sure to update this thread when there is. In the meantime, might I recommend the Subscribe button?
    image
    That way you'll be notified of any updates to this thread, without needlessly pinging everyone on this thread ☺️

  22. added a commit that references this issue on Aug 2, 2024
    450eec4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-OutputRelated to output processing (inserting text into buffer, retrieving buffer text, etc.)In-PRThis issue has a related PRIssue-FeatureComplex enough to require an in depth planning process and actual budgeted, scheduled work.Needs-Tag-FixDoesn't match tag requirementsProduct-ConhostFor issues in the Console codebase

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions