Community
    • Login

    Anyone familair with PseudoConsole API in Windows 10?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    5 Posts 3 Posters 830 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Vitalii DovganV
      Vitalii Dovgan
      last edited by

      Recently I caught sight of this nice article:
      https://learn.microsoft.com/en-us/windows/console/creating-a-pseudoconsole-session
      This technique looks very promising and allows to make NppExec to behave quite closer to a real console.
      So I’ve started to experiment with it:
      https://github.com/d0vgan/nppexec/tree/feature/pseudo-console
      However, I’ve noticed the following strange things while using the PseudoConsole:

      1. The characters that are read as the process output become UTF-8 characters unexpectedly. For example, for the standard cmd.exe, the default character set is OEM, however via PseudoConsole it becomes UTF-8. WTF, I’m asking. Anyway, NppExec allows to deal with it by setting the Console Output to {UTF-8/UTF-8}.
      2. The characters that are read as the process output are full of additional ANSI codes unexpectedly. Anyway, NppExec allows to suppress ANSI codes by using npe_console e1.
      3. The characters that are read as the process output sometimes contain unexpected trailing spaces. I have no idea why they appear.

      So, do we have developers who are familiar with this PseudoConsole API and who could shed some light to these (and probably other) unexpected things?
      Maybe there are some additional options to be specified while dealing with PseudoConsole which I’m not aware of?
      Anyway, please feel free to look into the code and correct me where needed.

      Michael VincentM dinkumoilD 2 Replies Last reply Reply Quote 1
      • Michael VincentM
        Michael Vincent @Vitalii Dovgan
        last edited by Michael Vincent

        @Vitalii-Dovgan said in Anyone familair with PseudoConsole API in Windows 10?:

        So, do we have developers who are familiar with this PseudoConsole API

        No, but have a look here:

        https://github.com/vinsworldcom/nppConsole

        Not sure if this is close to what you’re trying to do or not. I rescued this plugin many years ago so don’t really have any insightful tips as to how it does its magic - it does seem a bit “hacky”.

        Full disclosure - I’m a very happy NppExec user and if you could get essentially PowerShell as the NppExec console I would happily send this plugin back to obscurity in favor of your solution!

        Cheers.

        Vitalii DovganV 1 Reply Last reply Reply Quote 1
        • Vitalii DovganV
          Vitalii Dovgan @Michael Vincent
          last edited by

          The PseudoConsole is a relatively new feature available from Windows 10 October 2018 Update (version 1809). It did not exist before.

          1 Reply Last reply Reply Quote 2
          • dinkumoilD
            dinkumoil @Vitalii Dovgan
            last edited by dinkumoil

            @Vitalii-Dovgan

            I’m not familiar with this (relatively new) PseudoConsole feature but I recently “sneak-peeked” into that topic, so I share what I “know” about it.

            A valuable resource regarding that topic is this blog post of Rich Turner (Microsoft Sr. Program Manager, Windows Console & Command-Line). It is part of a series of blog posts about the Windows console in general, maybe the other parts could be helpful for you as well.

            This blog post explicitely states that the ConPTY or PseudoConsole feature works with UTF-8 character encoding. So, this seems to be the reason for your point 1.

            Another helpful resource could be Microsoft’s Terminal GitHub repo with example projects of how to use the new ConPTY feature.

            The EchoCon project in that repo contains the following lines of code:

                DWORD consoleMode{};
                GetConsoleMode(hConsole, &consoleMode);
                hr = SetConsoleMode(hConsole, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING)
            

            and the docu of GetConsoleMode states

            When a console is created, all input modes except ENABLE_WINDOW_INPUT and ENABLE_VIRTUAL_TERMINAL_INPUT are enabled by default.

            So, a call to SetConsoleMode like above could solve your problem in point 2. regarding “additional ANSI codes”. Maybe they are Virtual Terminal Sequences to control text rendering, cursor positioning, and so forth. It seems that a developer either has to process these VT sequences by himself or he has to delegate that task to an inbuild VT renderer by calling SetConsoleMode with the ENABLE_VIRTUAL_TERMINAL_INPUT flag.

            To your point 3. (the unexpected trailing spaces) I cannot say anything due to lack of experience with ConPTY.

            Vitalii DovganV 1 Reply Last reply Reply Quote 4
            • Vitalii DovganV
              Vitalii Dovgan @dinkumoil
              last edited by

              I tried GetConsoleMode/SetConsoleMode - these funcions are rather for real console (e.g. in a console application or when a console is created explicitly by means of AllocConsole and so on) than for a PseudoConsole. Anyway, it was worth to try since I didn’t have other ideas.

              Eventually I’ve asked another developer for advice since he uses PseudoConsole in his Python code:
              https://github.com/veksha/cuda_exterminal/issues/51
              From his clarifications, NppExec must support ANSI escape codes to deal with PseudoConsole properly. Which, in its turn, returns us to this:
              https://github.com/d0vgan/nppexec/issues/14
              The circle closed up :)
              So it looks like NppExec requires additional code that will handle the ANSI escape codes.

              1 Reply Last reply Reply Quote 2
              • First post
                Last post
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors