Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Color the usage bars green, orange and red by how much is left

AdityaUmalec095330d3144
diff --git a/src/components/EngineUsage.tsx b/src/components/EngineUsage.tsx
index 03c71d2db9..037a2af966 100644
--- a/src/components/EngineUsage.tsx
+++ b/src/components/EngineUsage.tsx
@@ -80,7 +80,8 @@ const GLYPH_HEIGHT = 14;
const BASELINE_INSET = 2;
const TALLEST = GLYPH_HEIGHT - BASELINE_INSET;
const GLYPH_WIDTH = BAR_STEP * USAGE_BARS - (BAR_STEP - BAR_WIDTH);
-const TONE_INK: Record<UsageTone, string> = { fine: "text-ink-tertiary", near: "text-warning", out: "text-warning" };
+const TONE_INK: Record<UsageTone, string> = { fine: "text-success", near: "text-warning", out: "text-danger" };
+const TONE_TRACK: Record<UsageTone, string> = { fine: "bg-success", near: "bg-warning", out: "bg-danger" };
/** Four rising bars on whole pixels, filled for the usage left; at the limit every bar is empty and struck through. */
export function UsageGlyph({ limit, className }: { limit: EngineLimit; className?: string }) {
@@ -116,13 +117,13 @@ export function UsageRows({ limit }: { limit: EngineLimit }) {
<div key={row.window} data-usage-row={row.window} className="flex flex-col gap-1.5">
<div className="flex items-baseline gap-3 text-[12px] leading-4">
<span className="shrink-0 text-ink-secondary">{windowLabel(row.window)}</span>
- <span className={cn("ms-auto min-w-0 truncate text-end tabular-nums", row.tone === "fine" ? "text-ink" : "text-warning")}>
+ <span className={cn("ms-auto min-w-0 truncate text-end tabular-nums", row.tone === "fine" ? "text-ink" : TONE_INK[row.tone])}>
<span className="font-medium">{row.tone === "out" ? t("limits.windowAtLimit") : t("planUsage.left", { remaining: row.left })}</span>
{row.resetsAt !== null && row.resetsAt > now && ` · ${t("limits.resets", { time: resetTime(row.resetsAt, now) })}`}
</span>
</div>
<div aria-hidden="true" className="h-1 overflow-hidden rounded-full bg-ink/[0.08]">
- <div data-usage-track className={cn("h-full rounded-full", row.tone === "fine" ? "bg-ink-tertiary" : "bg-warning")} style={{ width: `${100 - row.left}%` }} />
+ <div data-usage-track className={cn("h-full rounded-full", TONE_TRACK[row.tone])} style={{ width: `${100 - row.left}%` }} />
</div>
</div>
))}
diff --git a/src/components/limit-resets.test.ts b/src/components/limit-resets.test.ts
index dbab4d4104..e9e433baf1 100644
--- a/src/components/limit-resets.test.ts
+++ b/src/components/limit-resets.test.ts
@@ -198,6 +198,25 @@ describe("the bars", () => {
expect(out.querySelector(".sr-only")?.textContent).toBe("Claude: at its limit, resets 3:40 PM");
});
+ it("color the bars and each window's track green with room left, orange near the limit and red at it", () => {
+ const glyph = (limit: EngineLimit) => {
+ serve([limit]);
+ const ink = mount(createElement(UsageBars, { engine: "claude" })).querySelector("[data-usage-glyph]")?.getAttribute("class");
+ root!.unmount();
+ return ink;
+ };
+ expect([glyph(windows(38, 10)), glyph(claude(92)), glyph(claude(100, true))]).toEqual([
+ expect.stringContaining("text-success"), expect.stringContaining("text-warning"), expect.stringContaining("text-danger"),
+ ]);
+ const tracks = (limit: EngineLimit) => {
+ const fills = [...mount(createElement(UsageRows, { limit })).querySelectorAll("[data-usage-track]")].map((track) => track.className.match(/bg-\w+/)?.[0]);
+ root!.unmount();
+ return fills;
+ };
+ expect(tracks(windows(92, 20, { blocked: true, usedPercent: 100 }))).toEqual(["bg-danger", "bg-success"]);
+ expect(tracks(windows(95, 20))).toEqual(["bg-warning", "bg-success"]);
+ });
+
it("open every window in a card on a mouse hover, never on a touch, and keep the card's clicks from the model button", async () => {
serve([windows(38, 80)]);
const opened = vi.fn();