Skip to content

switch from humantime to jiff #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ include = ["src/**/*", "README.md", "LICENSE.md", "CHANGELOG.md"]
license = "MIT"
repository = "https://github.com/Byron/prodash"
readme = "README.md"
rust-version = "1.74"

[lib]
doctest = true
Expand Down Expand Up @@ -39,7 +40,7 @@ progress-tree-log = ["log"]
progress-log = ["log"]
unit-bytes = ["bytesize"]
unit-human = ["human_format"]
unit-duration = ["humantime"]
unit-duration = ["jiff"]
render-tui-crossterm = ["crosstermion/tui-react-crossterm", "crosstermion/input-async-crossterm"]
render-tui = ["tui",
"unicode-segmentation",
Expand All @@ -49,8 +50,8 @@ render-tui = ["tui",
"futures-lite",
"futures-core",
"async-io",
"humantime"]
render-line = ["crosstermion/color", "humantime", "unicode-width"]
"jiff"]
render-line = ["crosstermion/color", "jiff", "unicode-width"]
render-line-crossterm = ["crosstermion/crossterm"]
render-line-autoconfigure = ["is-terminal"]

Expand All @@ -69,14 +70,13 @@ tui = { package = "ratatui", version = "0.26.0", optional = true, default-featur
tui-react = { version = "0.23.0", optional = true }
futures-core = { version = "0.3.4", optional = true, default-features = false }
futures-lite = { version = "2.1.0", optional = true }
humantime = { version = "2.1.0", optional = true }
unicode-segmentation = { version = "1.6.0", optional = true }
unicode-width = { version = "0.1.7", optional = true }
crosstermion = { version = "0.14.0", optional = true, default-features = false }
async-io = { version = "2.2.1", optional = true }

# localtime support for render-tui
jiff = { version = "0.1.1", optional = true }
# localtime support for render-tui and duration formatting
jiff = { version = "0.2.4", optional = true }

# line renderer
ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This crate comes with various cargo features to tailor it to your needs.
* **unit-human**
* Display counts in a way that is easier to grasp for humans, using the tiny `human_format` crate.
* **unit-duration**
* Displays time in seconds like '_5m4s_' using the tiny `humantime` crate.
* Displays time in seconds like '_5m4s_' using the `jiff` crate's friendly duration format.

## Features

Expand Down
6 changes: 2 additions & 4 deletions examples/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
compile_error!(
"The `render-tui` feature must be set, along with either `render-tui-crossterm` or `render-tui-termion`"
);
#[cfg(not(any(feature = "render-tui-crossterm", feature = "render-tui-termion")))]
compile_error!(
"Please set either the 'render-tui-crossterm' or 'render-tui-termion' feature whne using the 'render-tui'"
);
#[cfg(not(any(feature = "render-tui-crossterm")))]
compile_error!("Please set the 'render-tui-crossterm' feature when using the 'render-tui'");

fn main() -> Result {
env_logger::init();
Expand Down
8 changes: 0 additions & 8 deletions examples/shared/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,9 @@ pub struct Options {
#[argh(option)]
pub line_end: Option<prodash::progress::key::Level>,

/// if set (default: false), we will stop running the TUI once there the list of drawable progress items is empty.
#[argh(switch)]
pub stop_if_empty_progress: bool,

/// set the renderer to use, defaults to "tui", and furthermore allows "line" and "log".
///
/// If set ot "log", there will only be logging. Set 'RUST_LOG=info' before running the program to see them.
#[argh(option, short = 'R')]
pub renderer: Option<String>,

/// has not effect - use the NO_COLOR environment variable instead.
#[argh(switch)]
pub no_line_color: bool,
}
10 changes: 3 additions & 7 deletions examples/units.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#![deny(unsafe_code)]

#[cfg(not(feature = "render-tui"))]
compile_error!(
"The `render-tui` feature must be set, along with either `render-tui-crossterm` or `render-tui-termion`"
);
#[cfg(not(any(feature = "render-tui-crossterm", feature = "render-tui-termion")))]
compile_error!(
"Please set either the 'render-tui-crossterm' or 'render-tui-termion' feature whne using the 'render-tui'"
);
compile_error!("The `render-tui` feature must be set, along with the `render-tui-crossterm`");
#[cfg(not(any(feature = "render-tui-crossterm")))]
compile_error!("Please set the 'render-tui-crossterm' feature when using the 'render-tui'");

use std::{error::Error, sync::Arc};

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![deny(unsafe_code, missing_docs)]
#![allow(clippy::empty_docs)]

/*!
Prodash is a dashboard for displaying the progress of concurrent application.
Expand Down Expand Up @@ -46,7 +47,7 @@ pub use log::info;
#[cfg(feature = "progress-tree-log")]
pub use log::warn;

#[cfg(any(feature = "humantime", feature = "local-time"))]
#[cfg(any(feature = "jiff", feature = "local-time"))]
///
pub mod time;

Expand Down
4 changes: 2 additions & 2 deletions src/render/line/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
pub output_is_terminal: bool,
pub colored: bool,
pub timestamp: bool,
pub hide_cursor: bool,

Check warning on line 64 in src/render/line/draw.rs

View workflow job for this annotation

GitHub Actions / build-and-test-on-windows

field `hide_cursor` is never read

Check warning on line 64 in src/render/line/draw.rs

View workflow job for this annotation

GitHub Actions / build-and-test-on-windows

field `hide_cursor` is never read

Check warning on line 64 in src/render/line/draw.rs

View workflow job for this annotation

GitHub Actions / build-and-test-linux

field `hide_cursor` is never read
}

fn messages(
Expand Down Expand Up @@ -149,7 +149,7 @@
let level_range = config
.level_filter
.clone()
.unwrap_or(RangeInclusive::new(0, progress::key::Level::max_value()));
.unwrap_or(RangeInclusive::new(0, progress::key::Level::MAX));
let lines_to_be_drawn = state
.tree
.iter()
Expand Down Expand Up @@ -253,7 +253,7 @@
const CHARS: [char; 6] = ['=', '=', '=', ' ', ' ', ' '];
buf.push(
styled_brush.paint(
(p.step.load(Ordering::SeqCst)..std::usize::MAX)
(p.step.load(Ordering::SeqCst)..usize::MAX)
.take(blocks_available as usize)
.map(|idx| CHARS[idx % CHARS.len()])
.rev()
Expand Down
7 changes: 2 additions & 5 deletions src/render/line/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#[cfg(all(
feature = "render-line",
not(any(feature = "render-line-crossterm", feature = "render-line-termion"))
))]
compile_error!("Please choose either one of these features: 'render-line-crossterm' or 'render-line-termion'");
#[cfg(all(feature = "render-line", not(any(feature = "render-line-crossterm"))))]
compile_error!("Please use the 'render-line-crossterm' feature");

mod draw;
mod engine;
Expand Down
16 changes: 6 additions & 10 deletions src/render/tui/draw/progress.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use std::{
fmt,
sync::atomic::Ordering,
time::{Duration, SystemTime},
};
use std::{fmt, sync::atomic::Ordering, time::Duration};

use humantime::format_duration;
use tui::{
buffer::Buffer,
layout::Rect,
Expand Down Expand Up @@ -145,7 +140,7 @@ pub(crate) fn headline(

struct ProgressFormat<'a>(&'a Option<Value>, u16, Option<unit::display::Throughput>);

impl<'a> fmt::Display for ProgressFormat<'a> {
impl fmt::Display for ProgressFormat<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0 {
Some(p) => match p.unit.as_ref() {
Expand Down Expand Up @@ -300,13 +295,14 @@ fn add_block_eta(state: progress::State, progress_text: &mut String) {
progress_text.push_str(reason);
progress_text.push(']');
if let Some(eta) = maybe_eta {
let now = SystemTime::now();
let eta = jiff::Timestamp::try_from(eta).expect("reasonable system time");
let now = jiff::Timestamp::now();
if eta > now {
use std::fmt::Write;
write!(
progress_text,
" → {} to {}",
format_duration(eta.duration_since(now).expect("computation to work")),
" → {:#} to {}",
eta.duration_since(now),
if let progress::State::Blocked(_, _) = state {
"unblock"
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/render/tui/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ pub(crate) enum InterruptDrawInfo {
Deferred(bool),
}

#[cfg(not(any(feature = "render-tui-crossterm", feature = "render-tui-termion")))]
compile_error!(
"Please set either the 'render-tui-crossterm' or 'render-tui-termion' feature whne using the 'render-tui'"
);
#[cfg(not(any(feature = "render-tui-crossterm")))]
compile_error!("Please set the 'render-tui-crossterm' feature when using the 'render-tui'");

use crosstermion::crossterm::event::{KeyCode, KeyEventKind, KeyModifiers};
use crosstermion::{
Expand Down
15 changes: 3 additions & 12 deletions src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,21 @@
mod utc {
use std::time::SystemTime;

use super::DATE_TIME_HMS;

Check warning on line 32 in src/time.rs

View workflow job for this annotation

GitHub Actions / build-and-test-on-windows

unused import: `super::DATE_TIME_HMS`

Check warning on line 32 in src/time.rs

View workflow job for this annotation

GitHub Actions / build-and-test-on-windows

unused import: `super::DATE_TIME_HMS`

Check warning on line 32 in src/time.rs

View workflow job for this annotation

GitHub Actions / build-and-test-linux

unused import: `super::DATE_TIME_HMS`
const DATE_TIME_YMD: usize = "2020-02-13T".len();

/// Return a string representing the current date and time as UTC.
///
/// Available without the `localtime` feature toggle.
pub fn format_time_for_messages(time: SystemTime) -> String {
String::from_utf8_lossy(
&humantime::format_rfc3339_seconds(time).to_string().as_bytes()
[DATE_TIME_YMD..DATE_TIME_YMD + DATE_TIME_HMS],
)
.into_owned()
let time = jiff::Timestamp::try_from(time).expect("reasonable system time");
time.strftime("%T").to_string()
}

/// Return a string representing the current time as UTC.
///
/// Available without the `localtime` feature toggle.
pub fn format_now_datetime_seconds() -> String {
String::from_utf8_lossy(
&humantime::format_rfc3339_seconds(std::time::SystemTime::now())
.to_string()
.as_bytes()[.."2020-02-13T00:51:45".len()],
)
.into_owned()
jiff::Timestamp::now().strftime("%FT%T").to_string()
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ mod impls {

pub trait Sealed {}

impl<'a, T> Count for &'a T
impl<T> Count for &T
where
T: Count + ?Sized,
{
Expand All @@ -268,7 +268,7 @@ mod impls {
}
}

impl<'a, T> Count for &'a mut T
impl<T> Count for &mut T
where
T: Count + ?Sized,
{
Expand All @@ -293,7 +293,7 @@ mod impls {
}
}

impl<'a, T> Progress for &'a mut T
impl<T> Progress for &mut T
where
T: Progress + ?Sized,
{
Expand Down Expand Up @@ -350,7 +350,7 @@ mod impls {
}
}

impl<'a, T> NestedProgress for &'a mut T
impl<T> NestedProgress for &mut T
where
T: NestedProgress + ?Sized,
{
Expand Down
4 changes: 2 additions & 2 deletions src/unit/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl What {
}
}

impl<'a> UnitDisplay<'a> {
impl UnitDisplay<'_> {
/// Display everything, values and the unit.
pub fn all(&mut self) -> &Self {
self.display = What::ValuesAndUnit;
Expand All @@ -135,7 +135,7 @@ impl<'a> UnitDisplay<'a> {
}
}

impl<'a> fmt::Display for UnitDisplay<'a> {
impl fmt::Display for UnitDisplay<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let unit: &dyn DisplayValue = self.parent.as_display_value();
let mode = self.parent.mode;
Expand Down
10 changes: 5 additions & 5 deletions src/unit/duration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::{fmt, time};

use humantime::format_duration;
use std::fmt;

use crate::{progress::Step, unit::DisplayValue};

Expand All @@ -10,13 +8,15 @@ pub struct Duration;

impl DisplayValue for Duration {
fn display_current_value(&self, w: &mut dyn fmt::Write, value: Step, _upper: Option<Step>) -> fmt::Result {
w.write_str(&format_duration(time::Duration::new(value as u64, 0)).to_string())
let dur = jiff::SignedDuration::from_secs(value as i64);
w.write_str(&format!("{dur:#}"))
}
fn separator(&self, w: &mut dyn fmt::Write, _value: Step, _upper: Option<Step>) -> fmt::Result {
w.write_str(" of ")
}
fn display_upper_bound(&self, w: &mut dyn fmt::Write, upper_bound: Step, _value: Step) -> fmt::Result {
w.write_str(&format_duration(time::Duration::new(upper_bound as u64, 0)).to_string())
let dur = jiff::SignedDuration::from_secs(upper_bound as i64);
w.write_str(&format!("{dur:#}"))
}

fn dyn_hash(&self, state: &mut dyn std::hash::Hasher) {
Expand Down
Loading