| Crates.io | utls |
| lib.rs | utls |
| version | 0.13.10 |
| created_at | 2024-12-06 19:18:29.611446+00 |
| updated_at | 2024-12-16 23:37:06.769091+00 |
| description | A simple utilities library for stuff I actually use sometimes, with a large focus on convenience and lack of dependencies. |
| homepage | |
| repository | https://github.com/barely-a-dev/utls |
| max_upload_size | |
| id | 1474572 |
| size | 208,259 |
A Rust utility library providing thread-safe progress bars and value watching functionality.
Progress Bars: Highly customizable, thread-safe progress bars with:
Value Watcher: Thread-safe value monitoring system
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!");
}
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());
}
}
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 charactersProgress 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)Requires Rust nightly due to #![feature(unboxed_closures)].
See the /examples directory for more usage examples: