diff --git a/src/main.js b/src/main.js index 23194bf..8b25b2c 100644 --- a/src/main.js +++ b/src/main.js @@ -92,7 +92,7 @@ export async function main() { const uiService = new UiService(); const mainMenu = new MainMenu(uiService); - mainMenu.show(); + await mainMenu.show(); return; try { diff --git a/src/services/uiservice.js b/src/services/uiservice.js index ee13a78..7711403 100644 --- a/src/services/uiservice.js +++ b/src/services/uiservice.js @@ -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(); + }; } diff --git a/src/ui/mainmenu.js b/src/ui/mainmenu.js index 99967bf..710f458 100644 --- a/src/ui/mainmenu.js +++ b/src/ui/mainmenu.js @@ -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!") + } + }, + ]) }; }