Skip to content
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

Is there a way for parent process to set the codepage to be used by ConPTY? #9174

Closed
Eli-Zaretskii opened this issue Feb 15, 2021 · 8 comments
Labels
Issue-Question For questions or discussion Product-Conpty For console issues specifically related to conpty Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@Eli-Zaretskii
Copy link

Description of the new feature/enhancement

This could be a feature request, or it could be a question about an existing feature (in which case apologies for missing that feature.

The problem is that a Pseudo Console seems to assume that the child process sends text encoded in the default console codepage, and it converts the text to UTF-8 under that assumption. When this assumption is false, the text read by the parent process from the other end of the pipe will represent very different characters.

Case in point: in my locale, the ANSI codepage is 1255, but the default console OEM codepage seems to be 437, something utterly inadequate for dealing with Hebrew text.

Another case in point: Git for Windows by default produces UTF-8 output, and while it can be told to use some other encoding, doing so is not recommended and generally causes problems in the long run, as non-UTF-8 sequences seep into the repository.

In sum, there are real-life use cases where (a) the application in the child process emits non-ASCII text encoded in something other than the default console codepage, and (b) the programmer who programs the parent application has no control on the code of the child application, and so can neither affect its encoding nor add a call to SetConsoleOutputCP to that application.

What is needed in this case is some way for the parent process to tell Pseudo Console to use a specific codepage when converting the output of the child process to UTF-8. Is this possible with the current APIs? If not, could such a feature be added?

This feature, if added, would allow to use Pseudo Console for communicating with child processes in a way similar to communications via pipes, but with the child process behaving as if it were invoked interactively vis-a-vis a terminal device, not unlike how PTYs are used on Posix systems.

Proposed technical implementation details (optional)

One possible implementation would be an API similar to SetConsoleOutputCP, but one that accepts a handle, either to the Pseudo Console or to one of its pipes.

Thanks.

@Eli-Zaretskii Eli-Zaretskii added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Feb 15, 2021
@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Feb 15, 2021
@DHowett
Copy link
Member

DHowett commented Feb 15, 2021

This is a reasonable request, but I do want to ask:

no control on the code of the child

can neither affect its encoding

How does this application work in a normal console window if it's incompatible with the default system codepage?

@Eli-Zaretskii
Copy link
Author

How does this application work in a normal console window if it's incompatible with the default system codepage?

It depends on special setup of the console where it runs. For example, Git runs in Git Bash window, which is not the default Command Prompt window. Other applications could require that "someone" runs chcp before starting them.

@lonnywong
Copy link
Contributor

Any progress?

@zadjii-msft
Copy link
Member

No, sorry for letting this fall so far down the triage queue.

This kinda just sounds by design right now.

The "git bash runs in a git bash window" thing - yea, I'm pretty sure they're running in winpty and the console isn't involved at all there. There, the client can just write output to the stdout pipe, and then mintty just reads whatever the bytes are.

Other applications could require that "someone" runs chcp before starting them

That sounds like exactly the same thing that would happen today

Ultimately, seems like the root of the issue here is:

(a) the application in the child process emits non-ASCII text encoded in something other than the default console codepage

but, under the assumption that the child process never added a call to SetConsole*Codepage. That kinda seems like an issue that the client application should resolve, right? Maybe I'm missing something. We're all talking in hypotheticals here, a concrete example might be useful.

Maybe there's something I'm missing between

in my locale, the ANSI codepage is 1255, but the default console OEM codepage seems to be 437

@zadjii-msft zadjii-msft added Issue-Question For questions or discussion Product-Conpty For console issues specifically related to conpty and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels Jul 13, 2022
@Eli-Zaretskii
Copy link
Author

You are basically saying that ConPTY is meant to be used as a console, i.e. its other end is actually displayed to users. Whereas I thought that ConPTY is meant to be used like PTY devices on Unix systems, where they are frequently used instead of pipes to have one process drive another via a bidirectional communications channel. The advantage of using PTYs like that is that the child program which writes to the PTY behaves as it would behave when its output was a console device, and thus the parent program could be a front-end to it. For example, there are programs that colorize their output, but only when the output is a console device. Or there are programs that automatically make their output unbuffered when it is connected to a console device, but not when it's a pipe.

So using PTYs instead of pipes allows to run the child process and have it behave as it does when it writes to a console, but the parent process can then grab the output and do whatever it likes with that. In these scenarios, it is frequently desirable to use encoding of text that is not the system codepage, because the system codepage could be inappropriate. Pipes allow that, but ConPTY doesn't. And if this is the design, then ConPTYs can never be used as the Windows equivalent of the Unix PTYs, because the latter don't have that limitation. Which is IMO too bad.

@carlos-zamora
Copy link
Member

carlos-zamora commented Dec 7, 2022

Which is IMO too bad.

Unfortunately, not all of the Windows console API can easily be converted directly into streamable operations. We're making progress on this in #1173, but we're not there yet. In the interest of maintaining our focus, I'm gonna track this work item over there /dup #1173.

@ghost
Copy link

ghost commented Dec 7, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Dec 7, 2022
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Dec 7, 2022
@ghost
Copy link

ghost commented Dec 7, 2022

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question For questions or discussion Product-Conpty For console issues specifically related to conpty Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

6 participants
@DHowett @carlos-zamora @zadjii-msft @lonnywong @Eli-Zaretskii and others