From 5fa68fa45b956fb7aa0705c865056261445d3cee Mon Sep 17 00:00:00 2001 From: bwcx_jzy Date: Sat, 10 Aug 2019 11:22:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E6=A0=BC=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../keepbx/jpom/socket/handler/SshHandler.java | 5 +++++ .../resources/templates/node/ssh/terminal.html | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/modules/server/src/main/java/cn/keepbx/jpom/socket/handler/SshHandler.java b/modules/server/src/main/java/cn/keepbx/jpom/socket/handler/SshHandler.java index 32b460da4..28d78bd2e 100644 --- a/modules/server/src/main/java/cn/keepbx/jpom/socket/handler/SshHandler.java +++ b/modules/server/src/main/java/cn/keepbx/jpom/socket/handler/SshHandler.java @@ -201,6 +201,11 @@ public class SshHandler extends BaseHandler { } private static void sendBinary(WebSocketSession session, String msg) { + // 判断退格键 + char[] chars = msg.toCharArray(); + if (chars.length == 1 && chars[0] == 127) { + return; + } synchronized (session.getId()) { BinaryMessage byteBuffer = new BinaryMessage(msg.getBytes()); try { diff --git a/modules/server/src/main/resources/templates/node/ssh/terminal.html b/modules/server/src/main/resources/templates/node/ssh/terminal.html index b9eacd28b..3144fef9e 100644 --- a/modules/server/src/main/resources/templates/node/ssh/terminal.html +++ b/modules/server/src/main/resources/templates/node/ssh/terminal.html @@ -40,10 +40,27 @@ term.onData(function (data) { sock.send(JSON.stringify({'data': data})); }); + + // 监听按键 + var startX = 2; + term.onKey(function (key) { + var ev = key.domEvent; + // const printable = !ev.altKey && !ev.altGraphKey && !ev.ctrlKey && !ev.metaKey; + if (ev.keyCode === 8) { + // Do not delete the prompt + if (term._core.buffer.x > startX) { + term.write('\b \b'); + } + } + }); // sock.onopen = function () { term.open(terminal, true); top.layer.closeAll(); + setTimeout(function () { + startX = term._core.buffer.x; + // console.log(); + }, 2000); }; sock.onmessage = function (msg) {