function QueueWorker(queueName){ this.TAG = '[' + chalk.yellow(queueName) + ']' this.status = console.draft() this.working = false this.idle() }
function startDownload() { var barLine = console.draft('Wait...') var progress = 0 var interval = downloadMock(function () { // To add random speed, we use random: progress += Math.round(Math.random() * 5) // Update bar barLine(ProgressBar(progress)) // Check ended if (progress >= 100) { barLine(ProgressBar(progress), chalk.green('Finished download!')) clearInterval(interval) } }, 50) }
function install(lib, callback) { var status = console.draft()
function trackMem() { let avgs = [], memus = console.draft(chalk`{blue Memory usage:} {green MB}`); setInterval(() => { let used = process.memoryUsage().heapUsed / 1024 / 1024; avgs.push(used); if (avgs.length > 30) { avgs.shift(); } let total = 0; avgs.forEach((avrg) => { total += avrg; }); let avg = total / avgs.length; memus(chalk`{blue Memory usage:} {green ${Math.round(used * 100) / 100}MB} {blue avg:} {green ${Math.round(avg * 100) / 100}MB}`) }, 1000); }
/** * Log an animated "loading" message * @param {String|Number} name - The name of the draft-log, this is needed to retrieve it later * @param {*} text - The text to be logged * @returns {void} */ async draft(name, text) { //If the terminal cannot handle draft logs, make a simple log if (!process.stderr.isTTY) { return this.info(text); } this.drafts.set(name, { spinning: true, text, draft: console.draft(this.info(`${frames[0]} ${text}`, true)) }); for (let i = 0; this.drafts.get(name).spinning; i++) { await sleep(50); this.drafts.get(name).draft(this.info(`${frames[i % frames.length]} ${text}`, true)); } }
/** * Log an animated "loading" message * @param {String|Number} name - The name of the draft-log, this is needed to retrieve it later * @param {string} text - The text to be logged * @returns {Promise<void | string>} TODO */ async draft(name, text) { //If the terminal cannot handle draft logs, make a simple log if (!process.stderr.isTTY) { return this.info(text); } this.drafts.set(name, { spinning: true, text, // @ts-ignore draft: console.draft(this.info(`${frames[0]} ${text}`, true)) }); for (let i = 0; this.drafts.get(name).spinning; i++) { await sleep(50); this.drafts.get(name).draft(this.info(`${frames[i % frames.length]} ${text}`, true)); } }