|
5 | 5 | */ |
6 | 6 | import * as net from 'net'; |
7 | 7 | import * as path from 'path'; |
8 | | -import * as tty from 'tty'; |
9 | 8 | import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal'; |
10 | 9 | import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces'; |
11 | 10 | import { ArgvOrCommandLine } from './types'; |
@@ -114,7 +113,7 @@ export class UnixTerminal extends Terminal { |
114 | 113 | // fork |
115 | 114 | const term = pty.fork(file, args, parsedEnv, cwd, this._cols, this._rows, uid, gid, (encoding === 'utf8'), helperPath, onexit); |
116 | 115 |
|
117 | | - this._socket = new tty.ReadStream(term.fd); |
| 116 | + this._socket = new PipeSocket(term.fd); |
118 | 117 | if (encoding !== null) { |
119 | 118 | this._socket.setEncoding(encoding); |
120 | 119 | } |
@@ -204,13 +203,13 @@ export class UnixTerminal extends Terminal { |
204 | 203 | // open |
205 | 204 | const term: IUnixOpenProcess = pty.open(cols, rows); |
206 | 205 |
|
207 | | - self._master = new tty.ReadStream(term.master); |
| 206 | + self._master = new PipeSocket(<number>term.master); |
208 | 207 | if (encoding !== null) { |
209 | 208 | self._master.setEncoding(encoding); |
210 | 209 | } |
211 | 210 | self._master.resume(); |
212 | 211 |
|
213 | | - self._slave = new tty.ReadStream(term.slave); |
| 212 | + self._slave = new PipeSocket(term.slave); |
214 | 213 | if (encoding !== null) { |
215 | 214 | self._slave.setEncoding(encoding); |
216 | 215 | } |
@@ -305,3 +304,18 @@ export class UnixTerminal extends Terminal { |
305 | 304 | delete env['LINES']; |
306 | 305 | } |
307 | 306 | } |
| 307 | + |
| 308 | +/** |
| 309 | + * Wraps net.Socket to force the handle type "PIPE" by temporarily overwriting |
| 310 | + * tty_wrap.guessHandleType. |
| 311 | + * See: https://github.com/chjj/pty.js/issues/103 |
| 312 | + */ |
| 313 | +class PipeSocket extends net.Socket { |
| 314 | + constructor(fd: number) { |
| 315 | + const pipeWrap = (<any>process).binding('pipe_wrap'); // tslint:disable-line |
| 316 | + // @types/node has fd as string? https://github.com/DefinitelyTyped/DefinitelyTyped/pull/18275 |
| 317 | + const handle = new pipeWrap.Pipe(pipeWrap.constants.SOCKET); |
| 318 | + handle.open(fd); |
| 319 | + super(<any>{ handle }); |
| 320 | + } |
| 321 | +} |
0 commit comments