From 1a0a5e16f303d6450b1a9762a5e3298a124489c9 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 8 Dec 2017 11:55:40 -0400 Subject: Add backspace and shift-arrows to telchars --- util/telchars.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'util/telchars.js') diff --git a/util/telchars.js b/util/telchars.js index 8cf414c..7f4d8e4 100644 --- a/util/telchars.js +++ b/util/telchars.js @@ -1,10 +1,15 @@ // Useful telnet key detection. +const compareBufStr = (buf, str) => { + return buf.equals(Buffer.from(str.split('').map(c => c.charCodeAt(0)))) +} + const telchars = { isSpace: buf => buf[0] === 0x20, isEnter: buf => buf[0] === 0x0d && buf[1] === 0x00, isTab: buf => buf[0] === 0x09, isBackTab: buf => buf[0] === 0x1b && buf[2] === 0x5A, + isBackspace: buf => buf[0] === 0x7F, // isEscape is hard because it's just send as ESC (the ANSI escape code), // so we need to make sure that the escape code is all on its own @@ -25,6 +30,11 @@ const telchars = { isDown: buf => buf[0] === 0x1b && buf[2] === 0x42, isRight: buf => buf[0] === 0x1b && buf[2] === 0x43, isLeft: buf => buf[0] === 0x1b && buf[2] === 0x44, + + isShiftUp: buf => buf[0] === 0x1b && compareBufStr(buf.slice(1), '[1;2A'), + isShiftDown: buf => buf[0] === 0x1b && compareBufStr(buf.slice(1), '[1;2B'), + isShiftRight: buf => buf[0] === 0x1b && compareBufStr(buf.slice(1), '[1;2C'), + isShiftLeft: buf => buf[0] === 0x1b && compareBufStr(buf.slice(1), '[1;2D'), } module.exports = telchars -- cgit 1.3.0-6-gf8a5