Comparing version 0.6.1 to 0.6.2-beta1
@@ -1,5 +0,1 @@ | ||
/** | ||
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License) | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
@@ -6,0 +2,0 @@ var os = require("os"); |
@@ -1,5 +0,2 @@ | ||
/** | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
//# sourceMappingURL=interfaces.js.map |
@@ -1,5 +0,1 @@ | ||
/** | ||
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License) | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
@@ -9,23 +5,16 @@ var events_1 = require("events"); | ||
function Terminal() { | ||
// for 'close' | ||
this._internalee = new events_1.EventEmitter(); | ||
} | ||
/** See net.Socket.end */ | ||
Terminal.prototype.end = function (data) { | ||
this.socket.end(data); | ||
}; | ||
/** See stream.Readable.pipe */ | ||
Terminal.prototype.pipe = function (dest, options) { | ||
return this.socket.pipe(dest, options); | ||
}; | ||
/** See net.Socket.pause */ | ||
Terminal.prototype.pause = function () { | ||
return this.socket.pause(); | ||
}; | ||
/** See net.Socket.resume */ | ||
Terminal.prototype.resume = function () { | ||
// TODO: Type with Socket | ||
return this.socket.resume(); | ||
}; | ||
/** See net.Socket.setEncoding */ | ||
Terminal.prototype.setEncoding = function (encoding) { | ||
@@ -69,3 +58,2 @@ if (this.socket._decoder) { | ||
}; | ||
// TODO: Should this be in the API? | ||
Terminal.prototype.redraw = function () { | ||
@@ -75,4 +63,2 @@ var _this = this; | ||
var rows = this.rows; | ||
// We could just send SIGWINCH, but most programs will ignore it if the | ||
// size hasn't actually changed. | ||
this.resize(cols + 1, rows + 1); | ||
@@ -79,0 +65,0 @@ setTimeout(function () { return _this.resize(cols, rows); }, 30); |
@@ -1,5 +0,1 @@ | ||
/** | ||
* Copyright (c) 2012-2015, Christopher Jeffrey (MIT License) | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
@@ -11,14 +7,9 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}; | ||
var extend = require("extend"); | ||
var net = require("net"); | ||
var path = require("path"); | ||
var terminal_1 = require("./terminal"); | ||
var pty; | ||
try { | ||
pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
} | ||
catch (e) { | ||
pty = require(path.join('..', 'build', 'Debug', 'pty.node')); | ||
} | ||
; | ||
var utils_1 = require("./utils"); | ||
var pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
var DEFAULT_FILE = 'sh'; | ||
var DEFAULT_NAME = 'xterm'; | ||
var UnixTerminal = (function (_super) { | ||
@@ -28,5 +19,4 @@ __extends(UnixTerminal, _super); | ||
var _this = _super.call(this) || this; | ||
// Initialize arguments | ||
args = args || []; | ||
file = file || 'sh'; | ||
file = file || DEFAULT_FILE; | ||
opt = opt || {}; | ||
@@ -36,5 +26,5 @@ opt.env = opt.env || process.env; | ||
var rows = opt.rows || terminal_1.Terminal.DEFAULT_ROWS; | ||
var uid = opt.uid != null ? opt.uid : -1; | ||
var gid = opt.gid != null ? opt.gid : -1; | ||
var env = extend({}, opt.env); | ||
var uid = opt.uid || -1; | ||
var gid = opt.gid || -1; | ||
var env = utils_1.assign({}, opt.env); | ||
if (opt.env === process.env) { | ||
@@ -44,8 +34,6 @@ _this._sanitizeEnv(env); | ||
var cwd = opt.cwd || process.cwd(); | ||
var name = opt.name || env.TERM || 'xterm'; | ||
var name = opt.name || env.TERM || DEFAULT_NAME; | ||
env.TERM = name; | ||
var parsedEnv = _this._parseEnv(env); | ||
var onexit = function (code, signal) { | ||
// XXX Sometimes a data event is emitted after exit. Wait til socket is | ||
// destroyed. | ||
if (!_this._emittedClose) { | ||
@@ -60,3 +48,2 @@ if (_this._boundClose) | ||
}; | ||
// fork | ||
var term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, onexit); | ||
@@ -66,5 +53,3 @@ _this.socket = new PipeSocket(term.fd); | ||
_this.socket.resume(); | ||
// setup | ||
_this.socket.on('error', function (err) { | ||
// NOTE: fs.ReadStream gets EAGAIN twice at first: | ||
if (err.code) { | ||
@@ -75,5 +60,3 @@ if (~err.code.indexOf('EAGAIN')) { | ||
} | ||
// close | ||
_this._close(); | ||
// EIO on exit from fs.ReadStream: | ||
if (!_this._emittedClose) { | ||
@@ -83,6 +66,2 @@ _this._emittedClose = true; | ||
} | ||
// EIO, happens when someone closes our child process: the only process in | ||
// the terminal. | ||
// node < 0.6.14: errno 5 | ||
// node >= 0.6.14: read EIO | ||
if (err.code) { | ||
@@ -93,3 +72,2 @@ if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) { | ||
} | ||
// throw anything else | ||
if (_this.listeners('error').length < 2) { | ||
@@ -116,5 +94,2 @@ throw err; | ||
} | ||
/** | ||
* openpty | ||
*/ | ||
UnixTerminal.open = function (opt) { | ||
@@ -131,3 +106,2 @@ var self = Object.create(UnixTerminal.prototype); | ||
var rows = opt.rows || terminal_1.Terminal.DEFAULT_ROWS; | ||
// open | ||
var term = pty.open(cols, rows); | ||
@@ -166,4 +140,2 @@ self.master = new PipeSocket(term.master); | ||
this._close(); | ||
// Need to close the read stream so node stops reading a dead file | ||
// descriptor. Then we can safely SIGHUP the shell. | ||
this.socket.once('close', function () { | ||
@@ -181,5 +153,2 @@ _this.kill('SIGHUP'); | ||
Object.defineProperty(UnixTerminal.prototype, "process", { | ||
/** | ||
* Gets the name of the process. | ||
*/ | ||
get: function () { | ||
@@ -191,5 +160,2 @@ return pty.process(this.fd, this.pty) || this.file; | ||
}); | ||
/** | ||
* TTY | ||
*/ | ||
UnixTerminal.prototype.resize = function (cols, rows) { | ||
@@ -199,10 +165,6 @@ pty.resize(this.fd, cols, rows); | ||
UnixTerminal.prototype._sanitizeEnv = function (env) { | ||
// Make sure we didn't start our server from inside tmux. | ||
delete env['TMUX']; | ||
delete env['TMUX_PANE']; | ||
// Make sure we didn't start our server from inside screen. | ||
// http://web.mit.edu/gnu/doc/html/screen_20.html | ||
delete env['STY']; | ||
delete env['WINDOW']; | ||
// Delete some variables that might confuse our terminal. | ||
delete env['WINDOWID']; | ||
@@ -216,7 +178,2 @@ delete env['TERMCAP']; | ||
exports.UnixTerminal = UnixTerminal; | ||
/** | ||
* Wraps net.Socket to force the handle type "PIPE" by temporarily overwriting | ||
* tty_wrap.guessHandleType. | ||
* See: https://github.com/chjj/pty.js/issues/103 | ||
*/ | ||
var PipeSocket = (function (_super) { | ||
@@ -223,0 +180,0 @@ __extends(PipeSocket, _super); |
@@ -1,47 +0,19 @@ | ||
/** | ||
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License) | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
var net = require("net"); | ||
var path = require("path"); | ||
var pty; | ||
try { | ||
pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
} | ||
catch (e) { | ||
pty = require(path.join('..', 'build', 'Debug', 'pty.node')); | ||
} | ||
; | ||
/** | ||
* Agent. Internal class. | ||
* | ||
* Everytime a new pseudo terminal is created it is contained | ||
* within agent.exe. When this process is started there are two | ||
* available named pipes (control and data socket). | ||
*/ | ||
var pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
var WindowsPtyAgent = (function () { | ||
function WindowsPtyAgent(file, args, env, cwd, cols, rows, debug) { | ||
var _this = this; | ||
// Sanitize input variable. | ||
cwd = path.resolve(cwd); | ||
// Compose command line | ||
var cmdline = [file]; | ||
Array.prototype.push.apply(cmdline, args); | ||
var cmdlineFlat = argvToCommandLine(cmdline); | ||
// Open pty session. | ||
var term = pty.startProcess(file, cmdlineFlat, env, cwd, cols, rows, debug); | ||
// Terminal pid. | ||
this._pid = term.pid; | ||
// Not available on windows. | ||
this._fd = term.fd; | ||
// Generated incremental number that has no real purpose besides using it | ||
// as a terminal id. | ||
this._pty = term.pty; | ||
// Create terminal pipe IPC channel and forward to a local unix socket. | ||
this._outSocket = new net.Socket(); | ||
this._outSocket.setEncoding('utf8'); | ||
this._outSocket.connect(term.conout, function () { | ||
// TODO: Emit event on agent instead of socket? | ||
// Emit ready event. | ||
_this._outSocket.emit('ready_datapipe'); | ||
@@ -52,3 +24,2 @@ }); | ||
this._inSocket.connect(term.conin); | ||
// TODO: Wait for ready event? | ||
} | ||
@@ -84,2 +55,6 @@ Object.defineProperty(WindowsPtyAgent.prototype, "inSocket", { | ||
WindowsPtyAgent.prototype.kill = function () { | ||
this._inSocket.readable = false; | ||
this._inSocket.writable = false; | ||
this._outSocket.readable = false; | ||
this._outSocket.writable = false; | ||
pty.kill(this.pid); | ||
@@ -90,5 +65,2 @@ }; | ||
exports.WindowsPtyAgent = WindowsPtyAgent; | ||
// Convert argc/argv into a Win32 command-line following the escaping convention | ||
// documented on MSDN (e.g. see CommandLineToArgvW documentation). Copied from | ||
// winpty project. | ||
function argvToCommandLine(argv) { | ||
@@ -95,0 +67,0 @@ var result = ''; |
@@ -1,5 +0,1 @@ | ||
/** | ||
* Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License) | ||
* Copyright (c) 2016, Daniel Imms (MIT License). | ||
*/ | ||
"use strict"; | ||
@@ -11,5 +7,7 @@ var __extends = (this && this.__extends) || function (d, b) { | ||
}; | ||
var extend = require("extend"); | ||
var terminal_1 = require("./terminal"); | ||
var windowsPtyAgent_1 = require("./windowsPtyAgent"); | ||
var utils_1 = require("./utils"); | ||
var DEFAULT_FILE = 'cmd.exe'; | ||
var DEFAULT_NAME = 'Windows Shell'; | ||
var WindowsTerminal = (function (_super) { | ||
@@ -19,44 +17,27 @@ __extends(WindowsTerminal, _super); | ||
var _this = _super.call(this) || this; | ||
// Initialize arguments | ||
args = args || []; | ||
file = file || 'cmd.exe'; | ||
file = file || DEFAULT_FILE; | ||
opt = opt || {}; | ||
opt.env = opt.env || process.env; | ||
var env = extend({}, opt.env); | ||
var env = utils_1.assign({}, opt.env); | ||
var cols = opt.cols || terminal_1.Terminal.DEFAULT_COLS; | ||
var rows = opt.rows || terminal_1.Terminal.DEFAULT_ROWS; | ||
var cwd = opt.cwd || process.cwd(); | ||
var name = opt.name || env.TERM || 'Windows Shell'; | ||
var name = opt.name || env.TERM || DEFAULT_NAME; | ||
var parsedEnv = _this._parseEnv(env); | ||
// If the terminal is ready | ||
_this.isReady = false; | ||
// Functions that need to run after `ready` event is emitted. | ||
_this.deferreds = []; | ||
// Create new termal. | ||
_this.agent = new windowsPtyAgent_1.WindowsPtyAgent(file, args, parsedEnv, cwd, cols, rows, false); | ||
_this.socket = _this.agent.outSocket; | ||
// Not available until `ready` event emitted. | ||
_this.pid = _this.agent.pid; | ||
_this.fd = _this.agent.fd; | ||
_this.pty = _this.agent.pty; | ||
// The forked windows terminal is not available until `ready` event is | ||
// emitted. | ||
_this.socket.on('ready_datapipe', function () { | ||
// These events needs to be forwarded. | ||
['connect', 'data', 'end', 'timeout', 'drain'].forEach(function (event) { | ||
_this.socket.on(event, function (data) { | ||
// Wait until the first data event is fired then we can run deferreds. | ||
if (!_this.isReady && event === 'data') { | ||
// Terminal is now ready and we can avoid having to defer method | ||
// calls. | ||
_this.isReady = true; | ||
// Execute all deferred methods | ||
_this.deferreds.forEach(function (fn) { | ||
// NB! In order to ensure that `this` has all its references | ||
// updated any variable that need to be available in `this` before | ||
// the deferred is run has to be declared above this forEach | ||
// statement. | ||
fn.run(); | ||
}); | ||
// Reset | ||
_this.deferreds = []; | ||
@@ -66,12 +47,5 @@ } | ||
}); | ||
// Resume socket. | ||
_this.socket.resume(); | ||
// Shutdown if `error` event is emitted. | ||
_this.socket.on('error', function (err) { | ||
// Close terminal session. | ||
_this._close(); | ||
// EIO, happens when someone closes our child process: the only process | ||
// in the terminal. | ||
// node < 0.6.14: errno 5 | ||
// node >= 0.6.14: read EIO | ||
if (err.code) { | ||
@@ -81,3 +55,2 @@ if (~err.code.indexOf('errno 5') || ~err.code.indexOf('EIO')) | ||
} | ||
// Throw anything else. | ||
if (_this.listeners('error').length < 2) { | ||
@@ -87,3 +60,2 @@ throw err; | ||
}); | ||
// Cleanup after the socket is closed. | ||
_this.socket.on('close', function () { | ||
@@ -100,11 +72,5 @@ _this.emit('exit', null); | ||
} | ||
/** | ||
* openpty | ||
*/ | ||
WindowsTerminal.open = function (options) { | ||
throw new Error('open() not supported on windows, use Fork() instead.'); | ||
}; | ||
/** | ||
* Events | ||
*/ | ||
WindowsTerminal.prototype.write = function (data) { | ||
@@ -116,5 +82,2 @@ var _this = this; | ||
}; | ||
/** | ||
* TTY | ||
*/ | ||
WindowsTerminal.prototype.resize = function (cols, rows) { | ||
@@ -144,7 +107,5 @@ var _this = this; | ||
var _this = this; | ||
// Ensure that this method is only used within Terminal class. | ||
if (!(this instanceof WindowsTerminal)) { | ||
throw new Error('Must be instanceof WindowsTerminal'); | ||
} | ||
// If the terminal is ready, execute. | ||
if (this.isReady) { | ||
@@ -154,3 +115,2 @@ deferredFn.apply(this, null); | ||
} | ||
// Queue until terminal is ready. | ||
this.deferreds.push({ | ||
@@ -161,5 +121,2 @@ run: function () { return deferredFn.apply(_this, null); } | ||
Object.defineProperty(WindowsTerminal.prototype, "process", { | ||
/** | ||
* Gets the name of the process. | ||
*/ | ||
get: function () { return this.name; }, | ||
@@ -166,0 +123,0 @@ enumerable: true, |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.6.1", | ||
"version": "0.6.2-beta1", | ||
"license": "MIT", | ||
@@ -42,4 +42,3 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"extend": "~1.2.1", | ||
"nan": "2.2.1" | ||
"nan": "2.5.0" | ||
}, | ||
@@ -46,0 +45,0 @@ "devDependencies": { |
@@ -9,3 +9,3 @@ # node-pty | ||
- Writing a terminal emulator. | ||
- Writing a terminal emulator (eg. via [xterm.js](https://github.com/sourcelair/xterm.js)). | ||
- Getting certain programs to *think* you're a terminal, such as when you need a program to send you control sequences. | ||
@@ -17,3 +17,3 @@ | ||
``` js | ||
```js | ||
var os = require('os'); | ||
@@ -58,4 +58,3 @@ var pty = require('node-pty'); | ||
> | ||
Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d. | ||
> Internal Windows PowerShell error. Loading managed Windows PowerShell failed with error 8009001d. | ||
@@ -62,0 +61,0 @@ This happens when PowerShell is launched with no `SystemRoot` environment variable present. |
var fs = require('fs'); | ||
var path = require('path'); | ||
var RELEASE_DIR = path.join(__dirname, "../build/Release"); | ||
var BUILD_FILES = [ path.join(RELEASE_DIR, "pty.node"), | ||
path.join(RELEASE_DIR, "winpty-agent.exe"), | ||
path.join(RELEASE_DIR, "winpty.dll") ] | ||
var RELEASE_DIR = path.join(__dirname, '..', 'build', 'Release'); | ||
var BUILD_FILES = [ | ||
path.join(RELEASE_DIR, 'pty.node'), | ||
path.join(RELEASE_DIR, 'winpty-agent.exe'), | ||
path.join(RELEASE_DIR, 'winpty.dll') | ||
]; | ||
@@ -9,0 +11,0 @@ cleanFolderRecursive = function(folder) { |
@@ -28,3 +28,3 @@ /** | ||
protected _internalee: any; | ||
protected _internalee: EventEmitter; | ||
@@ -31,0 +31,0 @@ constructor() { |
@@ -6,3 +6,2 @@ /** | ||
import * as extend from 'extend'; | ||
import * as net from 'net'; | ||
@@ -13,10 +12,9 @@ import * as path from 'path'; | ||
import { ProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces'; | ||
import { assign } from './utils'; | ||
let pty; | ||
try { | ||
pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
} catch (e) { | ||
pty = require(path.join('..', 'build', 'Debug', 'pty.node')); | ||
}; | ||
const pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
const DEFAULT_FILE = 'sh'; | ||
const DEFAULT_NAME = 'xterm'; | ||
export class UnixTerminal extends Terminal { | ||
@@ -43,3 +41,3 @@ protected pid: number; | ||
args = args || []; | ||
file = file || 'sh'; | ||
file = file || DEFAULT_FILE; | ||
opt = opt || {}; | ||
@@ -50,5 +48,5 @@ opt.env = opt.env || process.env; | ||
const rows = opt.rows || Terminal.DEFAULT_ROWS; | ||
const uid = opt.uid != null ? opt.uid : -1; | ||
const gid = opt.gid != null ? opt.gid : -1; | ||
const env = extend({}, opt.env); | ||
const uid = opt.uid || -1; | ||
const gid = opt.gid || -1; | ||
const env = assign({}, opt.env); | ||
@@ -60,3 +58,3 @@ if (opt.env === process.env) { | ||
const cwd = opt.cwd || process.cwd(); | ||
const name = opt.name || env.TERM || 'xterm'; | ||
const name = opt.name || env.TERM || DEFAULT_NAME; | ||
env.TERM = name; | ||
@@ -63,0 +61,0 @@ const parsedEnv = this._parseEnv(env); |
@@ -9,8 +9,3 @@ /** | ||
let pty; | ||
try { | ||
pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
} catch (e) { | ||
pty = require(path.join('..', 'build', 'Debug', 'pty.node')); | ||
}; | ||
const pty = require(path.join('..', 'build', 'Release', 'pty.node')); | ||
@@ -89,2 +84,6 @@ /** | ||
public kill(): void { | ||
this._inSocket.readable = false; | ||
this._inSocket.writable = false; | ||
this._outSocket.readable = false; | ||
this._outSocket.writable = false; | ||
pty.kill(this.pid); | ||
@@ -91,0 +90,0 @@ } |
@@ -8,3 +8,2 @@ /** | ||
import * as path from 'path'; | ||
import * as extend from 'extend'; | ||
import { inherits } from 'util'; | ||
@@ -14,3 +13,7 @@ import { Terminal } from './terminal'; | ||
import { IPtyForkOptions, IPtyOpenOptions } from './interfaces'; | ||
import { assign } from './utils'; | ||
const DEFAULT_FILE = 'cmd.exe'; | ||
const DEFAULT_NAME = 'Windows Shell'; | ||
export class WindowsTerminal extends Terminal { | ||
@@ -26,11 +29,11 @@ private isReady: boolean; | ||
args = args || []; | ||
file = file || 'cmd.exe'; | ||
file = file || DEFAULT_FILE; | ||
opt = opt || {}; | ||
opt.env = opt.env || process.env; | ||
const env = extend({}, opt.env); | ||
const env = assign({}, opt.env); | ||
const cols = opt.cols || Terminal.DEFAULT_COLS; | ||
const rows = opt.rows || Terminal.DEFAULT_ROWS; | ||
const cwd = opt.cwd || process.cwd(); | ||
const name = opt.name || env.TERM || 'Windows Shell'; | ||
const name = opt.name || env.TERM || DEFAULT_NAME; | ||
const parsedEnv = this._parseEnv(env); | ||
@@ -37,0 +40,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
233
25
1007949
2557
68
+ Addednan@2.5.0(transitive)
- Removedextend@~1.2.1
- Removedextend@1.2.1(transitive)
- Removednan@2.2.1(transitive)
Updatednan@2.5.0