Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save piscisaureus/788962 to your computer and use it in GitHub Desktop.

Select an option

Save piscisaureus/788962 to your computer and use it in GitHub Desktop.
From b9a6525b5dc7243c30c83da377bfd0360aab4a6e Mon Sep 17 00:00:00 2001
From: Bert Belder <bertbelder@gmail.com>
Date: Fri, 21 Jan 2011 00:47:55 +0100
Subject: [PATCH 1/1] Fix meta+character keys on mac
---
lib/tty_posix.js | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/lib/tty_posix.js b/lib/tty_posix.js
index dd37e31..8ffe9b3 100644
--- a/lib/tty_posix.js
+++ b/lib/tty_posix.js
@@ -66,6 +66,7 @@ ReadStream.prototype.isTTY = true;
Some patterns seen in terminal key escape codes, derived from combos seen
at http://www.midnight-commander.org/browser/lib/tty/key.c
+ ESC letter
ESC [ letter
ESC [ modifier letter
ESC [ 1 ; modifier letter
@@ -89,9 +90,10 @@ ReadStream.prototype.isTTY = true;
- two leading ESCs apparently mean the same as one leading ESC
*/
-// Regex used for ansi escape code splitting
-var splitKeyCodeRe =
- /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;(\d+))?([a-zA-Z]))/;
+// Regexes used for ansi escape code splitting
+var metaKeyCodeRe = /^(?:\x1b)([a-zA-Z0-9])$/,
+ functionKeyCodeRe =
+ /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;(\d+))?([a-zA-Z]))/;
ReadStream.prototype._emitKey = function(s) {
var char,
@@ -140,7 +142,13 @@ ReadStream.prototype._emitKey = function(s) {
key.name = s.toLowerCase();
key.shift = true;
- } else if (parts = splitKeyCodeRe.exec(s)) {
+ } else if (parts = metaKeyCodeRe.exec(s)) {
+ // meta+character key
+ key.name = parts[1].toLowerCase();
+ key.meta = true;
+ key.shift = /^[A-Z]$/.test(parts[1]);
+
+ } else if (parts = functionKeyCodeRe.exec(s)) {
// ansi escape sequence
// reassemble the key code leaving out leading \x1b's,
--
1.7.3.1.msysgit.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment