Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
export type ArgvOrCommandLine = string[] | string;

export interface IExitEvent {
exitCode: number;
exitCode: number | null;
signal: number | undefined;
}

Expand Down
11 changes: 10 additions & 1 deletion src/unixTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,21 @@ if (process.platform !== 'win32') {
const term = new UnixTerminal('node');
it('should exit when terminal is destroyed programmatically', (done) => {
term.on('exit', (code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(code, null);
assert.strictEqual(signal, constants.signals.SIGHUP);
done();
});
term.destroy();
});
it('should report a null exit code when killed by a signal', (done) => {
const killed = new UnixTerminal('node');
killed.onExit(({ exitCode, signal }) => {
assert.strictEqual(exitCode, null);
assert.strictEqual(signal, constants.signals.SIGKILL);
done();
});
killed.kill('SIGKILL');
});
});
describe('signals in parent and child', () => {
it('SIGINT - custom in parent and child', done => {
Expand Down
5 changes: 4 additions & 1 deletion src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export class UnixTerminal extends Terminal {

const encoding = (opt.encoding === undefined ? 'utf8' : opt.encoding);

const onexit = (code: number, signal: number): void => {
const onexit = (rawCode: number, signal: number): void => {
// Align with child_process: a process terminated by a signal has no
// exit code, so report null instead of a misleading 0.
const code = signal ? null : rawCode;
// XXX Sometimes a data event is emitted after exit. Wait til socket is
// destroyed.
if (!this._emittedClose) {
Expand Down
4 changes: 3 additions & 1 deletion typings/node-pty.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ declare module 'node-pty' {

/**
* Adds an event listener for when an exit event fires. This happens when the pty exits.
* On Unix, `exitCode` is `null` when the process was terminated by a signal, in which case
* `signal` holds the signal number.
* @returns an `IDisposable` to stop listening.
*/
readonly onExit: IEvent<{ exitCode: number, signal?: number }>;
readonly onExit: IEvent<{ exitCode: number | null, signal?: number }>;

/**
* Resizes the dimensions of the pty.
Expand Down