/////////////////////////////////////////
// Logging, Deforestation, & Prompting //
/////////////////////////////////////////
try {
const chalk = require('chalk');
const fake = true;
if (fake) {
chalk.enabled = true;
}
class Interactor {
constructor(input=process.stdin, output=process.stdout) {
this._input = input;
this._output = output;
const readline = require('readline');
this.rl = readline.createInterface({
input,
output,
prompt: '',
});
}
log(message) {
if (fake) {
const a2h = new (require('ansi-to-html'))({fg: '#000', bg: '#fff', newline: true});
console.log(`<code>${a2h.toHtml(message)}</code>`);
} else {
this._output.write(message);
}
}
formatBranch(...args) {
return chalk.bold.underline(...args);
}
fail(what, err) {
this.log(`${chalk.red('✗')} Failed to ${what}!\n${chalk.bold.red(err)}`);
}
ok(what, out) {
this.log(`${chalk.green('✓')} ${what}.${out ? '\n' + chalk.bold.green(out) : ''}`)
}
ask(query) {
query = `${chalk.blue.bold('?')} ${query}`;
if (fake) {
return Promise.resolve('feat');
} else {
return new Promise(resolve => rl.question(query, resolve))
}
}
}
global.interactor = new Interactor;
}catch(e){console.log(e,e.stack)}