microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.42k stars 233 forks source link

modernize example code #621

Closed SimonSiefke closed 11 months ago

SimonSiefke commented 11 months ago

Issue description

I quite like the example code in the readme. Nevertheless it might be a good idea to modernize some parts of the code to make it even easier to integrate node-pty into modern applications using "type": "module" or applications using typescript.

Proposed Changes

import * as os from 'node:os';
import * as pty from 'node-pty';

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

const ptyProcess = pty.spawn(shell, [], {
  name: 'xterm-color',
  cols: 80,
  rows: 30,
  cwd: process.env.HOME,
  env: process.env
});

ptyProcess.onData((data) => {
  process.stdout.write(data);
});

ptyProcess.write('ls\r');
ptyProcess.resize(100, 40);
ptyProcess.write('ls\r');
Tyriar commented 11 months ago

@SimonSiefke sounds good to me 👍, want to make a PR for this?

SimonSiefke commented 11 months ago

Sure, here it is: https://github.com/microsoft/node-pty/issues/622 :)