Wolverine Wolverine - 1 month ago 14
Node.js Question

How do you set the terminal tab title from Node.js?

I'm aware that this can be done manually from the terminal using:

echo -n -e "\033]0;My terminal tab title\007"


I tried putting this into a
console.log
and
process.stdout.write
and fiddling with the escaping, but I can't get it to work.

Answer

To save anyone reading this a bit of time, here is a function that will do it in strict mode:

function setTerminalTitle(title)
{
  process.stdout.write(
    String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7)
  );
}