2025-02-25 13:59:26 +01:00
|
|
|
|
import boxen from "boxen";
|
|
|
|
|
|
import chalk from "chalk";
|
2025-02-25 14:37:28 +01:00
|
|
|
|
import inquirer from "inquirer";
|
2025-04-09 09:31:22 +02:00
|
|
|
|
import { createSpinner } from "nanospinner";
|
2025-02-25 14:37:28 +01:00
|
|
|
|
|
|
|
|
|
|
import { ASCII_ART } from "../constants/ascii.js";
|
2025-02-25 13:59:26 +01:00
|
|
|
|
|
|
|
|
|
|
function show(msg) {
|
|
|
|
|
|
console.log(msg);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export class UiService {
|
|
|
|
|
|
showSuccessMessage = (message) => {
|
|
|
|
|
|
show(
|
|
|
|
|
|
boxen(chalk.green(message), {
|
|
|
|
|
|
padding: 1,
|
|
|
|
|
|
margin: 1,
|
|
|
|
|
|
borderStyle: "round",
|
|
|
|
|
|
borderColor: "green",
|
|
|
|
|
|
title: "✅ SUCCESS",
|
|
|
|
|
|
titleAlignment: "center",
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
showErrorMessage = (message) => {
|
|
|
|
|
|
show(
|
|
|
|
|
|
boxen(chalk.red(message), {
|
|
|
|
|
|
padding: 1,
|
|
|
|
|
|
margin: 1,
|
|
|
|
|
|
borderStyle: "round",
|
|
|
|
|
|
borderColor: "red",
|
|
|
|
|
|
title: "❌ ERROR",
|
|
|
|
|
|
titleAlignment: "center",
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-02-25 14:37:28 +01:00
|
|
|
|
showInfoMessage = (message) => {
|
2025-02-25 13:59:26 +01:00
|
|
|
|
show(
|
|
|
|
|
|
boxen(chalk.cyan(message), {
|
|
|
|
|
|
padding: 1,
|
|
|
|
|
|
margin: 1,
|
|
|
|
|
|
borderStyle: "round",
|
|
|
|
|
|
borderColor: "cyan",
|
|
|
|
|
|
title: "ℹ️ INFO",
|
|
|
|
|
|
titleAlignment: "center",
|
|
|
|
|
|
}),
|
|
|
|
|
|
);
|
2025-02-25 14:37:28 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
showLogo = () => {
|
|
|
|
|
|
console.log("\n" + chalk.cyanBright(ASCII_ART));
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
askMultipleChoice = async (message, choices) => {
|
|
|
|
|
|
var counter = 1;
|
|
|
|
|
|
var promptChoices = [];
|
2025-03-07 13:14:32 +01:00
|
|
|
|
choices.forEach(function (choice) {
|
2025-02-25 14:37:28 +01:00
|
|
|
|
promptChoices.push(`${counter}. ${choice.label}`);
|
|
|
|
|
|
counter++;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const { choice } = await inquirer.prompt([
|
|
|
|
|
|
{
|
|
|
|
|
|
type: "list",
|
|
|
|
|
|
name: "choice",
|
|
|
|
|
|
message: message,
|
|
|
|
|
|
choices: promptChoices,
|
|
|
|
|
|
pageSize: counter - 1,
|
2025-03-07 13:14:32 +01:00
|
|
|
|
loop: true,
|
|
|
|
|
|
},
|
2025-02-25 14:37:28 +01:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
const selectStr = choice.split(".")[0];
|
|
|
|
|
|
const selectIndex = parseInt(selectStr) - 1;
|
|
|
|
|
|
|
|
|
|
|
|
await choices[selectIndex].action();
|
|
|
|
|
|
};
|
2025-03-07 13:14:32 +01:00
|
|
|
|
|
|
|
|
|
|
askPrompt = async (prompt) => {
|
|
|
|
|
|
const response = await inquirer.prompt([
|
|
|
|
|
|
{
|
|
|
|
|
|
type: "input",
|
|
|
|
|
|
name: "valueStr",
|
|
|
|
|
|
message: prompt,
|
|
|
|
|
|
},
|
|
|
|
|
|
]);
|
|
|
|
|
|
return response.valueStr;
|
|
|
|
|
|
};
|
2025-04-09 09:31:22 +02:00
|
|
|
|
|
|
|
|
|
|
createAndStartSpinner = (message) => {
|
|
|
|
|
|
return createSpinner(message).start();
|
2025-04-09 10:27:00 +02:00
|
|
|
|
};
|
2025-04-09 09:31:22 +02:00
|
|
|
|
|
|
|
|
|
|
stopSpinnerSuccess = (spinner) => {
|
|
|
|
|
|
if (spinner == undefined) return;
|
|
|
|
|
|
spinner.stop();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
stopSpinnerError = (spinner) => {
|
|
|
|
|
|
if (spinner == undefined) return;
|
|
|
|
|
|
spinner.error();
|
|
|
|
|
|
};
|
2025-02-25 13:59:26 +01:00
|
|
|
|
}
|