public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pty: Prevent garbled output for existing non-cygwin apps.
@ 2020-09-11 10:54 Takashi Yano
  2020-09-11 12:09 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Takashi Yano @ 2020-09-11 10:54 UTC (permalink / raw)
  To: cygwin-patches

- If pseudo console is disabled, non-cygwin apps do not detect
  console device. In this case, some apps output UTF-8 regardless
  of the locale setting. At least git-for-windows, rust-based apps
  and node.js do that. This patch provides backward compatibility
  as default behaviour by setting console codepage to the charset of
  the locale. Even in the cases above, garbled output is prevented
  with this patch in most cases because mintty uses UTF-8 by default.

  I beleave this is not really a problem in cygwin side but that in
  app side, however, some users complain about garbled output with
  existing apps in MSYS2 (which is based on cygwin) in which pseudo
  console is disabled by default.
---
 winsup/cygwin/fhandler_tty.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index ee5c6a90a..3d93bef30 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1835,7 +1835,11 @@ fhandler_pty_slave::setup_locale (void)
   extern UINT __eval_codepage_from_internal_charset ();
 
   if (!get_ttyp ()->term_code_page)
-    get_ttyp ()->term_code_page = __eval_codepage_from_internal_charset ();
+    {
+      get_ttyp ()->term_code_page = __eval_codepage_from_internal_charset ();
+      SetConsoleCP (get_ttyp ()->term_code_page);
+      SetConsoleOutputCP (get_ttyp ()->term_code_page);
+    }
 }
 
 void
-- 
2.28.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Cygwin: pty: Prevent garbled output for existing non-cygwin apps.
  2020-09-11 10:54 [PATCH] Cygwin: pty: Prevent garbled output for existing non-cygwin apps Takashi Yano
@ 2020-09-11 12:09 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2020-09-11 12:09 UTC (permalink / raw)
  To: cygwin-patches

On Sep 11 19:54, Takashi Yano via Cygwin-patches wrote:
> - If pseudo console is disabled, non-cygwin apps do not detect
>   console device. In this case, some apps output UTF-8 regardless
>   of the locale setting. At least git-for-windows, rust-based apps
>   and node.js do that. This patch provides backward compatibility
>   as default behaviour by setting console codepage to the charset of
>   the locale. Even in the cases above, garbled output is prevented
>   with this patch in most cases because mintty uses UTF-8 by default.
> 
>   I beleave this is not really a problem in cygwin side but that in
>   app side, however, some users complain about garbled output with
>   existing apps in MSYS2 (which is based on cygwin) in which pseudo
>   console is disabled by default.
> ---
>  winsup/cygwin/fhandler_tty.cc | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
> index ee5c6a90a..3d93bef30 100644
> --- a/winsup/cygwin/fhandler_tty.cc
> +++ b/winsup/cygwin/fhandler_tty.cc
> @@ -1835,7 +1835,11 @@ fhandler_pty_slave::setup_locale (void)
>    extern UINT __eval_codepage_from_internal_charset ();
>  
>    if (!get_ttyp ()->term_code_page)
> -    get_ttyp ()->term_code_page = __eval_codepage_from_internal_charset ();
> +    {
> +      get_ttyp ()->term_code_page = __eval_codepage_from_internal_charset ();
> +      SetConsoleCP (get_ttyp ()->term_code_page);
> +      SetConsoleOutputCP (get_ttyp ()->term_code_page);
> +    }
>  }
>  
>  void
> -- 
> 2.28.0

Pushed.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-09-11 12:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-11 10:54 [PATCH] Cygwin: pty: Prevent garbled output for existing non-cygwin apps Takashi Yano
2020-09-11 12:09 ` Corinna Vinschen

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).