Xterm.js: Can't clear the terminal programmatically

Created on 6 Sep 2017  ·  4Comments  ·  Source: xtermjs/xterm.js

Running node -e "process.stdout.write ( '\u001Bc' );" should clear the terminal, but this is what I get if I run it in xterm:

screen shot 2017-09-06 at 23 16 44

If I try to clear it with a node -e "process.stdout.write ( '\033[2J\033[0f' );" the whole thing becomes black.

Is there a way it can be cleared properly?

typquestion

All 4 comments

Using node -e "process.stdout.write ( '\u001Bc' );" or echo -e '\x1bc' tell bash to clear, and bash gives back a response to xterm.js. I believe this is why you're seeing the prompt again. You can call term.write('\x1bc') to clear only the front end (xterm.js).

What if I don't have access to the xterm instance?

I basically want to clear the terminal when my CLI app starts, how am I supposed to do that if it gets launched from xterm?

@fabiospampinato it looks like clear command on Linux sends '\x1b[H\x1b[2J'

That translates into:

  • Move cursor to (1,1) (CUP)
  • Erase all in display (ED)

See http://invisible-island.net/xterm/ctlseqs/ctlseqs.html for more info

That works, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Tyriar picture Tyriar  ·  4Comments

tandatle picture tandatle  ·  3Comments

ghost picture ghost  ·  4Comments

jerch picture jerch  ·  3Comments

goxr3plus picture goxr3plus  ·  3Comments