@lydell/node-pty 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,69 @@
1
+ Copyright (c) 2012-2015, Christopher Jeffrey (https://github.com/chjj/)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
21
+
22
+
23
+ The MIT License (MIT)
24
+
25
+ Copyright (c) 2016, Daniel Imms (http://www.growingwiththeweb.com)
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining a copy
28
+ of this software and associated documentation files (the "Software"), to deal
29
+ in the Software without restriction, including without limitation the rights
30
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
31
+ copies of the Software, and to permit persons to whom the Software is
32
+ furnished to do so, subject to the following conditions:
33
+
34
+ The above copyright notice and this permission notice shall be included in all
35
+ copies or substantial portions of the Software.
36
+
37
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
42
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
43
+ SOFTWARE.
44
+
45
+
46
+
47
+ MIT License
48
+
49
+ Copyright (c) 2018 - present Microsoft Corporation
50
+
51
+ All rights reserved.
52
+
53
+ Permission is hereby granted, free of charge, to any person obtaining a copy
54
+ of this software and associated documentation files (the "Software"), to deal
55
+ in the Software without restriction, including without limitation the rights
56
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57
+ copies of the Software, and to permit persons to whom the Software is
58
+ furnished to do so, subject to the following conditions:
59
+
60
+ The above copyright notice and this permission notice shall be included in all
61
+ copies or substantial portions of the Software.
62
+
63
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
69
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @lydell/node-pty
2
+
3
+ Fork of [microsoft/node-pty](https://github.com/microsoft/node-pty) with prebuilt binaries.
4
+
5
+ - Only supports platforms with prebuilt binaries. (Never builds with node-gyp at install.)
6
+ - Removed support for old versions of Windows. (Removed winpty, only supports conpty.)
7
+
8
+ ## pty.js
9
+
10
+ microsoft/node-pty is forked from [chjj/pty.js](https://github.com/chjj/pty.js) with the primary goals being to provide better support for later Node.js versions and Windows.
11
+
12
+ ## License
13
+
14
+ Copyright (c) 2012-2015, Christopher Jeffrey (MIT License).<br>
15
+ Copyright (c) 2016, Daniel Imms (MIT License).<br>
16
+ Copyright (c) 2018, Microsoft Corporation (MIT License).
17
+
18
+ ## Version
19
+
20
+ @lydell/node-pty@1.0.0-beta.1 is based on node-pty@1.0.0 (plus maybe a few more unreleased commits).
21
+
22
+ ## Prebuilt binaries
23
+
24
+ This package includes prebuilt binaries for the following platforms and architectures:
25
+
26
+ - macOS (darwin-x64)
27
+ - macOS ARM (darwin-arm64)
28
+ - Linux x86_64 (linux-x64)
29
+ - Windows (win32-x64)
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2019, Microsoft Corporation (MIT License).
4
+ *
5
+ * This module fetches the console process list for a particular PID. It must be
6
+ * called from a different process (child_process.fork) as there can only be a
7
+ * single console attached to a process.
8
+ */
9
+ var getConsoleProcessList = require("@lydell/node-pty-" + process.platform + "-" + process.arch + "/conpty_console_list.node").getConsoleProcessList;
10
+ var shellPid = parseInt(process.argv[2], 10);
11
+ var consoleProcessList = getConsoleProcessList(shellPid);
12
+ process.send({ consoleProcessList: consoleProcessList });
13
+ process.exit(0);
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2019, Microsoft Corporation (MIT License).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var EventEmitter2 = /** @class */ (function () {
7
+ function EventEmitter2() {
8
+ this._listeners = [];
9
+ }
10
+ Object.defineProperty(EventEmitter2.prototype, "event", {
11
+ get: function () {
12
+ var _this = this;
13
+ if (!this._event) {
14
+ this._event = function (listener) {
15
+ _this._listeners.push(listener);
16
+ var disposable = {
17
+ dispose: function () {
18
+ for (var i = 0; i < _this._listeners.length; i++) {
19
+ if (_this._listeners[i] === listener) {
20
+ _this._listeners.splice(i, 1);
21
+ return;
22
+ }
23
+ }
24
+ }
25
+ };
26
+ return disposable;
27
+ };
28
+ }
29
+ return this._event;
30
+ },
31
+ enumerable: true,
32
+ configurable: true
33
+ });
34
+ EventEmitter2.prototype.fire = function (data) {
35
+ var queue = [];
36
+ for (var i = 0; i < this._listeners.length; i++) {
37
+ queue.push(this._listeners[i]);
38
+ }
39
+ for (var i = 0; i < queue.length; i++) {
40
+ queue[i].call(undefined, data);
41
+ }
42
+ };
43
+ return EventEmitter2;
44
+ }());
45
+ exports.EventEmitter2 = EventEmitter2;
package/index.js ADDED
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2012-2015, Christopher Jeffrey, Peter Sunde (MIT License)
4
+ * Copyright (c) 2016, Daniel Imms (MIT License).
5
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ var terminalCtor;
9
+ if (process.platform === 'win32') {
10
+ terminalCtor = require('./windowsTerminal').WindowsTerminal;
11
+ }
12
+ else {
13
+ terminalCtor = require('./unixTerminal').UnixTerminal;
14
+ }
15
+ /**
16
+ * Forks a process as a pseudoterminal.
17
+ * @param file The file to launch.
18
+ * @param args The file's arguments as argv (string[]) or in a pre-escaped
19
+ * CommandLine format (string). Note that the CommandLine option is only
20
+ * available on Windows and is expected to be escaped properly.
21
+ * @param options The options of the terminal.
22
+ * @throws When the file passed to spawn with does not exists.
23
+ * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
24
+ * @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
25
+ * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
26
+ */
27
+ function spawn(file, args, opt) {
28
+ return new terminalCtor(file, args, opt);
29
+ }
30
+ exports.spawn = spawn;
31
+ /** @deprecated */
32
+ function fork(file, args, opt) {
33
+ return new terminalCtor(file, args, opt);
34
+ }
35
+ exports.fork = fork;
36
+ /** @deprecated */
37
+ function createTerminal(file, args, opt) {
38
+ return new terminalCtor(file, args, opt);
39
+ }
40
+ exports.createTerminal = createTerminal;
41
+ function open(options) {
42
+ return terminalCtor.open(options);
43
+ }
44
+ exports.open = open;
package/interfaces.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2016, Daniel Imms (MIT License).
4
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
package/node-pty.d.ts ADDED
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Copyright (c) 2017, Daniel Imms (MIT License).
3
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
4
+ */
5
+
6
+ declare module "node-pty" {
7
+ /**
8
+ * Forks a process as a pseudoterminal.
9
+ * @param file The file to launch.
10
+ * @param args The file's arguments as argv (string[]) or in a pre-escaped CommandLine format
11
+ * (string). Note that the CommandLine option is only available on Windows and is expected to be
12
+ * escaped properly.
13
+ * @param options The options of the terminal.
14
+ * @see CommandLineToArgvW https://msdn.microsoft.com/en-us/library/windows/desktop/bb776391(v=vs.85).aspx
15
+ * @see Parsing C++ Comamnd-Line Arguments https://msdn.microsoft.com/en-us/library/17w5ykft.aspx
16
+ * @see GetCommandLine https://msdn.microsoft.com/en-us/library/windows/desktop/ms683156.aspx
17
+ */
18
+ export function spawn(file: string, args: string[] | string, options: IPtyForkOptions | IWindowsPtyForkOptions): IPty;
19
+
20
+ export interface IBasePtyForkOptions {
21
+
22
+ /**
23
+ * Name of the terminal to be set in environment ($TERM variable).
24
+ */
25
+ name?: string;
26
+
27
+ /**
28
+ * Number of intial cols of the pty.
29
+ */
30
+ cols?: number;
31
+
32
+ /**
33
+ * Number of initial rows of the pty.
34
+ */
35
+ rows?: number;
36
+
37
+ /**
38
+ * Working directory to be set for the child program.
39
+ */
40
+ cwd?: string;
41
+
42
+ /**
43
+ * Environment to be set for the child program.
44
+ */
45
+ env?: { [key: string]: string | undefined };
46
+
47
+ /**
48
+ * String encoding of the underlying pty.
49
+ * If set, incoming data will be decoded to strings and outgoing strings to bytes applying this encoding.
50
+ * If unset, incoming data will be delivered as raw bytes (Buffer type).
51
+ * By default 'utf8' is assumed, to unset it explicitly set it to `null`.
52
+ */
53
+ encoding?: string | null;
54
+
55
+ /**
56
+ * (EXPERIMENTAL)
57
+ * Whether to enable flow control handling (false by default). If enabled a message of `flowControlPause`
58
+ * will pause the socket and thus blocking the child program execution due to buffer back pressure.
59
+ * A message of `flowControlResume` will resume the socket into flow mode.
60
+ * For performance reasons only a single message as a whole will match (no message part matching).
61
+ * If flow control is enabled the `flowControlPause` and `flowControlResume` messages are not forwarded to
62
+ * the underlying pseudoterminal.
63
+ */
64
+ handleFlowControl?: boolean;
65
+
66
+ /**
67
+ * (EXPERIMENTAL)
68
+ * The string that should pause the pty when `handleFlowControl` is true. Default is XOFF ('\x13').
69
+ */
70
+ flowControlPause?: string;
71
+
72
+ /**
73
+ * (EXPERIMENTAL)
74
+ * The string that should resume the pty when `handleFlowControl` is true. Default is XON ('\x11').
75
+ */
76
+ flowControlResume?: string;
77
+ }
78
+
79
+ export interface IPtyForkOptions extends IBasePtyForkOptions {
80
+ /**
81
+ * Security warning: use this option with great caution,
82
+ * as opened file descriptors with higher privileges might leak to the child program.
83
+ */
84
+ uid?: number;
85
+ gid?: number;
86
+ }
87
+
88
+ export interface IWindowsPtyForkOptions extends IBasePtyForkOptions {
89
+ /**
90
+ * Whether to use PSEUDOCONSOLE_INHERIT_CURSOR in conpty.
91
+ * @see https://docs.microsoft.com/en-us/windows/console/createpseudoconsole
92
+ */
93
+ conptyInheritCursor?: boolean;
94
+ }
95
+
96
+ /**
97
+ * An interface representing a pseudoterminal.
98
+ */
99
+ export interface IPty {
100
+ /**
101
+ * The process ID of the outer process.
102
+ */
103
+ readonly pid: number;
104
+
105
+ /**
106
+ * The column size in characters.
107
+ */
108
+ readonly cols: number;
109
+
110
+ /**
111
+ * The row size in characters.
112
+ */
113
+ readonly rows: number;
114
+
115
+ /**
116
+ * The title of the active process.
117
+ */
118
+ readonly process: string;
119
+
120
+ /**
121
+ * (EXPERIMENTAL)
122
+ * Whether to handle flow control. Useful to disable/re-enable flow control during runtime.
123
+ * Use this for binary data that is likely to contain the `flowControlPause` string by accident.
124
+ */
125
+ handleFlowControl: boolean;
126
+
127
+ /**
128
+ * Adds an event listener for when a data event fires. This happens when data is returned from
129
+ * the pty.
130
+ * @returns an `IDisposable` to stop listening.
131
+ */
132
+ readonly onData: IEvent<string>;
133
+
134
+ /**
135
+ * Adds an event listener for when an exit event fires. This happens when the pty exits.
136
+ * @returns an `IDisposable` to stop listening.
137
+ */
138
+ readonly onExit: IEvent<{ exitCode: number, signal?: number }>;
139
+
140
+ /**
141
+ * Resizes the dimensions of the pty.
142
+ * @param columns The number of columns to use.
143
+ * @param rows The number of rows to use.
144
+ */
145
+ resize(columns: number, rows: number): void;
146
+
147
+ /**
148
+ * Clears the pty's internal representation of its buffer. This is a no-op
149
+ * unless on Windows/ConPTY. This is useful if the buffer is cleared on the
150
+ * frontend in order to synchronize state with the backend to avoid ConPTY
151
+ * possibly reprinting the screen.
152
+ */
153
+ clear(): void;
154
+
155
+ /**
156
+ * Writes data to the pty.
157
+ * @param data The data to write.
158
+ */
159
+ write(data: string): void;
160
+
161
+ /**
162
+ * Kills the pty.
163
+ * @param signal The signal to use, defaults to SIGHUP. This parameter is not supported on
164
+ * Windows.
165
+ * @throws Will throw when signal is used on Windows.
166
+ */
167
+ kill(signal?: string): void;
168
+
169
+ /**
170
+ * Pauses the pty for customizable flow control.
171
+ */
172
+ pause(): void;
173
+
174
+ /**
175
+ * Resumes the pty for customizable flow control.
176
+ */
177
+ resume(): void;
178
+ }
179
+
180
+ /**
181
+ * An object that can be disposed via a dispose function.
182
+ */
183
+ export interface IDisposable {
184
+ dispose(): void;
185
+ }
186
+
187
+ /**
188
+ * An event that can be listened to.
189
+ * @returns an `IDisposable` to stop listening.
190
+ */
191
+ export interface IEvent<T> {
192
+ (listener: (e: T) => any): IDisposable;
193
+ }
194
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@lydell/node-pty",
3
+ "description": "node-pty with prebuilt binaries",
4
+ "author": "Simon Lydell",
5
+ "version": "1.0.0-beta.1",
6
+ "license": "MIT",
7
+ "main": "./index.js",
8
+ "types": "./node-pty.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git://github.com/lydell/node-pty.git"
12
+ },
13
+ "keywords": [
14
+ "pty",
15
+ "tty",
16
+ "terminal",
17
+ "pseudoterminal",
18
+ "forkpty",
19
+ "openpty",
20
+ "prebuild",
21
+ "prebuilt"
22
+ ],
23
+ "dependencies": {
24
+ "node-addon-api": "^7.1.0"
25
+ },
26
+ "optionalDependencies": {
27
+ "@lydell/node-pty-darwin-x64": "1.0.0-beta.1",
28
+ "@lydell/node-pty-darwin-arm64": "1.0.0-beta.1",
29
+ "@lydell/node-pty-linux-x64": "1.0.0-beta.1",
30
+ "@lydell/node-pty-win32-x64": "1.0.0-beta.1"
31
+ }
32
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var PACKAGE_NAME = "@lydell/node-pty-" + process.platform + "-" + process.arch;
4
+ var help = "\nThis can happen if you use the \"--omit=optional\" (or \"--no-optional\") npm flag.\nThe \"optionalDependencies\" package.json feature is used to install the correct\nbinary executable for your current platform. Remove that flag to use @lydell/node-pty.\n\nThis can also happen if the \"node_modules\" folder was copied between two operating systems\nthat need different binaries - including \"virtual\" operating systems like Docker and WSL.\nIf so, try installing with npm rather than copying \"node_modules\".\n".trim();
5
+ function requireBinary(file) {
6
+ try {
7
+ return require(PACKAGE_NAME + "/" + file);
8
+ }
9
+ catch (error) {
10
+ if (error && error.code === 'MODULE_NOT_FOUND') {
11
+ var optionalDependencies = getOptionalDependencies();
12
+ throw new Error(optionalDependencies === undefined
13
+ ? "The @lydell/node-pty package could not find the binary package: " + PACKAGE_NAME + "/" + file + "\n\n" + help + "\n\nYour platform (" + process.platform + "-" + process.arch + ") might not be supported."
14
+ : PACKAGE_NAME in optionalDependencies
15
+ ? "The @lydell/node-pty package supports your platform (" + process.platform + "-" + process.arch + "), but it could not find the binary package for it: " + PACKAGE_NAME + "/" + file + "\n\n" + help
16
+ : "The @lydell/node-pty package currently does not support your platform: " + process.platform + "-" + process.arch,
17
+ // @ts-ignore: The TypeScript setup does not seem to support cause.
18
+ { cause: error });
19
+ }
20
+ else {
21
+ throw error;
22
+ }
23
+ }
24
+ }
25
+ exports.requireBinary = requireBinary;
26
+ function getOptionalDependencies() {
27
+ try {
28
+ return require('./package.json').optionalDependencies;
29
+ }
30
+ catch (_error) {
31
+ return undefined;
32
+ }
33
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2020, Microsoft Corporation (MIT License).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ function getWorkerPipeName(conoutPipeName) {
7
+ return conoutPipeName + "-worker";
8
+ }
9
+ exports.getWorkerPipeName = getWorkerPipeName;
package/terminal.js ADDED
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2012-2015, Christopher Jeffrey (MIT License)
4
+ * Copyright (c) 2016, Daniel Imms (MIT License).
5
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ var events_1 = require("events");
9
+ var eventEmitter2_1 = require("./eventEmitter2");
10
+ exports.DEFAULT_COLS = 80;
11
+ exports.DEFAULT_ROWS = 24;
12
+ /**
13
+ * Default messages to indicate PAUSE/RESUME for automatic flow control.
14
+ * To avoid conflicts with rebound XON/XOFF control codes (such as on-my-zsh),
15
+ * the sequences can be customized in `IPtyForkOptions`.
16
+ */
17
+ var FLOW_CONTROL_PAUSE = '\x13'; // defaults to XOFF
18
+ var FLOW_CONTROL_RESUME = '\x11'; // defaults to XON
19
+ var Terminal = /** @class */ (function () {
20
+ function Terminal(opt) {
21
+ this._pid = 0;
22
+ this._fd = 0;
23
+ this._cols = 0;
24
+ this._rows = 0;
25
+ this._readable = false;
26
+ this._writable = false;
27
+ this._onData = new eventEmitter2_1.EventEmitter2();
28
+ this._onExit = new eventEmitter2_1.EventEmitter2();
29
+ // for 'close'
30
+ this._internalee = new events_1.EventEmitter();
31
+ // setup flow control handling
32
+ this.handleFlowControl = !!(opt === null || opt === void 0 ? void 0 : opt.handleFlowControl);
33
+ this._flowControlPause = (opt === null || opt === void 0 ? void 0 : opt.flowControlPause) || FLOW_CONTROL_PAUSE;
34
+ this._flowControlResume = (opt === null || opt === void 0 ? void 0 : opt.flowControlResume) || FLOW_CONTROL_RESUME;
35
+ if (!opt) {
36
+ return;
37
+ }
38
+ // Do basic type checks here in case node-pty is being used within JavaScript. If the wrong
39
+ // types go through to the C++ side it can lead to hard to diagnose exceptions.
40
+ this._checkType('name', opt.name ? opt.name : undefined, 'string');
41
+ this._checkType('cols', opt.cols ? opt.cols : undefined, 'number');
42
+ this._checkType('rows', opt.rows ? opt.rows : undefined, 'number');
43
+ this._checkType('cwd', opt.cwd ? opt.cwd : undefined, 'string');
44
+ this._checkType('env', opt.env ? opt.env : undefined, 'object');
45
+ this._checkType('uid', opt.uid ? opt.uid : undefined, 'number');
46
+ this._checkType('gid', opt.gid ? opt.gid : undefined, 'number');
47
+ this._checkType('encoding', opt.encoding ? opt.encoding : undefined, 'string');
48
+ }
49
+ Object.defineProperty(Terminal.prototype, "onData", {
50
+ get: function () { return this._onData.event; },
51
+ enumerable: true,
52
+ configurable: true
53
+ });
54
+ Object.defineProperty(Terminal.prototype, "onExit", {
55
+ get: function () { return this._onExit.event; },
56
+ enumerable: true,
57
+ configurable: true
58
+ });
59
+ Object.defineProperty(Terminal.prototype, "pid", {
60
+ get: function () { return this._pid; },
61
+ enumerable: true,
62
+ configurable: true
63
+ });
64
+ Object.defineProperty(Terminal.prototype, "cols", {
65
+ get: function () { return this._cols; },
66
+ enumerable: true,
67
+ configurable: true
68
+ });
69
+ Object.defineProperty(Terminal.prototype, "rows", {
70
+ get: function () { return this._rows; },
71
+ enumerable: true,
72
+ configurable: true
73
+ });
74
+ Terminal.prototype.write = function (data) {
75
+ if (this.handleFlowControl) {
76
+ // PAUSE/RESUME messages are not forwarded to the pty
77
+ if (data === this._flowControlPause) {
78
+ this.pause();
79
+ return;
80
+ }
81
+ if (data === this._flowControlResume) {
82
+ this.resume();
83
+ return;
84
+ }
85
+ }
86
+ // everything else goes to the real pty
87
+ this._write(data);
88
+ };
89
+ Terminal.prototype._forwardEvents = function () {
90
+ var _this = this;
91
+ this.on('data', function (e) { return _this._onData.fire(e); });
92
+ this.on('exit', function (exitCode, signal) { return _this._onExit.fire({ exitCode: exitCode, signal: signal }); });
93
+ };
94
+ Terminal.prototype._checkType = function (name, value, type, allowArray) {
95
+ if (allowArray === void 0) { allowArray = false; }
96
+ if (value === undefined) {
97
+ return;
98
+ }
99
+ if (allowArray) {
100
+ if (Array.isArray(value)) {
101
+ value.forEach(function (v, i) {
102
+ if (typeof v !== type) {
103
+ throw new Error(name + "[" + i + "] must be a " + type + " (not a " + typeof v[i] + ")");
104
+ }
105
+ });
106
+ return;
107
+ }
108
+ }
109
+ if (typeof value !== type) {
110
+ throw new Error(name + " must be a " + type + " (not a " + typeof value + ")");
111
+ }
112
+ };
113
+ /** See net.Socket.end */
114
+ Terminal.prototype.end = function (data) {
115
+ this._socket.end(data);
116
+ };
117
+ /** See stream.Readable.pipe */
118
+ Terminal.prototype.pipe = function (dest, options) {
119
+ return this._socket.pipe(dest, options);
120
+ };
121
+ /** See net.Socket.pause */
122
+ Terminal.prototype.pause = function () {
123
+ return this._socket.pause();
124
+ };
125
+ /** See net.Socket.resume */
126
+ Terminal.prototype.resume = function () {
127
+ return this._socket.resume();
128
+ };
129
+ /** See net.Socket.setEncoding */
130
+ Terminal.prototype.setEncoding = function (encoding) {
131
+ if (this._socket._decoder) {
132
+ delete this._socket._decoder;
133
+ }
134
+ if (encoding) {
135
+ this._socket.setEncoding(encoding);
136
+ }
137
+ };
138
+ Terminal.prototype.addListener = function (eventName, listener) { this.on(eventName, listener); };
139
+ Terminal.prototype.on = function (eventName, listener) {
140
+ if (eventName === 'close') {
141
+ this._internalee.on('close', listener);
142
+ return;
143
+ }
144
+ this._socket.on(eventName, listener);
145
+ };
146
+ Terminal.prototype.emit = function (eventName) {
147
+ var args = [];
148
+ for (var _i = 1; _i < arguments.length; _i++) {
149
+ args[_i - 1] = arguments[_i];
150
+ }
151
+ if (eventName === 'close') {
152
+ return this._internalee.emit.apply(this._internalee, arguments);
153
+ }
154
+ return this._socket.emit.apply(this._socket, arguments);
155
+ };
156
+ Terminal.prototype.listeners = function (eventName) {
157
+ return this._socket.listeners(eventName);
158
+ };
159
+ Terminal.prototype.removeListener = function (eventName, listener) {
160
+ this._socket.removeListener(eventName, listener);
161
+ };
162
+ Terminal.prototype.removeAllListeners = function (eventName) {
163
+ this._socket.removeAllListeners(eventName);
164
+ };
165
+ Terminal.prototype.once = function (eventName, listener) {
166
+ this._socket.once(eventName, listener);
167
+ };
168
+ Terminal.prototype._close = function () {
169
+ this._socket.readable = false;
170
+ this.write = function () { };
171
+ this.end = function () { };
172
+ this._writable = false;
173
+ this._readable = false;
174
+ };
175
+ Terminal.prototype._parseEnv = function (env) {
176
+ var keys = Object.keys(env || {});
177
+ var pairs = [];
178
+ for (var i = 0; i < keys.length; i++) {
179
+ if (keys[i] === undefined) {
180
+ continue;
181
+ }
182
+ pairs.push(keys[i] + '=' + env[keys[i]]);
183
+ }
184
+ return pairs;
185
+ };
186
+ return Terminal;
187
+ }());
188
+ exports.Terminal = Terminal;
package/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) 2017, Daniel Imms (MIT License).
4
+ * Copyright (c) 2018, Microsoft Corporation (MIT License).
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });