New implementation of pseudo console support (experimental)
Corinna Vinschen
corinna-cygwin@cygwin.com
Mon Aug 31 19:37:36 GMT 2020
On Aug 31 21:17, Johannes Schindelin wrote:
> [...]
> So I had a look at the code, and it seems that
> `fhandler_pty_slave::setup_locale()` forces the output encoding to
> C.ASCII if Pseudo Console support is enabled:
>
> char locale[ENCODING_LEN + 1] = "C";
> char charset[ENCODING_LEN + 1] = "ASCII";
> LCID lcid = get_langinfo (locale, charset);
>
> /* Set console code page from locale */
> if (get_pseudo_console ())
> {
> UINT code_page;
> if (lcid == 0 || lcid == (LCID) -1)
> code_page = 20127; /* ASCII */
This looks wrong, actually. The default behaviour of Cygwin since
Cygwin 1.7 was to assume UTF-8, even if the application doesn't call
setlocale. This means the locale is "C", so ASCII is expected.
However, even in this case, the internal conversions use UTF-8.
See function internal_setlocale() in nlsfuncs.cc, lines 1553/1554.
We never switched the console codepage, though, because the codepage
doesn't make much sense when using wide character functions only,
i. e. WriteConsoleW. Only the alternate charset is 437/ASCII. So,
if the pseudo console actually *requires* to set the charset...
> else if (!GetLocaleInfo (lcid,
> LOCALE_IDEFAULTCODEPAGE | LOCALE_RETURN_NUMBER,
> (char *) &code_page, sizeof (code_page)))
> code_page = 20127; /* ASCII */
> SetConsoleCP (code_page);
> SetConsoleOutputCP (code_page);
can we please default to UTF-8 here even if the code page is ASCII?
Corinna
More information about the Cygwin-developers
mailing list