Skip to main content

Crate ai_usagebar

Crate ai_usagebar 

Source
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§

pub use error::AppError;
pub use error::Result;

Modules§

active
Active-vendor state file. Set by --cycle-next / --cycle-prev (which Waybar’s on-scroll-up/on-scroll-down invoke), 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/usage endpoint.
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.
deepseek
error
Shared error type. Vendors and renderers convert their failures into AppError so the widget shell can decide whether to retry, fall back to cache, show ⚠, or show “Loading…”.
format
{placeholder} substitution for --format and --tooltip-format.
openai
OpenAI vendor — Codex OAuth via ~/.codex/auth.json + the undocumented chatgpt.com/backend-api/wham/usage endpoint. Reference: ~/Projects/codexbar/codexbar by the same author as claudebar.
openrouter
OpenRouter vendor — /api/v1/credits and /api/v1/key over an API key.
pacing
Pacing math — encodes claudebar’s calc_pacing (claudebar:279-321) and pace_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 is Authorization: <KEY> with NO Bearer prefix.