public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: console: Retain ENABLE_VIRTUAL_TERMIANL_PROCESSING flag.
@ 2022-06-15  4:36 Takashi Yano
  0 siblings, 0 replies; only message in thread
From: Takashi Yano @ 2022-06-15  4:36 UTC (permalink / raw)
  To: cygwin-patches

- Currently, ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is disabled
  unconditionally when exiting from cygwin. This causes ANSI escape
  sequence disabled in Windows Terminal where it is enables by
  default. This patch retains that flag if it is originally enabled.
---
 winsup/cygwin/fhandler.h          | 1 +
 winsup/cygwin/fhandler_console.cc | 4 ++++
 2 files changed, 5 insertions(+)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index dfad07f72..d7c358e7f 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2022,6 +2022,7 @@ class dev_console
 {
   pid_t owner;
   bool is_legacy;
+  bool orig_virtual_terminal_processing_mode;
 
   WORD default_color, underline_color, dim_color;
 
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 52239c2f9..12c2c4f12 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -597,6 +597,8 @@ fhandler_console::set_output_mode (tty::cons_mode m, const termios *t,
 				   const handle_set_t *p)
 {
   DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
+  if (con.orig_virtual_terminal_processing_mode)
+    flags |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
   WaitForSingleObject (p->output_mutex, mutex_timeout);
   switch (m)
     {
@@ -1505,6 +1507,8 @@ fhandler_console::open (int flags, mode_t)
       /* Check xterm compatible mode in output */
       acquire_attach_mutex (mutex_timeout);
       GetConsoleMode (get_output_handle (), &dwMode);
+      con.orig_virtual_terminal_processing_mode =
+	!!(dwMode & ENABLE_VIRTUAL_TERMINAL_PROCESSING);
       if (!SetConsoleMode (get_output_handle (),
 			   dwMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
 	is_legacy = true;
-- 
2.36.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-15  4:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-15  4:36 [PATCH] Cygwin: console: Retain ENABLE_VIRTUAL_TERMIANL_PROCESSING flag Takashi Yano

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