cloc-graph
Version:
Track lines of code over time by language with visualization
104 lines (103 loc) • 3.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProgressService = void 0;
/**
* Progress bar service for CLI feedback
*/
const cliProgress = __importStar(require("cli-progress"));
/**
* Service for showing progress bars in the CLI
*/
class ProgressService {
constructor() {
this.progressBar = null;
}
/**
* Create and start a new progress bar
*
* @param total - Total number of steps
* @param options - Configuration options
*/
start(total, options = {}) {
// Don't create a progress bar for very small tasks
if (total < 3)
return;
const format = options.format ||
`${options.title || 'Progress'}: [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}`;
// Create a new progress bar
this.progressBar = new cliProgress.SingleBar({
format,
barCompleteChar: '\u2588',
barIncompleteChar: '\u2591',
hideCursor: true,
etaBuffer: options.etaBuffer || 100
});
// Start the progress bar
this.progressBar.start(total, 0);
}
/**
* Update the progress bar
*
* @param current - Current progress value
* @param payload - Optional payload to update progress bar
*/
update(current, payload) {
if (this.progressBar) {
this.progressBar.update(current, payload);
}
}
/**
* Increment the progress bar by a specified amount
*
* @param amount - Amount to increment (default: 1)
* @param payload - Optional payload to update progress bar
*/
increment(amount = 1, payload) {
if (this.progressBar) {
this.progressBar.increment(amount, payload);
}
}
/**
* Stop and clear the progress bar
*/
stop() {
if (this.progressBar) {
this.progressBar.stop();
this.progressBar = null;
}
}
}
exports.ProgressService = ProgressService;