claude_quota_bar/lib.rs
1//! claude-quota-bar — fast Claude Code statusline.
2//!
3//! Library surface exists so integration tests can call into render paths
4//! without spawning the binary; the binary itself is a thin shell in
5//! `main.rs` that does stdin/file IO and delegates to these modules.
6
7pub mod ansi;
8pub mod cache;
9pub mod git;
10pub mod input;
11pub mod progress;
12pub mod render;
13pub mod theme;
14pub mod time_fmt;
15
16#[cfg(test)]
17pub(crate) mod test_env {
18 use std::sync::Mutex;
19 use tempfile::TempDir;
20
21 // HOME is process-global state: every test that swaps it must
22 // serialize through this ONE lock, no matter which module it lives in.
23 // Per-module locks (which cache.rs and the former session ledger each
24 // briefly had) still race each other under the parallel test runner and
25 // fail intermittently.
26 static ENV_LOCK: Mutex<()> = Mutex::new(());
27
28 pub fn with_temp_home<F: FnOnce(&TempDir)>(f: F) {
29 let _g = ENV_LOCK.lock().unwrap_or_else(|e| e.into_inner());
30 let home = TempDir::new().unwrap();
31 unsafe { std::env::set_var("HOME", home.path()) };
32 f(&home);
33 unsafe { std::env::remove_var("HOME") };
34 }
35}