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 badges1 Answer
Reset to default 4In 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