6 releases (breaking)
new 0.9.7 | Dec 10, 2024 |
---|---|
0.8.7 | Dec 7, 2024 |
0.7.6 | Dec 6, 2024 |
0.6.5 | Dec 6, 2024 |
0.5.5 | Dec 6, 2024 |
#293 in Development tools
428 downloads per month
68KB
1.5K
SLoC
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
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
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 stylePB::modern()
- Unicode blocks stylePB::minimal()
- Minimalistic appearancePB::fancy()
- Decorative Unicode stylePB::ascii()
- Pure ASCII charactersPB::dots()
- Braille pattern stylePB::arrows()
- Arrow-based stylePB::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: