Skip to content

Commit

Permalink
Merge pull request #516 from corwin-of-amber/main
Browse files Browse the repository at this point in the history
Add accessors `pty` and `ptsName`
  • Loading branch information
Tyriar authored Dec 14, 2021
2 parents bb65b93 + 97f2f27 commit ed75c34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/unixTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { UnixTerminal } from './unixTerminal';
import * as assert from 'assert';
import * as cp from 'child_process';
import * as path from 'path';
import * as tty from 'tty';
import { constants } from 'os';
import { pollUntil } from './testUtils.test';

const FIXTURES_PATH = path.normalize(path.join(__dirname, '..', 'fixtures', 'utf8-character.txt'));
Expand All @@ -26,8 +28,9 @@ if (process.platform !== 'win32') {
regExp = /^\/dev\/tty[p-sP-S][a-z0-9]+$/;
}
if (regExp) {
assert.ok(regExp.test((<any>term)._pty), '"' + (<any>term)._pty + '" should match ' + regExp.toString());
assert.ok(regExp.test(term.ptsName), '"' + term.ptsName + '" should match ' + regExp.toString());
}
assert.ok(tty.isatty(term.fd));
});
});

Expand Down Expand Up @@ -104,6 +107,17 @@ if (process.platform !== 'win32') {
term.master.write('master\n');
});
});
describe('close', () => {
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(signal, constants.signals.SIGHUP);
done();
});
term.destroy();
});
});
describe('signals in parent and child', () => {
it('SIGINT - custom in parent and child', done => {
// this test is cumbersome - we have to run it in a sub process to
Expand Down
4 changes: 4 additions & 0 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export class UnixTerminal extends Terminal {
this._socket.write(data);
}

/* Accessors */
get fd(): number { return this._fd; }
get ptsName(): string { return this._pty; }

/**
* openpty
*/
Expand Down

0 comments on commit ed75c34

Please sign in to comment.