microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.43k stars 232 forks source link

ANSI escape doesn't work #550

Closed MassMessage closed 1 year ago

MassMessage commented 2 years ago

Environment details

Issue description

i'm trying to use ANSI escapes like "\x1B[31mTexting\x1b[0m\t\t" to print a green text in the powershell terminal but it isn't working; it just print the text in the default color. What am I missing? i'm doing something like this:

var os = require('os');
var pty = require('node-pty');

var shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';

var ptyProcess = pty.spawn(shell, [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: process.env
});
ptyProcess.write("\x1B[31mTexting\x1b[0m\t\t");
Tyriar commented 1 year ago

There you're creating a powershell instance and writing that text to it. You would want to do something like ptyProcess.write('Write-Host "e[31mTextinge[0m\n"'); to write it in powershell.

I suspect what you're actually after is to create xterm.js and write the sequence to that.