update deno-commons-mode.ts
This commit is contained in:
@@ -439,6 +439,41 @@ export function setKeyRingPassword(
|
||||
return;
|
||||
}
|
||||
|
||||
export class ProcessBar {
|
||||
interval?: number;
|
||||
message: string;
|
||||
constructor(message?: string) {
|
||||
this.message = message || "Processing";
|
||||
}
|
||||
async call<T>(cb: () => Promise<T>, clearLine?: boolean): Promise<T> {
|
||||
this.start();
|
||||
try {
|
||||
return await cb();
|
||||
} finally {
|
||||
this.stop(clearLine);
|
||||
}
|
||||
}
|
||||
start(): void {
|
||||
const startMs = new Date().getTime();
|
||||
let count = 0;
|
||||
this.interval = setInterval(() => {
|
||||
const dots = ".".repeat(((count++) % 10) + 1);
|
||||
const costMs = new Date().getTime() - startMs;
|
||||
let time = `${costMs}ms`;
|
||||
if (costMs > 1000) {
|
||||
time = `${Math.floor(costMs / 1000)}s`;
|
||||
}
|
||||
process.stderr.write(`\r${this.message} ${time} ${dots}\x1b[K`);
|
||||
}, 200);
|
||||
}
|
||||
stop(clearLine?: boolean): void {
|
||||
if (this.interval) {
|
||||
clearInterval(this.interval);
|
||||
process.stderr.write(clearLine ? "\r" : "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Deno.test("isOn", () => {
|
||||
assertEquals(false, isOn(undefined));
|
||||
assertEquals(false, isOn(""));
|
||||
|
||||
Reference in New Issue
Block a user