utls

Crates.ioutls
lib.rsutls
version
sourcesrc
created_at2024-12-06 19:18:29.611446
updated_at2024-12-12 20:26:05.677359
descriptionA simple utilities library for stuff I actually use sometimes, with a large focus on convenience and lack of dependencies.
homepage
repositoryhttps://github.com/barely-a-dev/utls
max_upload_size
id1474572
Cargo.toml error:TOML parse error at line 23, column 1 | 23 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
(barely-a-dev)

documentation

https://docs.rs/utls

README

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 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
  • Watcher demos: Watcher

License

License

Commit count: 0

cargo fmt