From 05013fe7cc5bbc3f20a840bc44a49c1e07702bf4 Mon Sep 17 00:00:00 2001
From: Takashi Yano <takashi.yano@nifty.ne.jp>
Date: Fri, 4 Sep 2020 18:31:35 +0900
Subject: [PATCH] Cygwin: pty: Prevent garbled output when pseudo console is
 disabled.

- If pseudo console is disabled, non-cygwin apps do not detect
  console device. In this case, the some apps may output messages
  based on the locale. In addition, some apps output UTF-8 string
  regardless of the locale setting. At least git-for-windows and
  node.js do that. Even in this case, garbled output is prevented
  with this patch in most cases because mintty uses UTF-8 by default.
---
 winsup/cygwin/fhandler_tty.cc | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index fd74a9f3d..3b33e82f7 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1848,6 +1848,8 @@ fhandler_pty_slave::setup_locale (void)
 	  get_ttyp ()->term_code_page = cs_names[i].cp;
 	  break;
 	}
+  SetConsoleCP (get_ttyp ()->term_code_page);
+  SetConsoleOutputCP (get_ttyp ()->term_code_page);
 }
 
 void
-- 
2.28.0

