public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: console: Make cursor keys work in vim under ConEmu.
Date: Sat, 30 May 2020 17:41:56 +0000 (GMT)	[thread overview]
Message-ID: <20200530174156.89F6D3858D35@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=0c5aab9c99cf150bc90374c7fb72931e56dc955f

commit 0c5aab9c99cf150bc90374c7fb72931e56dc955f
Author: Takashi Yano via Cygwin-patches <cygwin-patches@cygwin.com>
Date:   Sat May 30 18:25:03 2020 +0900

    Cygwin: console: Make cursor keys work in vim under ConEmu.
    
    - After commit 774b8996d1f3e535e8267be4eb8e751d756c2cec, cursor
      keys do not work in vim under ConEmu without cygwin-connector.
      This patch fixes the issue.

Diff:
---
 winsup/cygwin/fhandler.h          |  1 +
 winsup/cygwin/fhandler_console.cc | 20 ++++++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 76ad2aab0..b2957e4ee 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -2040,6 +2040,7 @@ class dev_console
   char *cons_rapoi;
   LONG xterm_mode_input;
   LONG xterm_mode_output;
+  bool cursor_key_app_mode;
 
   inline UINT get_console_cp ();
   DWORD con_to_str (char *d, int dlen, WCHAR w);
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 3930c6068..5cb4343ea 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -243,6 +243,7 @@ fhandler_console::setup ()
       con.backspace_keycode = CERASE;
       con.cons_rapoi = NULL;
       shared_console_info->tty_min_state.is_console = true;
+      con.cursor_key_app_mode = false;
     }
 }
 
@@ -289,6 +290,8 @@ fhandler_console::request_xterm_mode_input (bool req)
 	  GetConsoleMode (get_handle (), &dwMode);
 	  dwMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;
 	  SetConsoleMode (get_handle (), dwMode);
+	  if (con.cursor_key_app_mode) /* Restore DECCKM */
+	    WriteConsoleA (get_output_handle (), "\033[?1h", 5, NULL, 0);
 	}
     }
   else
@@ -2150,10 +2153,6 @@ fhandler_console::char_command (char c)
 	  break;
 	case 'h': /* DECSET */
 	case 'l': /* DECRST */
-	  if (c == 'h')
-	    con.screen_alternated = true;
-	  else
-	    con.screen_alternated = false;
 	  wpbuf.put (c);
 	  /* Just send the sequence */
 	  wpbuf.send (get_output_handle ());
@@ -2161,8 +2160,15 @@ fhandler_console::char_command (char c)
 	    {
 	      bool need_fix_tab_position = false;
 	      for (int i = 0; i < con.nargs; i++)
-		if (con.args[i] == 1049)
-		  need_fix_tab_position = true;
+		{
+		  if (con.args[i] == 1049)
+		    {
+		      con.screen_alternated = (c == 'h');
+		      need_fix_tab_position = true;
+		    }
+		  if (con.args[i] == 1) /* DECCKM */
+		    con.cursor_key_app_mode = (c == 'h');
+		}
 	      /* Call fix_tab_position() if screen has been alternated. */
 	      if (need_fix_tab_position)
 		fix_tab_position ();
@@ -2174,6 +2180,7 @@ fhandler_console::char_command (char c)
 	      con.scroll_region.Top = 0;
 	      con.scroll_region.Bottom = -1;
 	      con.savex = con.savey = -1;
+	      con.cursor_key_app_mode = false;
 	    }
 	  wpbuf.put (c);
 	  /* Just send the sequence */
@@ -3077,6 +3084,7 @@ fhandler_console::write (const void *vsrc, size_t len)
 		  con.scroll_region.Top = 0;
 		  con.scroll_region.Bottom = -1;
 		  con.savex = con.savey = -1;
+		  con.cursor_key_app_mode = false;
 		}
 	      /* ESC sequences below (e.g. OSC, etc) are left to xterm
 		 emulation in xterm compatible mode, therefore, are not


                 reply	other threads:[~2020-05-30 17:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20200530174156.89F6D3858D35@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /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).