mirror of
https://github.com/farcasterxyz/hub-monorepo.git
synced 2026-04-18 03:00:22 -04:00
fix: Fix progress bar for non-tty (#1319)
This commit is contained in:
@@ -8,7 +8,6 @@ version: '3.9'
|
||||
services:
|
||||
hubble:
|
||||
image: farcasterxyz/hubble:latest
|
||||
tty: true
|
||||
restart: unless-stopped
|
||||
command: [
|
||||
"node", "--no-warnings", "build/cli.js", "start",
|
||||
|
||||
@@ -1,27 +1,33 @@
|
||||
import cliProgress, { SingleBar } from "cli-progress";
|
||||
import { logger } from "./logger.js";
|
||||
|
||||
// The global multibar, to which all progress bars are added
|
||||
const multiBar = new cliProgress.MultiBar(
|
||||
{
|
||||
format: " {bar} {percentage}% | {name} | {value}/{total} | ETA: {eta_formatted}",
|
||||
hideCursor: true,
|
||||
clearOnComplete: false,
|
||||
etaBuffer: 1_000,
|
||||
autopadding: true,
|
||||
},
|
||||
cliProgress.Presets.shades_grey,
|
||||
);
|
||||
const allBars: SingleBar[] = [];
|
||||
let finished = false;
|
||||
|
||||
// Add a progress bar to the console. Returns undefined if the progress bar
|
||||
// cannot be added (e.g. if the process is shutting down).
|
||||
// Call finishAllProgressBars() to stop all progress bars.
|
||||
export function addProgressBar(name: string, total: number, options?: cliProgress.Options): SingleBar | undefined {
|
||||
export function addProgressBar(name: string, total: number): SingleBar | undefined {
|
||||
if (finished) {
|
||||
return undefined;
|
||||
}
|
||||
return multiBar.create(total, 0, { name, ...options });
|
||||
|
||||
const bar = new cliProgress.SingleBar(
|
||||
{
|
||||
format: ` {bar} {percentage}% | ${name} | {value}/{total} | ETA: {eta_formatted}`,
|
||||
hideCursor: true,
|
||||
clearOnComplete: false,
|
||||
etaBuffer: 1_000,
|
||||
autopadding: true,
|
||||
noTTYOutput: true,
|
||||
notTTYSchedule: 3000,
|
||||
},
|
||||
cliProgress.Presets.shades_grey,
|
||||
);
|
||||
|
||||
bar.start(total, 0);
|
||||
allBars.push(bar);
|
||||
return bar;
|
||||
}
|
||||
|
||||
// Finish all progress bars. This should be called when the process is shutting
|
||||
@@ -44,7 +50,7 @@ export function finishAllProgressBars(showDelay = false): void {
|
||||
finished = true;
|
||||
}
|
||||
|
||||
multiBar.stop();
|
||||
allBars.forEach((bar) => bar.stop());
|
||||
logger.flush();
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user