Expand description
ai-usagebar library — shared core for the Waybar widget and TUI binaries.
The crate is organized by concern, not by binary:
- low-level primitives (
cache,countdown,pacing,pango,theme) - the vendor abstraction (
vendor,vendors::*,usage) - bin-specific composition (
widget,tui) which lives next to its binary
The two binaries (ai-usagebar and ai-usagebar-tui) are thin: they parse
CLI args, instantiate vendors, and hand off to a renderer in this crate.
Re-exports§
Modules§
- active
- Active-vendor state file. Set by
--cycle-next/--cycle-prev(which Waybar’son-scroll-up/on-scroll-downinvoke), read by the widget on every tick. The TUI does NOT consult this — it has its own tab state. - anthropic
- Anthropic vendor — OAuth-based plan usage via the undocumented
https://api.anthropic.com/api/oauth/usageendpoint. - cache
- Per-vendor on-disk cache with atomic writes, TTL checks, and inter-process locking.
- config
- Config file at
~/.config/ai-usagebar/config.toml. - countdown
- Human-readable countdown between two instants.
- error
- Shared error type. Vendors and renderers convert their failures into
AppErrorso the widget shell can decide whether to retry, fall back to cache, show ⚠, or show “Loading…”. - format
{placeholder}substitution for--formatand--tooltip-format.- openai
- OpenAI vendor — Codex OAuth via
~/.codex/auth.json+ the undocumentedchatgpt.com/backend-api/wham/usageendpoint. Reference:~/Projects/codexbar/codexbarby the same author as claudebar. - openrouter
- OpenRouter vendor —
/api/v1/creditsand/api/v1/keyover an API key. - pacing
- Pacing math — encodes claudebar’s
calc_pacing(claudebar:279-321) andpace_color_for(claudebar:212-219) as pure functions. - pango
- Pango-markup rendering helpers shared by the widget bar text and tooltip.
- theme
- Color palette resolution.
- tooltip
- Pango-bordered tooltip primitives shared by every vendor renderer.
- tui
- TUI binary support — ratatui app with one tab per enabled vendor.
- usage
- Canonical in-memory representation of “how much have I used my plan”.
- vendor
- Shared vendor IDs and renderer/fetcher structs used by the widget and TUI.
- waybar
- Waybar JSON output:
{text, tooltip, class}. - widget
- Widget binary support: CLI parsing, per-vendor rendering, the always-exit-0
wrapper, and the local-testing renderers (
--pretty,--watch,--json). - zai
- Z.AI / BigModel vendor — undocumented
/api/monitor/usage/quota/limit. Auth header isAuthorization: <KEY>with NOBearerprefix.