最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to implement 'BackSpace', 'arrow' in Xterm.js? - Stack Overflow

programmeradmin3浏览0评论

I'm designing a web which include a terminal using Xterm.js and would like transfer the string to the server. 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.

e.g. 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!

I'm designing a web which include a terminal using Xterm.js and would like transfer the string to the server. 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.

e.g. 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!

Share edited Dec 14, 2020 at 23:23 Thomas Dickey 54.8k8 gold badges78 silver badges108 bronze badges asked Sep 6, 2019 at 9:00 AssamAssam 3072 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

In short, yes. You have to manipulate the buffer yourself, there are no methods to do this for you.

TL;DR

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

发布评论

评论列表(0)

  1. 暂无评论