Comparing version 0.6.3 to 0.6.4
@@ -22,2 +22,3 @@ export declare type ProcessEnv = { | ||
gid?: number; | ||
encoding?: string; | ||
} | ||
@@ -27,2 +28,3 @@ export interface IPtyOpenOptions { | ||
rows?: number; | ||
encoding?: string; | ||
} |
/// <reference types="node" /> | ||
import { Socket } from 'net'; | ||
import { EventEmitter } from 'events'; | ||
import { ITerminal } from './interfaces'; | ||
import { ITerminal, IPtyForkOptions } from './interfaces'; | ||
export declare abstract class Terminal implements ITerminal { | ||
@@ -19,3 +19,4 @@ protected static readonly DEFAULT_COLS: number; | ||
protected _internalee: EventEmitter; | ||
constructor(); | ||
constructor(opt?: IPtyForkOptions); | ||
private _checkType(name, value, type); | ||
end(data: string): void; | ||
@@ -22,0 +23,0 @@ pipe(dest: any, options: any): any; |
@@ -5,5 +5,21 @@ "use strict"; | ||
var Terminal = (function () { | ||
function Terminal() { | ||
function Terminal(opt) { | ||
this._internalee = new events_1.EventEmitter(); | ||
if (!opt) { | ||
return; | ||
} | ||
this._checkType('name', opt.name ? opt.name : null, 'string'); | ||
this._checkType('cols', opt.cols ? opt.cols : null, 'number'); | ||
this._checkType('rows', opt.rows ? opt.rows : null, 'number'); | ||
this._checkType('cwd', opt.cwd ? opt.cwd : null, 'string'); | ||
this._checkType('env', opt.env ? opt.env : null, 'object'); | ||
this._checkType('uid', opt.uid ? opt.uid : null, 'number'); | ||
this._checkType('gid', opt.gid ? opt.gid : null, 'number'); | ||
this._checkType('encoding', opt.encoding ? opt.encoding : null, 'string'); | ||
} | ||
Terminal.prototype._checkType = function (name, value, type) { | ||
if (value && typeof value !== type) { | ||
throw new Error(name + " must be a " + type + " (not a " + typeof value + ")"); | ||
} | ||
}; | ||
Terminal.prototype.end = function (data) { | ||
@@ -10,0 +26,0 @@ this.socket.end(data); |
@@ -23,3 +23,3 @@ "use strict"; | ||
function UnixTerminal(file, args, opt) { | ||
var _this = _super.call(this) || this; | ||
var _this = _super.call(this, opt) || this; | ||
if (typeof args === 'string') { | ||
@@ -44,2 +44,3 @@ throw new Error('args as a string is not supported on unix.'); | ||
var parsedEnv = _this._parseEnv(env); | ||
var encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding); | ||
var onexit = function (code, signal) { | ||
@@ -55,5 +56,7 @@ if (!_this._emittedClose) { | ||
}; | ||
var term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, onexit); | ||
var term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, (encoding === 'utf8'), onexit); | ||
_this.socket = new PipeSocket(term.fd); | ||
_this.socket.setEncoding('utf8'); | ||
if (encoding !== null) { | ||
_this.socket.setEncoding(encoding); | ||
} | ||
_this.socket.resume(); | ||
@@ -108,8 +111,9 @@ _this.socket.on('error', function (err) { | ||
var rows = opt.rows || terminal_1.Terminal.DEFAULT_ROWS; | ||
var encoding = opt.encoding ? 'utf8' : opt.encoding; | ||
var term = pty.open(cols, rows); | ||
self.master = new PipeSocket(term.master); | ||
self.master.setEncoding('utf8'); | ||
self.master.setEncoding(encoding); | ||
self.master.resume(); | ||
self.slave = new PipeSocket(term.slave); | ||
self.slave.setEncoding('utf8'); | ||
self.slave.setEncoding(encoding); | ||
self.slave.resume(); | ||
@@ -116,0 +120,0 @@ self.socket = self.master; |
@@ -14,4 +14,4 @@ /// <reference types="node" /> | ||
readonly outSocket: net.Socket; | ||
readonly pid: number; | ||
readonly fd: any; | ||
readonly innerPid: number; | ||
readonly pty: number; | ||
@@ -18,0 +18,0 @@ constructor(file: string, args: ArgvOrCommandLine, env: string[], cwd: string, cols: number, rows: number, debug: boolean); |
@@ -36,9 +36,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(WindowsPtyAgent.prototype, "pid", { | ||
get: function () { return this._pid; }, | ||
Object.defineProperty(WindowsPtyAgent.prototype, "fd", { | ||
get: function () { return this._fd; }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(WindowsPtyAgent.prototype, "fd", { | ||
get: function () { return this._fd; }, | ||
Object.defineProperty(WindowsPtyAgent.prototype, "innerPid", { | ||
get: function () { return this._innerPid; }, | ||
enumerable: true, | ||
@@ -53,3 +53,3 @@ configurable: true | ||
WindowsPtyAgent.prototype.resize = function (cols, rows) { | ||
pty.resize(this.pid, cols, rows); | ||
pty.resize(this._pid, cols, rows); | ||
}; | ||
@@ -61,3 +61,3 @@ WindowsPtyAgent.prototype.kill = function () { | ||
this._outSocket.writable = false; | ||
pty.kill(this.pid, this._innerPidHandle); | ||
pty.kill(this._pid, this._innerPidHandle); | ||
}; | ||
@@ -64,0 +64,0 @@ return WindowsPtyAgent; |
@@ -22,2 +22,5 @@ "use strict"; | ||
var _this = _super.call(this) || this; | ||
if (opt.encoding) { | ||
console.warn('Setting encoding on Windows is not supported'); | ||
} | ||
args = args || []; | ||
@@ -37,3 +40,3 @@ file = file || DEFAULT_FILE; | ||
_this.socket = _this.agent.outSocket; | ||
_this.pid = _this.agent.pid; | ||
_this.pid = _this.agent.innerPid; | ||
_this.fd = _this.agent.fd; | ||
@@ -40,0 +43,0 @@ _this.pty = _this.agent.pty; |
@@ -7,3 +7,3 @@ { | ||
}, | ||
"version": "0.6.3", | ||
"version": "0.6.4", | ||
"license": "MIT", | ||
@@ -10,0 +10,0 @@ "main": "./lib/index.js", |
@@ -7,5 +7,9 @@ 'use strict' | ||
spawn(os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], { | ||
const p = spawn(os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', ['rebuild'], { | ||
cwd: path.join(__dirname, '..'), | ||
stdio: 'inherit' | ||
}); | ||
p.on('exit', function (code) { | ||
process.exit(code); | ||
}); |
@@ -27,2 +27,3 @@ /** | ||
gid?: number; | ||
encoding?: string; | ||
} | ||
@@ -33,2 +34,3 @@ | ||
rows?: number; | ||
encoding?: string; | ||
} |
@@ -9,3 +9,3 @@ /** | ||
import { EventEmitter } from 'events'; | ||
import { ITerminal } from './interfaces'; | ||
import { ITerminal, IPtyForkOptions } from './interfaces'; | ||
@@ -31,7 +31,28 @@ export abstract class Terminal implements ITerminal { | ||
constructor() { | ||
constructor(opt?: IPtyForkOptions) { | ||
// for 'close' | ||
this._internalee = new EventEmitter(); | ||
if (!opt) { | ||
return; | ||
} | ||
// Do basic type checks here in case node-pty is being used within JavaScript. If the wrong | ||
// types go through to the C++ side it can lead to hard to diagnose exceptions. | ||
this._checkType('name', opt.name ? opt.name : null, 'string'); | ||
this._checkType('cols', opt.cols ? opt.cols : null, 'number'); | ||
this._checkType('rows', opt.rows ? opt.rows : null, 'number'); | ||
this._checkType('cwd', opt.cwd ? opt.cwd : null, 'string'); | ||
this._checkType('env', opt.env ? opt.env : null, 'object'); | ||
this._checkType('uid', opt.uid ? opt.uid : null, 'number'); | ||
this._checkType('gid', opt.gid ? opt.gid : null, 'number'); | ||
this._checkType('encoding', opt.encoding ? opt.encoding : null, 'string'); | ||
} | ||
private _checkType(name: string, value: any, type: string): void { | ||
if (value && typeof value !== type) { | ||
throw new Error(`${name} must be a ${type} (not a ${typeof value})`); | ||
} | ||
} | ||
/** See net.Socket.end */ | ||
@@ -38,0 +59,0 @@ public end(data: string): void{ |
@@ -36,3 +36,3 @@ /** | ||
constructor(file?: string, args?: ArgvOrCommandLine, opt?: IPtyForkOptions) { | ||
super(); | ||
super(opt); | ||
@@ -64,2 +64,4 @@ if (typeof args === 'string') { | ||
const encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding); | ||
const onexit = (code: any, signal: any) => { | ||
@@ -78,6 +80,8 @@ // XXX Sometimes a data event is emitted after exit. Wait til socket is | ||
// fork | ||
const term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, onexit); | ||
const term = pty.fork(file, args, parsedEnv, cwd, cols, rows, uid, gid, (encoding === 'utf8'), onexit); | ||
this.socket = new PipeSocket(term.fd); | ||
this.socket.setEncoding('utf8'); | ||
if (encoding !== null) { | ||
this.socket.setEncoding(encoding); | ||
} | ||
this.socket.resume(); | ||
@@ -155,2 +159,3 @@ | ||
const rows = opt.rows || Terminal.DEFAULT_ROWS; | ||
const encoding = opt.encoding ? 'utf8' : opt.encoding; | ||
@@ -161,7 +166,7 @@ // open | ||
self.master = new PipeSocket(term.master); | ||
self.master.setEncoding('utf8'); | ||
self.master.setEncoding(encoding); | ||
self.master.resume(); | ||
self.slave = new PipeSocket(term.slave); | ||
self.slave.setEncoding('utf8'); | ||
self.slave.setEncoding(encoding); | ||
self.slave.resume(); | ||
@@ -168,0 +173,0 @@ |
@@ -32,4 +32,4 @@ /** | ||
public get outSocket(): net.Socket { return this._outSocket; } | ||
public get pid(): number { return this._pid; } | ||
public get fd(): any { return this._fd; } | ||
public get innerPid(): number { return this._innerPid; } | ||
public get pty(): number { return this._pty; } | ||
@@ -84,3 +84,3 @@ | ||
public resize(cols: number, rows: number): void { | ||
pty.resize(this.pid, cols, rows); | ||
pty.resize(this._pid, cols, rows); | ||
} | ||
@@ -93,3 +93,3 @@ | ||
this._outSocket.writable = false; | ||
pty.kill(this.pid, this._innerPidHandle); | ||
pty.kill(this._pid, this._innerPidHandle); | ||
} | ||
@@ -96,0 +96,0 @@ } |
@@ -26,2 +26,6 @@ /** | ||
if (opt.encoding) { | ||
console.warn('Setting encoding on Windows is not supported'); | ||
} | ||
// Initialize arguments | ||
@@ -51,3 +55,3 @@ args = args || []; | ||
// Not available until `ready` event emitted. | ||
this.pid = this.agent.pid; | ||
this.pid = this.agent.innerPid; | ||
this.fd = this.agent.fd; | ||
@@ -54,0 +58,0 @@ this.pty = this.agent.pty; |
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
928652
1474