mirror of
https://github.com/logos-storage/logos-storage-installer.git
synced 2026-01-02 13:33:11 +00:00
Abstracts out the multiple choice prompt
This commit is contained in:
parent
ef589cf085
commit
b1e49eef87
@ -92,7 +92,7 @@ export async function main() {
|
||||
const uiService = new UiService();
|
||||
const mainMenu = new MainMenu(uiService);
|
||||
|
||||
mainMenu.show();
|
||||
await mainMenu.show();
|
||||
return;
|
||||
|
||||
try {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import boxen from "boxen";
|
||||
import chalk from "chalk";
|
||||
import inquirer from "inquirer";
|
||||
|
||||
import { ASCII_ART } from "../constants/ascii.js";
|
||||
|
||||
function show(msg) {
|
||||
console.log(msg);
|
||||
@ -32,7 +35,7 @@ export class UiService {
|
||||
);
|
||||
};
|
||||
|
||||
showInfoMessage(message) {
|
||||
showInfoMessage = (message) => {
|
||||
show(
|
||||
boxen(chalk.cyan(message), {
|
||||
padding: 1,
|
||||
@ -43,5 +46,34 @@ export class UiService {
|
||||
titleAlignment: "center",
|
||||
}),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
showLogo = () => {
|
||||
console.log("\n" + chalk.cyanBright(ASCII_ART));
|
||||
};
|
||||
|
||||
askMultipleChoice = async (message, choices) => {
|
||||
var counter = 1;
|
||||
var promptChoices = [];
|
||||
choices.forEach(function(choice) {
|
||||
promptChoices.push(`${counter}. ${choice.label}`);
|
||||
counter++;
|
||||
});
|
||||
|
||||
const { choice } = await inquirer.prompt([
|
||||
{
|
||||
type: "list",
|
||||
name: "choice",
|
||||
message: message,
|
||||
choices: promptChoices,
|
||||
pageSize: counter - 1,
|
||||
loop: true
|
||||
}
|
||||
]);
|
||||
|
||||
const selectStr = choice.split(".")[0];
|
||||
const selectIndex = parseInt(selectStr) - 1;
|
||||
|
||||
await choices[selectIndex].action();
|
||||
};
|
||||
}
|
||||
|
||||
@ -3,7 +3,22 @@ export class MainMenu {
|
||||
this.ui = uiService;
|
||||
}
|
||||
|
||||
show = () => {
|
||||
show = async () => {
|
||||
this.ui.showLogo();
|
||||
this.ui.showInfoMessage("hello");
|
||||
|
||||
await this.ui.askMultipleChoice("Select an option",[
|
||||
{
|
||||
label: "optionOne",
|
||||
action: async function() {
|
||||
console.log("A!")
|
||||
}
|
||||
},{
|
||||
label: "optionTwo",
|
||||
action: async function() {
|
||||
console.log("B!")
|
||||
}
|
||||
},
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user