Skip to content

Commit 1ff1bd0

Browse files
committed
Fix duplicate listener bug
1 parent 70ade46 commit 1ff1bd0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/shell/commands/testwatch.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ export default function testwatch(that: BJShell, arg: string[]) {
5757
await that.revertlineModeFromKeypress();
5858
await probset_select(that, arg)(false);
5959
await testwatch(that, arg)();
60-
} else if (data.name === "l") {
61-
console.log();
62-
await probset_list(that, arg)();
6360
}
6461
});
6562

src/shell/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ export class BJShell {
115115
async changelineModeToKeypress(
116116
keypressListener: (key: string, data: any) => Promise<void>
117117
) {
118+
if(this?.keyeventListener) {
119+
console.log(chalk.red("Already in keypress mode! override previous listener."));
120+
await this.revertlineModeFromKeypress();
121+
}
118122
this.r.removeListener("line", this.lineListener);
119123
readline.emitKeypressEvents(process.stdin);
120124
process.stdin.setRawMode(true);
@@ -132,6 +136,8 @@ export class BJShell {
132136
}
133137
this.r.write(null, { ctrl: true, name: "u" });
134138
await this.setPrompt();
139+
// re-register line listener (assure 1 listener)
140+
this.r.removeListener("line", this.lineListener);
135141
this.r.on("line", this.lineListener);
136142
}
137143

@@ -140,6 +146,9 @@ export class BJShell {
140146
this.r.on("close", function () {
141147
process.exit();
142148
});
149+
this.r.setMaxListeners(1);
150+
// onkeypress listener is already registered
151+
process.stdin.setMaxListeners(2);
143152

144153
// Handle Ctrl+C (SIGINT) to send it to the child process
145154
this.r.on("SIGINT", async () => {

0 commit comments

Comments
 (0)