From 49275524a5d33acc16eb440173f94f92d28b6352 Mon Sep 17 00:00:00 2001 From: isaacs Date: Fri, 21 Jan 2011 10:08:48 -0800 Subject: [PATCH] Fix for meta keys in a weird iTerm state. --- lib/tty_posix.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/tty_posix.js b/lib/tty_posix.js index a0a896d064..309f9f70bf 100644 --- a/lib/tty_posix.js +++ b/lib/tty_posix.js @@ -93,7 +93,7 @@ ReadStream.prototype.isTTY = true; // 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]))/; + /^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/; ReadStream.prototype._emitKey = function(s) { var char, @@ -106,7 +106,12 @@ ReadStream.prototype._emitKey = function(s) { parts; if (Buffer.isBuffer(s)) { - s = s.toString(this.encoding || 'utf-8'); + if (s[0] > 127 && s[1] === undefined) { + s[0] -= 128; + s = '\x1b'+s.toString(this.encoding || 'utf-8'); + } else { + s = s.toString(this.encoding || 'utf-8'); + } } if (s === '\r') {