简体   繁体   English

如何在 Xterm.js 中实现“BackSpace”、“箭头”?

[英]How to implement 'BackSpace', 'arrow' in Xterm.js?

I'm designing a web which include a terminal using Xterm.js and would like transfer the string to the server.我正在设计一个包含使用 Xterm.js 的终端的网络,并希望将字符串传输到服务器。 I can type some string on it but can't use 'backspace', 'delete', 'home' functions.我可以在上面输入一些字符串,但不能使用“退格”、“删除”、“主页”功能。

I tried to do that functions by myself, but there are a lot function need to do.我试图自己做这些功能,但有很多功能需要做。

eg Backspace例如退格

term.on('key', (key, ev) => {
    const code = key.charCodeAt(0);
    if(code == 127){   //Backspace
        term.write("\b \b");
    }
});

I could delete the last character, but can't delete inside the string... Are these functions to be done by myself?我可以删除最后一个字符,但不能删除字符串内部......这些功能是自己完成的吗? Is there a more convenient module?有没有更方便的模块?

Thanks!谢谢!

In short, yes.简而言之,是的。 You have to manipulate the buffer yourself, there are no methods to do this for you.您必须自己操作缓冲区,没有任何方法可以为您执行此操作。

TL;DR TL; 博士

I am running into the same issue actually.我实际上遇到了同样的问题。 It appears all of this is buffer driven and I haven't quite figured out how to do this in a natural way yet, but...看起来所有这些都是缓冲区驱动的,我还没有完全弄清楚如何以自然的方式做到这一点,但是......

To simulate a left arrow:模拟左箭头:

this.child.write('\x1b[D');

You can also add any unicode character by hex: \\uhhhh您还可以通过十六进制添加任何 unicode 字符:\\uhhhh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM