From cc2ee9c586607e3fbcd3e0d51a24624b21eea3dc Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 31 Jan 2018 22:42:43 -0700 Subject: [PATCH] Add ESC support - WIP, not fully functional --- core/telnet_bridge.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/telnet_bridge.js b/core/telnet_bridge.js index 447efe4c..95ace6c6 100644 --- a/core/telnet_bridge.js +++ b/core/telnet_bridge.js @@ -158,7 +158,17 @@ exports.getModule = class TelnetBridgeModule extends MenuModule { const telnetConnection = new TelnetClientConnection(self.client); + const connectionKeyPressHandler = (ch, key) => { + if('escape' === key.name) { + self.client.removeListener('key press', connectionKeyPressHandler); + telnetConnection.disconnect(); + } + }; + + self.client.on('key press', connectionKeyPressHandler); + telnetConnection.on('connected', () => { + self.client.removeListener('key press', connectionKeyPressHandler); self.client.log.info(connectOpts, 'Telnet bridge connection established'); if(self.config.font) { @@ -173,6 +183,8 @@ exports.getModule = class TelnetBridgeModule extends MenuModule { }); telnetConnection.on('end', err => { + self.client.removeListener('key press', connectionKeyPressHandler); + if(err) { self.client.log.info(`Telnet bridge connection error: ${err.message}`); }