Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1bc941a
add support for .on('exit', function (code, signal) {})
joshwilsdon Feb 21, 2015
568d186
use an arg instead of arguments[0]
joshwilsdon Feb 22, 2015
aa2fbee
htop command cannot resize with env.LINSE and env.COLUMNS
vangie Apr 6, 2015
dbfb57a
v0.2.8. fixes #122.
chjj Jul 5, 2015
b15642e
Merge pull request #110 from joshwilsdon/exitStatus
chjj Jul 30, 2015
d497a37
style conventions.
chjj Jul 30, 2015
647bcae
fix build. see #110.
chjj Jul 30, 2015
b4e213f
call uv_close to take cb off the event loop. see #110.
chjj Jul 30, 2015
8d1b6b8
more style fixes.
chjj Jul 30, 2015
efa3bea
use older v8 api for function casts?
chjj Jul 30, 2015
b242815
fix after_wait_on_pid for node v0.10.x. see #110.
chjj Jul 31, 2015
c1ffc0e
fix close events. see #110.
chjj Jul 31, 2015
457a970
v0.2.9
chjj Jul 31, 2015
3e6b21d
refactor waitpid thread.
chjj Aug 1, 2015
feac246
refactor pty.fork args.
chjj Aug 1, 2015
a92a38e
free up baton in uv_close callback. see #110.
chjj Aug 1, 2015
4af6285
fix issue where exit is emitted before the last data event. see #110.
chjj Aug 1, 2015
5746a30
account for node v0.8.x on waitpid. see #110.
chjj Aug 2, 2015
58378aa
v0.2.10
chjj Aug 2, 2015
b587bc6
Merge pull request #117 from vangie/fix_htop_incorrect_resize
chjj Aug 2, 2015
87c3584
add comment.
chjj Aug 2, 2015
b8c5fa2
v0.2.11
chjj Aug 2, 2015
b4d9445
better onexit callback.
chjj Aug 2, 2015
d2fcdb6
event better onexit callback. see #110.
chjj Aug 4, 2015
cd58363
v0.2.12
chjj Aug 4, 2015
e477660
create scope in pty_after_waitpid to prevent fatal v8 error in io.js.…
chjj Aug 5, 2015
a2c2f7a
v0.2.13
chjj Aug 5, 2015
91fb97f
upgrade to nan 2.0.5. see #127.
chjj Aug 24, 2015
1dae5e3
remove "heap-style" Nan::Callback.
chjj Aug 24, 2015
311ca65
strict nan version.
chjj Aug 24, 2015
79d8b93
remove useless v8 namespace prefixes.
chjj Aug 24, 2015
847f650
minor: whitespace. cols.
chjj Aug 24, 2015
61cea83
bind to close only once.
chjj Aug 24, 2015
70f0799
v0.3.0
chjj Aug 24, 2015
c3499f0
update win/pty.cc to work with nan 2.0.5
nightwing Mar 8, 2015
7700f31
Merge pull request #128 from cloud9ide/nan-2
chjj Sep 10, 2015
ef6aa14
Optional resuming of the socket
apoco Jan 18, 2016
7d05463
Merge pull request #145 from apoco/paused-socket
chjj Jan 18, 2016
effa94d
Merge commit '7d05463a0da1c82cf138548d80b8e7f086d9bd72' into node_431
Feb 18, 2016
ab3eec2
Update nan version
Feb 18, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Makefile.gyp
*.filters
*.user
*.project
test.js
.idea
test.js
61 changes: 47 additions & 14 deletions lib/pty.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*/

var extend = require('extend');
var EventEmitter = require('events').EventEmitter;
var pty = require('../build/Release/pty.node');
var net = require('net');
var tty = require('tty');
var nextTick = global.setImmediate || process.nextTick;

var version = process.versions.node.split('.').map(function(n) {
return +(n + '').split('-')[0];
Expand Down Expand Up @@ -37,6 +39,8 @@ function Terminal(file, args, opt) {
, name
, cols
, rows
, uid
, gid
, term;

// backward compatibility
Expand All @@ -50,6 +54,9 @@ function Terminal(file, args, opt) {
args = [];
}

// for 'close'
this._internalee = new EventEmitter;

// arguments
args = args || [];
file = file || 'sh';
Expand All @@ -58,6 +65,9 @@ function Terminal(file, args, opt) {
cols = opt.cols || 80;
rows = opt.rows || 24;

uid = opt.uid != null ? opt.uid : -1;
gid = opt.gid != null ? opt.gid : -1;

opt.env = opt.env || process.env;
env = extend({}, opt.env);

Expand Down Expand Up @@ -88,19 +98,35 @@ function Terminal(file, args, opt) {
cwd = opt.cwd || process.cwd();
name = opt.name || env.TERM || 'xterm';
env.TERM = name;
env.LINES = rows + '';
env.COLUMNS = cols + '';
// XXX Shouldn't be necessary:
// env.LINES = rows + '';
// env.COLUMNS = cols + '';

env = environ(env);

function onexit(code, signal) {
// XXX Sometimes a data event is emitted
// after exit. Wait til socket is destroyed.
if (!self._emittedClose) {
if (self._boundClose) return;
self._boundClose = true;
self.once('close', function() {
self.emit('exit', code, signal);
});
return;
}
self.emit('exit', code, signal);
}

// fork
term = opt.uid && opt.gid
? pty.fork(file, args, env, cwd, cols, rows, opt.uid, opt.gid)
: pty.fork(file, args, env, cwd, cols, rows);
term = pty.fork(file, args, env, cwd, cols, rows, uid, gid, onexit);

this.socket = TTYStream(term.fd);
this.socket.setEncoding('utf8');
this.socket.resume();

if (opt.resume !== false) {
this.socket.resume();
}

// setup
this.socket.on('error', function(err) {
Expand All @@ -112,10 +138,10 @@ function Terminal(file, args, opt) {
// close
self._close();
// EIO on exit from fs.ReadStream:
if (!self._emittedExit) {
self._emittedExit = true;
if (!self._emittedClose) {
self._emittedClose = true;
Terminal.total--;
self.emit('exit', null);
self.emit('close');
}

// EIO, happens when someone closes our child
Expand Down Expand Up @@ -146,13 +172,13 @@ function Terminal(file, args, opt) {
this.writable = true;

Terminal.total++;
// XXX This never gets emitted with v0.12.0

this.socket.on('close', function() {
if (self._emittedExit) return;
self._emittedExit = true;
if (self._emittedClose) return;
self._emittedClose = true;
Terminal.total--;
self._close();
self.emit('exit', null);
self.emit('close');
});

env = null;
Expand Down Expand Up @@ -268,11 +294,18 @@ Terminal.prototype.setEncoding = function(enc) {

Terminal.prototype.addListener =
Terminal.prototype.on = function(type, func) {
if (type === 'close') {
this._internalee.on('close', func);
return this;
}
this.socket.on(type, func);
return this;
};

Terminal.prototype.emit = function() {
Terminal.prototype.emit = function(evt) {
if (evt === 'close') {
return this._internalee.emit.apply(this._internalee, arguments);
}
return this.socket.emit.apply(this.socket, arguments);
};

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "pty.js",
"description": "Pseudo terminals for node.",
"author": "Christopher Jeffrey",
"version": "0.2.7-1",
"version": "0.3.0",
"license": "MIT",
"main": "./index.js",
"repository": "git://github.com/chjj/pty.js.git",
"homepage": "https://github.com/chjj/pty.js",
Expand All @@ -24,7 +25,7 @@
],
"dependencies": {
"extend": "~1.2.1",
"nan": "^1.8.4"
"nan": "2.2.0"
},
"devDependencies": {
"mocha": "~1.17.1"
Expand Down
Loading