5

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!

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Assam
  • 179
  • 1
  • 13

1 Answers1

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

shreyasm-dev
  • 2,711
  • 5
  • 16
  • 34
thaGH05T
  • 120
  • 1
  • 9
  • When I get farther I will update my post. If you get any farther please also post a solution. – thaGH05T Sep 19 '19 at 01:38
  • 4
    Maybe we could reference this [sample](https://www.linkedin.com/pulse/xtermjs-local-echo-ioannis-charalampidis) – Assam Sep 19 '19 at 08:19
  • Actually @Assam that isn't a bad looking code base. I was actually wring something like this as well for my app. Instead f continuing on with what I have, I may try to implement this and offer some guidance. What's your stack look like? I am using Angular8. – thaGH05T Sep 20 '19 at 13:23
  • 1
    Why the don't implement it natively ? – GOXR3PLUS Nov 14 '19 at 12:07