Skip to content

Commit

Permalink
release: 0.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Sep 10, 2022
2 parents 9a9b4f8 + 0d58368 commit 796efc0
Show file tree
Hide file tree
Showing 20 changed files with 168 additions and 55 deletions.
12 changes: 6 additions & 6 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Project Dependencies
Package: fyi
Version: 0.10.0
Generated: 2022-08-23 20:18:50 UTC
Version: 0.10.1
Generated: 2022-09-10 19:52:19 UTC

| Package | Version | Author(s) | License |
| ---- | ---- | ---- | ---- |
| [argyle](https://github.com/Blobfolio/argyle) | 0.6.2 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [const_fn](https://github.com/taiki-e/const_fn) | 0.4.9 | | Apache-2.0 or MIT |
| [dactyl](https://github.com/Blobfolio/dactyl) | 0.4.2 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.10.0 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [dactyl](https://github.com/Blobfolio/dactyl) | 0.4.5 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [fyi_msg](https://github.com/Blobfolio/fyi) | 0.10.1 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [num-traits](https://github.com/rust-num/num-traits) | 0.2.15 | The Rust Project Developers | Apache-2.0 or MIT |
| [once_cell](https://github.com/matklad/once_cell) | 1.13.1 | [Aleksey Kladov](mailto:aleksey.kladov@gmail.com) | Apache-2.0 or MIT |
| [once_cell](https://github.com/matklad/once_cell) | 1.14.0 | [Aleksey Kladov](mailto:aleksey.kladov@gmail.com) | Apache-2.0 or MIT |
| [tz-rs](https://github.com/x-hgg-x/tz-rs) | 0.6.14 | x-hgg-x | Apache-2.0 or MIT |
| [utc2k](https://github.com/Blobfolio/utc2k) | 0.5.7 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
| [utc2k](https://github.com/Blobfolio/utc2k) | 0.5.8 | [Blobfolio, LLC.](mailto:hello@blobfolio.com) | WTFPL |
2 changes: 1 addition & 1 deletion fyi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fyi"
version = "0.10.0"
version = "0.10.1"
license = "WTFPL"
authors = ["Blobfolio, LLC. <hello@blobfolio.com>"]
edition = "2021"
Expand Down
3 changes: 2 additions & 1 deletion fyi_msg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fyi_msg"
version = "0.10.0"
version = "0.10.1"
authors = ["Blobfolio, LLC. <hello@blobfolio.com>"]
edition = "2021"
rust-version = "1.62"
Expand All @@ -20,6 +20,7 @@ dactyl = "0.4.*, >= 0.4.2"

[dependencies.ahash]
version = "=0.8.0"
default-features = false
optional = true

[dependencies.bytecount]
Expand Down
29 changes: 28 additions & 1 deletion fyi_msg/examples/progless-par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn main() {
#[cfg(feature = "progress")]
/// # Do it.
fn main() {
use dactyl::NiceU16;
use fyi_msg::Progless;
use rayon::prelude::*;
use std::time::Duration;
Expand All @@ -40,7 +41,33 @@ fn main() {
pbar.remove(txt);
});

// Print a simple summary.
// Let's do it again! We could start a new Progless, but let's keep the
// original one going instead.
let nums: Vec<u16> = (10_000_u16..11_000_u16).collect();

// This would only fail if the new total is zero, which we know is not the
// case here.
pbar.reset(nums.len() as u32).unwrap();

// Change the title.
pbar.set_title(Some(Msg::custom("Crunching", 199, "Playing with numbers now…")));

// Loop through the new tasks.
nums.into_par_iter()
.for_each(|n| {
let nice = NiceU16::from(n);
pbar.add(nice.as_str());

// Simulate work.
std::thread::sleep(Duration::from_millis(100));

pbar.remove(nice.as_str());
});

// We're really done now.
pbar.finish();

// Print a generic summary. The nicer `Progless::summary` summary would
// only reflect the last incarnation, which isn't helpful here.
Msg::from(pbar).print();
}
78 changes: 67 additions & 11 deletions fyi_msg/src/progress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const AHASH_STATE: RandomState = RandomState::with_seeds(13, 19, 23, 71);
/// last tick, saving the overhead of recalculating the buffer values each time
/// a value changes. (Instead they're only recalculated at most once per tick.)
const TICK_NEW: u8 = 0b0110_0001;
const TICK_RESET: u8 = 0b0110_1111;
const TICK_RESIZED: u8 = 0b0001_0011;

const TICK_BAR: u8 = 0b0000_0001;
Expand Down Expand Up @@ -158,7 +159,7 @@ struct ProglessInner {
title: Mutex<Option<Msg>>,
done: AtomicU32,
doing: Mutex<HashSet<ProglessTask, RandomState>>,
total: NonZeroU32,
total: AtomicU32,
}

impl From<NonZeroU32> for ProglessInner {
Expand Down Expand Up @@ -237,7 +238,7 @@ impl From<NonZeroU32> for ProglessInner {
title: Mutex::new(None),
done: AtomicU32::new(0),
doing: Mutex::new(HashSet::with_hasher(AHASH_STATE)),
total,
total: AtomicU32::new(total.get()),
}
}
}
Expand Down Expand Up @@ -266,7 +267,7 @@ impl ProglessInner {
fn stop(&self) {
if self.running() {
self.flags.store(0, SeqCst);
self.done.store(self.total.get(), SeqCst);
self.done.store(self.total(), SeqCst);
self.elapsed.store(
u32::saturating_from(self.started.elapsed().as_millis()),
SeqCst
Expand All @@ -291,7 +292,7 @@ impl ProglessInner {
/// `0.0..=1.0`.
fn percent(&self) -> f64 {
let done = self.done();
let total = self.total.get();
let total = self.total();

if done == 0 { 0.0 }
else if done == total { 1.0 }
Expand All @@ -309,6 +310,12 @@ impl ProglessInner {
/// For the most part, this struct's setter methods only work while
/// progress is happening; after that they're frozen.
fn running(&self) -> bool { 0 != self.flags.load(SeqCst) & TICKING }

#[inline]
/// # Total.
///
/// The total number of tasks.
fn total(&self) -> u32 { self.total.load(SeqCst) }
}

/// # Setters.
Expand Down Expand Up @@ -341,7 +348,7 @@ impl ProglessInner {
fn increment(&self) {
if self.running() {
let done = self.done.fetch_add(1, SeqCst) + 1;
if done >= self.total.get() { self.stop() }
if done >= self.total() { self.stop() }
else {
self.flags.fetch_or(TICK_DONE | TICK_PERCENT | TICK_BAR, SeqCst);
}
Expand All @@ -361,14 +368,39 @@ impl ProglessInner {
}
}

/// # Reset.
///
/// Stop the current run (if any), clear the done/doing metrics, and assign
/// a new total so you can re-use the [`Progless`] instance for a new set
/// of tasks.
///
/// Note: the start/elapsed times for a given [`Progless`] instance are
/// _continuous_. If you need the time counter to reset to `[00:00:00]`,
/// you need start a brand new instance instead of resetting an existing
/// one.
///
/// ## Errors
///
/// This will return an error if the new total is zero.
fn reset(&self, total: u32) -> Result<(), ProglessError> {
self.stop();
if 0 == total { Err(ProglessError::EmptyTotal) }
else {
self.total.store(total, SeqCst);
self.done.store(0, SeqCst);
self.flags.store(TICK_RESET, SeqCst);
Ok(())
}
}

/// # Set Done.
///
/// Set the done count to a specific value. Be careful in cases where
/// things are happening in parallel; in such cases `increment` is probably
/// better.
fn set_done(&self, done: u32) {
if self.running() && done != self.done.swap(done, SeqCst) {
if done >= self.total.get() { self.stop(); }
if done >= self.total() { self.stop(); }
else {
self.flags.fetch_or(TICK_DONE | TICK_PERCENT | TICK_BAR, SeqCst);
}
Expand Down Expand Up @@ -582,7 +614,7 @@ impl ProglessInner {
}));
if space < MIN_BARS_WIDTH { return (0, 0); }

let total = self.total.get();
let total = self.total();
if 0 == total { return (0, 0); }

// Done!
Expand Down Expand Up @@ -729,7 +761,7 @@ impl ProglessInner {
/// This updates the "total" portion of the buffer as needed.
fn tick_set_total(&self) {
if self.flag_unset(TICK_TOTAL) {
mutex!(self.buf).replace(PART_TOTAL, &NiceU32::from(self.total));
mutex!(self.buf).replace(PART_TOTAL, &NiceU32::from(self.total()));
}
}

Expand Down Expand Up @@ -793,7 +825,7 @@ impl ProglessInner {
/// with the progress. Removing a task automatically increments the done count,
/// so if you're tracking tasks, you should *not* call [`Progless::increment`].
///
/// ```ignore
/// ```no_run
/// # use fyi_msg::Progless;
/// # use rayon::prelude::*;
///
Expand All @@ -802,14 +834,14 @@ impl ProglessInner {
/// // ... snip
///
/// // Iterate in Parallel.
/// for i in (0..1001).par_iter() {
/// (0..1001).into_par_iter().for_each(|i| {
/// let task: String = format!("Task #{}.", i);
/// pbar.add(&task);
///
/// // Do some work.
///
/// pbar.remove(&task);
/// }
/// });
///
/// // ... snip
/// ```
Expand Down Expand Up @@ -1020,6 +1052,10 @@ impl Progless {
/// If you just want a generic "Finished in X." message, use [`Msg::from`]
/// instead.
///
/// Note: if you called [`Progless::reset`] anywhere along the way, this
/// won't include totals from the previous run(s). (The duration is the
/// only constant.)
///
/// ## Examples
///
/// ```no_run
Expand Down Expand Up @@ -1111,6 +1147,26 @@ impl Progless {
pub fn remove<S>(&self, txt: S)
where S: AsRef<str> { self.inner.remove(txt); }

/// # Reset.
///
/// Stop the current run (if any), clear the done/doing metrics, and assign
/// a new total so you can re-use the [`Progless`] instance for a new set
/// of tasks.
///
/// Note: the start/elapsed times for a given [`Progless`] instance are
/// _continuous_. If you need the time counter to reset to `[00:00:00]`,
/// you need start a brand new instance instead of resetting an existing
/// one.
///
/// ## Errors
///
/// This will return an error if the new total is zero.
pub fn reset(&self, total: u32) -> Result<(), ProglessError> {
self.inner.reset(total)?;
self.steady.start(self.inner.clone());
Ok(())
}

#[inline]
/// # Set Done.
///
Expand Down
43 changes: 36 additions & 7 deletions fyi_msg/src/progress/steady.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use std::{
Arc,
atomic::{
AtomicBool,
Ordering::Relaxed,
Ordering::{
Relaxed,
SeqCst,
},
},
},
thread::JoinHandle,
Expand All @@ -21,6 +24,10 @@ use super::{



const SLEEP: Duration = Duration::from_millis(30);



#[derive(Debug)]
/// # Steady Ticker.
///
Expand All @@ -41,17 +48,16 @@ pub(super) struct ProglessSteady {

impl From<Arc<ProglessInner>> for ProglessSteady {
fn from(t_inner: Arc<ProglessInner>) -> Self {
const SLEEP: Duration = Duration::from_millis(30);
let dead = Arc::new(AtomicBool::new(false));
let t_dead = Arc::clone(&dead);

Self {
dead,
ticker: Mutex::new(Some(std::thread::spawn(move || loop {
// This will abort if we've manually shut off the "enabled"
// field, or if "inner" has reached 100%. Otherwise this will
// initiate a "tick", which may or may not paint an update to
// the CLI.
// This will abort if we've manually turned "dead" on, or if
// "inner" has reached 100%. Until then, this will initiate a
// steady "tick", which may or may not paint an update to the
// CLI.
if t_dead.load(Relaxed) || ! t_inner.tick() { break; }

// Sleep for a short while before checking again.
Expand All @@ -64,13 +70,36 @@ impl From<Arc<ProglessInner>> for ProglessSteady {
}

impl ProglessSteady {
/// # Start.
///
/// Make sure the steady ticker is running.
pub(super) fn start(&self, t_inner: Arc<ProglessInner>) {
// Make sure the old steady ticker is dead.
self.stop();

// Reset!
self.dead.store(false, SeqCst);
let t_dead = self.dead.clone();
mutex!(self.ticker).replace(std::thread::spawn(move || loop {
// This will abort if we've manually turned "dead" on, or if
// "inner" has reached 100%. Until then, this will initiate a
// steady "tick", which may or may not paint an update to the CLI.
if t_dead.load(Relaxed) || ! t_inner.tick() { break; }

// Sleep for a short while before checking again.
std::thread::sleep(SLEEP);
if t_dead.load(Relaxed) { break; }
std::thread::sleep(SLEEP);
}));
}

/// # Stop.
///
/// Make sure the steady ticker has actually aborted. This is called
/// automatically when [`Progless::finish`] is called.
pub(super) fn stop(&self) {
if let Some(handle) = mutex!(self.ticker).take() {
self.dead.store(true, Relaxed);
self.dead.store(true, SeqCst);
handle.join().unwrap();
}
}
Expand Down
4 changes: 2 additions & 2 deletions release/man/fyi-blank.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FYI BLANK" "1" "August 2022" "blank v0.10.0" "User Commands"
.TH "FYI BLANK" "1" "September 2022" "blank v0.10.1" "User Commands"
.SH NAME
blank \- Manual page for blank v0.10.0.
blank \- Manual page for blank v0.10.1.
.SH DESCRIPTION
Print blank line(s).
.SS USAGE:
Expand Down
4 changes: 2 additions & 2 deletions release/man/fyi-confirm.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FYI CONFIRM" "1" "August 2022" "confirm v0.10.0" "User Commands"
.TH "FYI CONFIRM" "1" "September 2022" "confirm v0.10.1" "User Commands"
.SH NAME
confirm \- Manual page for confirm v0.10.0.
confirm \- Manual page for confirm v0.10.1.
.SH DESCRIPTION
Ask a Yes/No question using the built\-in prefix "confirm".
.SS USAGE:
Expand Down
4 changes: 2 additions & 2 deletions release/man/fyi-crunched.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FYI CRUNCHED" "1" "August 2022" "crunched v0.10.0" "User Commands"
.TH "FYI CRUNCHED" "1" "September 2022" "crunched v0.10.1" "User Commands"
.SH NAME
crunched \- Manual page for crunched v0.10.0.
crunched \- Manual page for crunched v0.10.1.
.SH DESCRIPTION
Crunched: Hello World
.SS USAGE:
Expand Down
4 changes: 2 additions & 2 deletions release/man/fyi-debug.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.TH "FYI DEBUG" "1" "August 2022" "debug v0.10.0" "User Commands"
.TH "FYI DEBUG" "1" "September 2022" "debug v0.10.1" "User Commands"
.SH NAME
debug \- Manual page for debug v0.10.0.
debug \- Manual page for debug v0.10.1.
.SH DESCRIPTION
Debug: Hello World
.SS USAGE:
Expand Down

0 comments on commit 796efc0

Please sign in to comment.