Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize example code #621

Closed
SimonSiefke opened this issue Jul 27, 2023 · 2 comments · Fixed by #622
Closed

modernize example code #621

SimonSiefke opened this issue Jul 27, 2023 · 2 comments · Fixed by #622
Milestone

Comments

@SimonSiefke
Copy link
Contributor

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

  • using import instead of require
  • using const instead of var
  • (optional) using 'node:os' import instead of os
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
Copy link
Member

Tyriar commented Jul 27, 2023

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

@SimonSiefke
Copy link
Contributor Author

SimonSiefke commented Jul 27, 2023

Sure, here it is: #622 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants