退格键

This commit is contained in:
bwcx_jzy 2019-08-10 11:22:00 +08:00
parent 1dc6b82739
commit 5fa68fa45b
2 changed files with 22 additions and 0 deletions

View File

@ -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 {

View File

@ -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) {