diff options
author | Florrie <towerofnix@gmail.com> | 2017-12-08 11:55:40 -0400 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2017-12-08 11:55:40 -0400 |
commit | 1a0a5e16f303d6450b1a9762a5e3298a124489c9 (patch) | |
tree | 9dbcc30d86c71e81eacde1327e23b47f6ae30509 | |
parent | 12f5eb1f7b6c02972ad23e698a418210ed743632 (diff) |
Add backspace and shift-arrows to telchars
-rw-r--r-- | util/telchars.js | 10 |
1 files changed, 10 insertions, 0 deletions
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 |