-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (65 loc) · 1.79 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const readline = require("readline");
const generateFingerprint = require("./fingerprint.js");
const generateKeybox = require("./keybox.js");
// Create readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
// Define the menu options
const menuOptions = ["Generate fingerprint overlay", "Generate keybox overlay"];
// Function to display the menu
function showMenu() {
console.log("\nPlease select an option:");
menuOptions.forEach((option, index) => {
console.log(`${index + 1}. ${option}`);
});
}
// Function to handle user's choice
function handleChoice(choice) {
switch (choice) {
case "1":
generateFingerprint().then(() => {
askToContinue();
});
break;
case "2":
generateKeybox().then(() => {
askToContinue();
});
break;
default:
console.clear();
console.log("Invalid choice, please select a valid option.");
showMenu();
promptUser();
}
}
function askToContinue() {
rl.question(
"\nWould you like to make another selection? (y/n): ",
(answer) => {
if (answer.toLowerCase() === "y") {
console.clear();
showMenu();
promptUser(); // Prompt for the next selection if user says 'y'
} else if (answer.toLowerCase() === "n") {
console.log("Goodbye!");
rl.close();
process.exit(); // Close the program if user says 'n'
} else {
console.log('Invalid input. Please respond with "y" or "n".');
askToContinue(); // Re-prompt if the input is invalid
}
}
);
}
// Function to prompt the user for input
function promptUser() {
rl.question("Enter your choice (1-2): ", (answer) => {
handleChoice(answer);
});
}
// Start by showing the menu
showMenu();
promptUser();