Skip to content

Commit c02222b

Browse files
committed
Fix blocking once on splash screen
1 parent b4c0c6c commit c02222b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/scenes/splash-screen.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,39 @@ import { GameStateScene } from "../enums.js";
88
*/
99
export class SplashScreenScene extends Scene {
1010
private readonly nextScene: GameStateScene;
11+
/* eslint-disable @typescript-eslint/no-explicit-any */
12+
private readonly onKeyPress: (letter: string, key: any) => void;
1113

1214
constructor(nextScene: GameStateScene) {
1315
super();
1416
this.nextScene = nextScene;
1517
this.canWrite = false;
16-
}
17-
18-
override start() {
19-
process.stdin.once("keypress", (_letter, key) => {
18+
this.onKeyPress = (_letter, key) => {
2019
if (key.name === "return" || key.name === "enter") {
2120
this.exit(this.nextScene);
2221
}
23-
});
22+
};
23+
}
24+
25+
/**
26+
* Shows the splash-screen and listen to "enter" key press to
27+
* continue to the next scene.
28+
*/
29+
override start() {
30+
process.stdin.on("keypress", this.onKeyPress);
2431
const card = drawCard(
2532
["Cli-learning-cards", "--Press enter--"],
2633
getCardWidth(this.tWidth),
2734
);
2835
this.setContent("all", card, true);
2936
super.start();
3037
}
38+
39+
/**
40+
* Exits this scene and remove the keypress listener.
41+
*/
42+
override exit(nextScene: GameStateScene) {
43+
process.stdin.off("keypress", this.onKeyPress);
44+
super.exit(nextScene);
45+
}
3146
}

0 commit comments

Comments
 (0)