create-datadao
Version:
A CLI tool to generate and deploy DataDAOs on the Vana network
164 lines (142 loc) âĸ 3.3 kB
JavaScript
const chalk = require('chalk');
/**
* Clean output utilities for better UX
*/
class OutputManager {
constructor() {
this.isQuiet = false;
this.userInputMarker = 'đ¤';
}
/**
* Set quiet mode to reduce noise
*/
setQuiet(quiet = true) {
this.isQuiet = quiet;
}
/**
* Main step header
*/
step(title, description = '') {
console.log();
console.log(chalk.blue.bold(`đ ${title}`));
if (description) {
console.log(chalk.gray(` ${description}`));
}
console.log();
}
/**
* Success message
*/
success(message) {
console.log(chalk.green(`â
${message}`));
}
/**
* Warning message
*/
warning(message) {
console.log(chalk.yellow(`â ī¸ ${message}`));
}
/**
* Error message
*/
error(message) {
console.log(chalk.red(`â ${message}`));
}
/**
* Info message (can be suppressed in quiet mode)
*/
info(message, force = false) {
if (!this.isQuiet || force) {
console.log(chalk.cyan(`âšī¸ ${message}`));
}
}
/**
* Progress indicator
*/
progress(message) {
if (!this.isQuiet) {
console.log(chalk.blue(`âŗ ${message}`));
}
}
/**
* Mark user input clearly
*/
userInput(prompt) {
console.log();
console.log(chalk.bgBlue.white.bold(` ${this.userInputMarker} USER INPUT REQUIRED `));
console.log(chalk.blue.bold(prompt));
console.log();
}
/**
* Show user's response
*/
userResponse(response) {
console.log(chalk.green(`${this.userInputMarker} ${response}`));
console.log();
}
/**
* Summary section
*/
summary(title, items) {
console.log();
console.log(chalk.blue.bold(`đ ${title}`));
items.forEach(item => {
if (typeof item === 'string') {
console.log(` âĸ ${item}`);
} else {
console.log(` âĸ ${chalk.cyan(item.label)}: ${item.value}`);
}
});
console.log();
}
/**
* Next steps section
*/
nextSteps(steps) {
console.log();
console.log(chalk.blue.bold('đ Next Steps:'));
steps.forEach((step, index) => {
console.log(` ${index + 1}. ${step}`);
});
console.log();
}
/**
* Divider for sections
*/
divider() {
if (!this.isQuiet) {
console.log(chalk.gray('â'.repeat(50)));
}
}
/**
* Clear previous line (for progress updates)
*/
clearLine() {
process.stdout.write('\r\x1b[K');
}
/**
* Progress bar for long operations
*/
progressBar(current, total, message = '') {
// Handle edge cases
if (total === 0) {
const bar = 'â'.repeat(20);
this.clearLine();
process.stdout.write(`${chalk.blue(bar)} 0% ${message}`);
return;
}
const percentage = Math.round((current / total) * 100);
let filled = Math.round((current / total) * 20);
// Clamp filled between 0 and 20
filled = Math.max(0, Math.min(20, filled));
const bar = 'â'.repeat(filled) + 'â'.repeat(20 - filled);
this.clearLine();
process.stdout.write(`${chalk.blue(bar)} ${percentage}% ${message}`);
if (current === total) {
console.log(); // New line when complete
}
}
}
// Create singleton instance
const output = new OutputManager();
module.exports = output;