From 769413468e88acba1a180baa0113139d929a3b9f Mon Sep 17 00:00:00 2001 From: liam4 Date: Mon, 3 Jul 2017 18:59:57 -0300 Subject: A long-due cleanup + examples + things ..Obviously this breaks old things (particularly, see changes in FocusElement). --- util/telchars.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 util/telchars.js (limited to 'util/telchars.js') diff --git a/util/telchars.js b/util/telchars.js new file mode 100644 index 0000000..8cf414c --- /dev/null +++ b/util/telchars.js @@ -0,0 +1,30 @@ +// Useful telnet key detection. + +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, + + // 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 + // (i.e. the length is 1) + isEscape: buf => buf[0] === 0x1b && buf.length === 1, + + // Use this for when you'd like to detect the user confirming or issuing a + // command, like the X button on your PlayStation controller, or the mouse + // when you click on a button. + isSelect: buf => telchars.isSpace(buf) || telchars.isEnter(buf), + + // Use this for when you'd like to detect the user cancelling an action, + // like the O button on your PlayStation controller, or the Escape key on + // your keyboard. + isCancel: buf => telchars.isEscape(buf), + + isUp: buf => buf[0] === 0x1b && buf[2] === 0x41, + isDown: buf => buf[0] === 0x1b && buf[2] === 0x42, + isRight: buf => buf[0] === 0x1b && buf[2] === 0x43, + isLeft: buf => buf[0] === 0x1b && buf[2] === 0x44, +} + +module.exports = telchars -- cgit 1.3.0-6-gf8a5