61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
|
// requirements
|
||
|
const progress = require('progress');
|
||
|
const readline = require('readline');
|
||
|
|
||
|
// print logo
|
||
|
function printLogo() {
|
||
|
console.log(' _ _ _ __ __ ');
|
||
|
console.log(' | |__ __ _ __| |__ _ ___ _ _ /_\\ | \\/ |');
|
||
|
console.log(' | \'_ \\\/ _` \/ _` \/ _` / -_) \'_\/ _ \\| |\\/| |');
|
||
|
console.log(' |_.__\/\\__,_\\__,_\\__, \\___|_|\/_\/ \\_\\_| |_|');
|
||
|
console.log(' |___/ ');
|
||
|
}
|
||
|
|
||
|
// display a confirmation prompt
|
||
|
function askForConfirmation(message, confirms, callback) {
|
||
|
const line = readline.createInterface({
|
||
|
input: process.stdin,
|
||
|
output: process.stdout
|
||
|
});
|
||
|
message += ' [';
|
||
|
for (let counter = 0, length = confirms.length; counter < length; counter++) {
|
||
|
if (counter > 0) {
|
||
|
message += '/' + confirms[counter];
|
||
|
} else {
|
||
|
message += confirms[counter];
|
||
|
}
|
||
|
}
|
||
|
message += ']';
|
||
|
line.question(message + '\n', function (answer) {
|
||
|
if (confirms.indexOf(answer) === -1) {
|
||
|
return callback('wrong input: \'' + answer + '\'');
|
||
|
}
|
||
|
callback();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// create a ascii progressbar
|
||
|
function createProgressBar(total) {
|
||
|
return new progress(':bar | progress: :current/:total (:percent) | elapsed: :elapseds | eta: :etas', {
|
||
|
total: total,
|
||
|
width: 32
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// shutdown
|
||
|
function exit(err, start) {
|
||
|
if (err) {
|
||
|
console.error(err);
|
||
|
process.exit(1);
|
||
|
}
|
||
|
const diff = process.hrtime(start);
|
||
|
console.log('exiting after ' + ((diff[0] + (diff[1] / 1000000)) / 1000).toFixed(2) + ' seconds');
|
||
|
process.exit(0);
|
||
|
}
|
||
|
|
||
|
// api
|
||
|
exports.printLogo = printLogo;
|
||
|
exports.askForConfirmation = askForConfirmation;
|
||
|
exports.createProgressBar = createProgressBar;
|
||
|
exports.exit = exit;
|