repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/footer/progress.ts
Raw/**
* Progress bar rendering with discrete block characters.
*
* Renders ▁▂▃▄▅▆▇█ glyphs on a dim background track.
*/
import type { Theme, ThemeColor } from "@earendil-works/pi-coding-agent";
const GLYPHS = [" ", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"];
const MAX_LEVEL = GLYPHS.length - 1;
/** Render discrete block characters with dim background track. */
export function renderBlocksBar(
pct: number,
width: number,
theme: Theme,
color: ThemeColor,
): string {
const clamped = Math.max(0, Math.min(100, pct));
const filledFloat = (clamped / 100) * width;
const background = theme.colors.dim;
const result: string[] = [];
for (let i = 0; i < width; i++) {
const blockFill = Math.max(0, Math.min(1, filledFloat - i));
const level = Math.round(blockFill * MAX_LEVEL);
const glyph = GLYPHS[level] ?? " ";
result.push(
theme.style(glyph, {
...(level > 0 ? { fg: color } : {}),
bg: background,
}),
);
}
return result.join("");
}