# Utils (utls)
A Rust utility library providing thread-safe progress bars and value watching functionality.
## Features
- **Progress Bars**: Highly customizable, thread-safe progress bars with:
- Multiple built-in styles (Classic, Modern, Minimal, Fancy, ASCII, Dots, Arrows, Box)
- Customizable appearance and behavior
- Real-time statistics tracking
- Spinner animations
- Threading support
- Formatted message templates
- **Value Watcher**: Thread-safe value monitoring system
## Usage Examples
### Progress Bar
```rust
use utls::prog::PB;
use std::thread;
use std::time::Duration;
fn main() {
let pb = PB::modern(100); // Create a modern style progress bar with 100 steps
let (handle, pb_ref) = pb.threaded_start(); // Start the bar rendering in a new thread
PB::inc_until_arc(pb_ref.clone(), || { // Run the Fn closure then increment until the bar finishes
thread::sleep(Duration::from_millis(10)); // (or some work)
});
handle.join().unwrap();
pb_ref.lock().unwrap().finish_with_message("Complete!");
}
```
### Value Watcher
```rust
use utls::watcher::Watcher;
use std::sync::{atomic::AtomicBool, Arc, Mutex};
fn main() {
let shutdown = Arc::new(Mutex::new(AtomicBool::new(false)));
let watcher = Watcher::new(0, 100, shutdown); // Initial value 0, poll every 100ms
watcher.set_value(42);
if watcher.has_changed() {
println!("Value changed to: {}", watcher.get_value());
}
}
```
## Progress Bar Styles
- `PB::classic()` - Traditional ASCII style
- `PB::modern()` - Unicode blocks style
- `PB::minimal()` - Minimalistic appearance
- `PB::fancy()` - Decorative Unicode style
- `PB::ascii()` - Pure ASCII characters
- `PB::dots()` - Braille pattern style
- `PB::arrows()` - Arrow-based style
- `PB::box_heavy()` - Heavy box drawing characters
## Message Formatting
Progress bars support the following template variables in messages if formatting is enabled:
- `{p}` - Progress percentage
- `{c}` - Current value
- `{m}` - Maximum value
- `{e}` - Elapsed time
- `{r}` - Estimated remaining time (highly inaccurate)
#### Note: enabling formatting can decrease performance
## Building
Requires Rust nightly due to `#![feature(unboxed_closures)]`.
## Examples
See the `/examples` directory for more usage examples:
- Progress bar demos: [PB](/examples/pb/)
- Watcher demos: [Watcher](/examples/watcher/)
## License
[License](LICENSE)