Skip to content

Commit

Permalink
Update examples to use new events
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Apr 28, 2019
1 parent f277da3 commit 7287e06
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
25 changes: 9 additions & 16 deletions examples/fork/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
var os = require('os');
var pty = require('../..');

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

var ptyProcess = pty.spawn(shell, [], {
name: 'xterm-256color',
cols: 80,
rows: 26,
cwd: os.platform() === 'win32' ? process.env.USERPROFILE : process.env.HOME,
env: Object.assign({ TEST: "abc" }, process.env),
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
env: Object.assign({ TEST: "Environment vars work" }, process.env),
experimentalUseConpty: true
});

ptyProcess.on('data', function(data) {
// console.log(data);
process.stdout.write(data);
});
ptyProcess.onData(data => process.stdout.write(data));

ptyProcess.write('dir\r');
// ptyProcess.write('ls\r');
ptyProcess.write(isWindows ? 'dir\r' : 'ls\r');

setTimeout(() => {
ptyProcess.resize(30, 19);
ptyProcess.write(shell === 'powershell.exe' ? '$Env:TEST\r' : 'echo %TEST%\r');
ptyProcess.write(isWindows ? '$Env:TEST\r' : 'echo $TEST\r');
}, 2000);

process.on('exit', () => {
ptyProcess.kill();
});
process.on('exit', () => ptyProcess.kill());

setTimeout(() => {
process.exit();
}, 4000);
setTimeout(() => process.exit(), 4000);
4 changes: 1 addition & 3 deletions examples/killDeepTree/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ var ptyProcess = pty.spawn(shell, [], {
env: process.env
});

ptyProcess.on('data', function(data) {
process.stdout.write(data);
});
ptyProcess.onData((data) => process.stdout.write(data));

ptyProcess.write('start notepad\r');
ptyProcess.write('npm start\r');
Expand Down

0 comments on commit 7287e06

Please sign in to comment.