Skip to content

Commit

Permalink
Added "Q to exit" and fixed tracker stopping on errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Buck committed Sep 13, 2018
1 parent 48fcb0b commit 4cc8fb6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/bin/pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ app
.action(function (args: ParsedArgs) {

return selectPlay.call(this, args)
.then(play => {
return pb.run(play, text => app.ui.redraw(text));
.then(async (play) => {
this.log(ansiEscapes.clearScreen);
await pb.run(play, text => app.ui.redraw(text));
this.log(ansiEscapes.clearScreen);
})
.catch((err: Error) => {
this.log(chalk.bgRed.white(err.message), err);
Expand Down Expand Up @@ -284,11 +286,11 @@ function editPlay(play: Play): Promise<void> {
return pb
.findProjects()
.then((projects: Project[]) => {
console.log(`Projects Found: ${projects.length}`);
// console.log(`Projects Found: ${projects.length}`);
const defaults = [... new Set(play.projects.map(p => p.name))];
const choices = sortStrings(projects.map(proj => proj.name));
console.log(`Defaults Found: ${defaults.length}`);
console.log(`Choices Found: ${choices.length}`);
// console.log(`Defaults Found: ${defaults.length}`);
// console.log(`Choices Found: ${choices.length}`);

return this
.prompt(<Question[]>[
Expand Down
22 changes: 16 additions & 6 deletions src/services/process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ export class ProcessManager {
this._redraw();
}, TICK_INTERVAL);
});


const stdin = process.openStdin();
const PREV_RAW_VALUE = process.stdin.isRaw || false;
process.stdin.setRawMode(true);

stdin.on('keypress', (chunk, key) => {
if (key.name === 'q') {
process.stdin.setRawMode(PREV_RAW_VALUE);
this.cancel();
}
});

return this.currentRun = new Promise<void>((resolve) => {
this._drawFunc = () => {
if (this._isCancelled) {
Expand Down Expand Up @@ -189,9 +200,9 @@ Output:
}
});

drawString += `
------------------------------------
`;
drawString +=
`------------------------------------
Press 'Q' to exit...`;

drawFn(drawString);
};
Expand Down Expand Up @@ -236,9 +247,8 @@ Output:
});

tracker.process.on('error', (code: number, signal: string) => {
tracker.done = true;
tracker.buffer.enqueue(GRAY_BLOCK);
this._lastOutput[tracker.name].push(`Process Error: ${code} (${signal})`);
this._lastOutput[tracker.name].push(`Process Error: Signal = ${signal} Code = ${code}`);
this._redraw();
});

Expand Down

0 comments on commit 4cc8fb6

Please sign in to comment.