UNPKG

chromancer

Version:

A powerful command-line interface for automating Chrome browser using Playwright. Perfect for web scraping, automation, testing, and browser workflows.

68 lines (67 loc) 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProgressBar = exports.ProgressIndicator = void 0; class ProgressIndicator { spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; currentIndex = 0; interval; message; constructor(message) { this.message = message; } start() { this.interval = setInterval(() => { process.stdout.write(`\r${this.spinner[this.currentIndex]} ${this.message}`); this.currentIndex = (this.currentIndex + 1) % this.spinner.length; }, 80); } update(message) { this.message = message; } stop(finalMessage) { if (this.interval) { clearInterval(this.interval); process.stdout.write('\r' + ' '.repeat(this.message.length + 3) + '\r'); if (finalMessage) { console.log(finalMessage); } } } } exports.ProgressIndicator = ProgressIndicator; class ProgressBar { width; total; current = 0; description; constructor(description, total, width = 30) { this.description = description; this.total = total; this.width = width; } update(current) { this.current = Math.min(current, this.total); this.render(); } increment() { this.update(this.current + 1); } render() { const percent = this.current / this.total; const filled = Math.floor(this.width * percent); const empty = this.width - filled; const bar = '█'.repeat(filled) + '░'.repeat(empty); const percentStr = `${Math.floor(percent * 100)}%`; process.stdout.write(`\r${this.description} [${bar}] ${percentStr} (${this.current}/${this.total})`); if (this.current === this.total) { console.log(); // New line when complete } } complete(message) { this.update(this.total); if (message) { console.log(message); } } } exports.ProgressBar = ProgressBar;