From: =?gb18030?B?uay087q6?= <gdh1995@qq.com>
To: =?gb18030?B?Y3lnd2luLXBhdGNoZXM=?= <cygwin-patches@cygwin.com>
Subject: [Patch] Fix incorrect code page when setting console title on Win10
Date: Wed, 26 Aug 2020 16:43:44 +0800 [thread overview]
Message-ID: <tencent_DEAF96B572731C3B3E524F22CCAC86D3AD07@qq.com> (raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb18030", Size: 2757 bytes --]
When Cygwin sets console titles on Win10 (has_con_24bit_colors && !con_is_legacy),
`WriteConsoleA` is used and causes an error if:
1. the environment variable of `LANG` is `***.UTF-8`
2. and the code page of console.exe is not UTF-8
1. e.g. on my Computer, it's GB2312, for Chinese text
I've done some tests on msys2 and details are on https://github.com/git-for-windows/git/issues/2738,
and I filed a PR of https://github.com/git-for-windows/msys2-runtime/pull/25.
Then what should I do, in order to fix this on Cygwin?
The below is the commit's .patch file:
From 334f52a53a2e6b7f560b0e8810b9f672ebb3ad24 Mon Sep 17 00:00:00 2001
From: Dahan Gong <gdh1995@qq.com>
Date: Fri, 31 Jul 2020 22:06:54 +0800
Subject: [PATCH] Fix incorrect code page in console title
`WriteConsoleA` always follows the current code page of a console window, so it's not suitable to pass a multi-byte string in `get_ttyp ()->term_code_page` to it directly.
This PR turns to `WriteConsoleW` so that most characters will be translated "as is", and I've tested it on Win 10 v2004 (CMD: ver 10.0.19041.388).
Signed-off-by: gdh1995 <gdh1995@qq.com>
---
winsup/cygwin/fhandler_console.cc | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index dd979fb8e2..7870eeda81 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -80,6 +80,15 @@ static class write_pending_buffer
{
WriteConsoleA (handle, buf, ixput, wn, 0);
}
+ inline char *c_str (size_t *psize = NULL)
+ {
+ size_t size = ixput < WPBUF_LEN ? ixput : WPBUF_LEN - 1;
+ buf[size] = '\0';
+ if (psize != NULL) {
+ *psize = size;
+ }
+ return (char *) buf;
+ }
} wpbuf;
static void
@@ -3203,7 +3212,14 @@ fhandler_console::write (const void *vsrc, size_t len)
if (*src < ' ')
{
if (wincap.has_con_24bit_colors () && !con_is_legacy)
- wpbuf.send (get_output_handle ());
+ {
+ size_t nms;
+ char *ms = wpbuf.c_str(&nms);
+ wchar_t write_buf[TITLESIZE + 1];
+ DWORD done;
+ DWORD buf_len = sys_mbstowcs (write_buf, TITLESIZE, ms);
+ write_console (write_buf, buf_len, done);
+ }
else if (*src == '\007' && con.state == gettitle)
set_console_title (con.my_title_buf);
con.state = normal;
next reply other threads:[~2020-08-26 8:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-26 8:43 =?gb18030?B?uay087q6?= [this message]
2020-08-26 9:06 ` Corinna Vinschen
2020-08-26 7:30 ` Johannes Schindelin
2020-08-26 17:33 ` Corinna Vinschen
2020-08-27 3:34 ` Takashi Yano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_DEAF96B572731C3B3E524F22CCAC86D3AD07@qq.com \
--to=gdh1995@qq.com \
--cc=cygwin-patches@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).