Skip to content

Commit eaf1c26

Browse files
authored
Merge pull request #32 from BurntSushi/ag/moar-jiff
switch from `humantime` to `jiff`
2 parents 9c476cf + 521c6e1 commit eaf1c26

File tree

14 files changed

+40
-71
lines changed

14 files changed

+40
-71
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ include = ["src/**/*", "README.md", "LICENSE.md", "CHANGELOG.md"]
88
license = "MIT"
99
repository = "https://github.com/Byron/prodash"
1010
readme = "README.md"
11+
rust-version = "1.74"
1112

1213
[lib]
1314
doctest = true
@@ -39,7 +40,7 @@ progress-tree-log = ["log"]
3940
progress-log = ["log"]
4041
unit-bytes = ["bytesize"]
4142
unit-human = ["human_format"]
42-
unit-duration = ["humantime"]
43+
unit-duration = ["jiff"]
4344
render-tui-crossterm = ["crosstermion/tui-react-crossterm", "crosstermion/input-async-crossterm"]
4445
render-tui = ["tui",
4546
"unicode-segmentation",
@@ -49,8 +50,8 @@ render-tui = ["tui",
4950
"futures-lite",
5051
"futures-core",
5152
"async-io",
52-
"humantime"]
53-
render-line = ["crosstermion/color", "humantime", "unicode-width"]
53+
"jiff"]
54+
render-line = ["crosstermion/color", "jiff", "unicode-width"]
5455
render-line-crossterm = ["crosstermion/crossterm"]
5556
render-line-autoconfigure = ["is-terminal"]
5657

@@ -69,14 +70,13 @@ tui = { package = "ratatui", version = "0.26.0", optional = true, default-featur
6970
tui-react = { version = "0.23.0", optional = true }
7071
futures-core = { version = "0.3.4", optional = true, default-features = false }
7172
futures-lite = { version = "2.1.0", optional = true }
72-
humantime = { version = "2.1.0", optional = true }
7373
unicode-segmentation = { version = "1.6.0", optional = true }
7474
unicode-width = { version = "0.1.7", optional = true }
7575
crosstermion = { version = "0.14.0", optional = true, default-features = false }
7676
async-io = { version = "2.2.1", optional = true }
7777

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

8181
# line renderer
8282
ctrlc = { version = "3.1.4", optional = true, default-features = false, features = ['termination'] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ This crate comes with various cargo features to tailor it to your needs.
7171
* **unit-human**
7272
* Display counts in a way that is easier to grasp for humans, using the tiny `human_format` crate.
7373
* **unit-duration**
74-
* Displays time in seconds like '_5m4s_' using the tiny `humantime` crate.
74+
* Displays time in seconds like '_5m4s_' using the `jiff` crate's friendly duration format.
7575

7676
## Features
7777

examples/dashboard.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
compile_error!(
55
"The `render-tui` feature must be set, along with either `render-tui-crossterm` or `render-tui-termion`"
66
);
7-
#[cfg(not(any(feature = "render-tui-crossterm", feature = "render-tui-termion")))]
8-
compile_error!(
9-
"Please set either the 'render-tui-crossterm' or 'render-tui-termion' feature whne using the 'render-tui'"
10-
);
7+
#[cfg(not(any(feature = "render-tui-crossterm")))]
8+
compile_error!("Please set the 'render-tui-crossterm' feature when using the 'render-tui'");
119

1210
fn main() -> Result {
1311
env_logger::init();

examples/shared/args.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,9 @@ pub struct Options {
6363
#[argh(option)]
6464
pub line_end: Option<prodash::progress::key::Level>,
6565

66-
/// if set (default: false), we will stop running the TUI once there the list of drawable progress items is empty.
67-
#[argh(switch)]
68-
pub stop_if_empty_progress: bool,
69-
7066
/// set the renderer to use, defaults to "tui", and furthermore allows "line" and "log".
7167
///
7268
/// If set ot "log", there will only be logging. Set 'RUST_LOG=info' before running the program to see them.
7369
#[argh(option, short = 'R')]
7470
pub renderer: Option<String>,
75-
76-
/// has not effect - use the NO_COLOR environment variable instead.
77-
#[argh(switch)]
78-
pub no_line_color: bool,
7971
}

examples/units.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#![deny(unsafe_code)]
22

33
#[cfg(not(feature = "render-tui"))]
4-
compile_error!(
5-
"The `render-tui` feature must be set, along with either `render-tui-crossterm` or `render-tui-termion`"
6-
);
7-
#[cfg(not(any(feature = "render-tui-crossterm", feature = "render-tui-termion")))]
8-
compile_error!(
9-
"Please set either the 'render-tui-crossterm' or 'render-tui-termion' feature whne using the 'render-tui'"
10-
);
4+
compile_error!("The `render-tui` feature must be set, along with the `render-tui-crossterm`");
5+
#[cfg(not(any(feature = "render-tui-crossterm")))]
6+
compile_error!("Please set the 'render-tui-crossterm' feature when using the 'render-tui'");
117

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

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![deny(unsafe_code, missing_docs)]
2+
#![allow(clippy::empty_docs)]
23

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

49-
#[cfg(any(feature = "humantime", feature = "local-time"))]
50+
#[cfg(any(feature = "jiff", feature = "local-time"))]
5051
///
5152
pub mod time;
5253

src/render/line/draw.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub fn all(out: &mut impl io::Write, show_progress: bool, state: &mut State, con
149149
let level_range = config
150150
.level_filter
151151
.clone()
152-
.unwrap_or(RangeInclusive::new(0, progress::key::Level::max_value()));
152+
.unwrap_or(RangeInclusive::new(0, progress::key::Level::MAX));
153153
let lines_to_be_drawn = state
154154
.tree
155155
.iter()
@@ -253,7 +253,7 @@ fn draw_progress_bar(p: &Value, style: Style, mut blocks_available: u16, colored
253253
const CHARS: [char; 6] = ['=', '=', '=', ' ', ' ', ' '];
254254
buf.push(
255255
styled_brush.paint(
256-
(p.step.load(Ordering::SeqCst)..std::usize::MAX)
256+
(p.step.load(Ordering::SeqCst)..usize::MAX)
257257
.take(blocks_available as usize)
258258
.map(|idx| CHARS[idx % CHARS.len()])
259259
.rev()

src/render/line/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
#[cfg(all(
2-
feature = "render-line",
3-
not(any(feature = "render-line-crossterm", feature = "render-line-termion"))
4-
))]
5-
compile_error!("Please choose either one of these features: 'render-line-crossterm' or 'render-line-termion'");
1+
#[cfg(all(feature = "render-line", not(any(feature = "render-line-crossterm"))))]
2+
compile_error!("Please use the 'render-line-crossterm' feature");
63

74
mod draw;
85
mod engine;

src/render/tui/draw/progress.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
use std::{
2-
fmt,
3-
sync::atomic::Ordering,
4-
time::{Duration, SystemTime},
5-
};
1+
use std::{fmt, sync::atomic::Ordering, time::Duration};
62

7-
use humantime::format_duration;
83
use tui::{
94
buffer::Buffer,
105
layout::Rect,
@@ -145,7 +140,7 @@ pub(crate) fn headline(
145140

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

148-
impl<'a> fmt::Display for ProgressFormat<'a> {
143+
impl fmt::Display for ProgressFormat<'_> {
149144
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150145
match self.0 {
151146
Some(p) => match p.unit.as_ref() {
@@ -300,13 +295,14 @@ fn add_block_eta(state: progress::State, progress_text: &mut String) {
300295
progress_text.push_str(reason);
301296
progress_text.push(']');
302297
if let Some(eta) = maybe_eta {
303-
let now = SystemTime::now();
298+
let eta = jiff::Timestamp::try_from(eta).expect("reasonable system time");
299+
let now = jiff::Timestamp::now();
304300
if eta > now {
305301
use std::fmt::Write;
306302
write!(
307303
progress_text,
308-
" → {} to {}",
309-
format_duration(eta.duration_since(now).expect("computation to work")),
304+
" → {:#} to {}",
305+
eta.duration_since(now),
310306
if let progress::State::Blocked(_, _) = state {
311307
"unblock"
312308
} else {

src/render/tui/engine.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ pub(crate) enum InterruptDrawInfo {
8989
Deferred(bool),
9090
}
9191

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

9795
use crosstermion::crossterm::event::{KeyCode, KeyEventKind, KeyModifiers};
9896
use crosstermion::{

src/time.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,20 @@ mod utc {
3030
use std::time::SystemTime;
3131

3232
use super::DATE_TIME_HMS;
33-
const DATE_TIME_YMD: usize = "2020-02-13T".len();
3433

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

4642
/// Return a string representing the current time as UTC.
4743
///
4844
/// Available without the `localtime` feature toggle.
4945
pub fn format_now_datetime_seconds() -> String {
50-
String::from_utf8_lossy(
51-
&humantime::format_rfc3339_seconds(std::time::SystemTime::now())
52-
.to_string()
53-
.as_bytes()[.."2020-02-13T00:51:45".len()],
54-
)
55-
.into_owned()
46+
jiff::Timestamp::now().strftime("%FT%T").to_string()
5647
}
5748
}
5849

src/traits.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod impls {
243243

244244
pub trait Sealed {}
245245

246-
impl<'a, T> Count for &'a T
246+
impl<T> Count for &T
247247
where
248248
T: Count + ?Sized,
249249
{
@@ -268,7 +268,7 @@ mod impls {
268268
}
269269
}
270270

271-
impl<'a, T> Count for &'a mut T
271+
impl<T> Count for &mut T
272272
where
273273
T: Count + ?Sized,
274274
{
@@ -293,7 +293,7 @@ mod impls {
293293
}
294294
}
295295

296-
impl<'a, T> Progress for &'a mut T
296+
impl<T> Progress for &mut T
297297
where
298298
T: Progress + ?Sized,
299299
{
@@ -350,7 +350,7 @@ mod impls {
350350
}
351351
}
352352

353-
impl<'a, T> NestedProgress for &'a mut T
353+
impl<T> NestedProgress for &mut T
354354
where
355355
T: NestedProgress + ?Sized,
356356
{

src/unit/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl What {
117117
}
118118
}
119119

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

138-
impl<'a> fmt::Display for UnitDisplay<'a> {
138+
impl fmt::Display for UnitDisplay<'_> {
139139
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140140
let unit: &dyn DisplayValue = self.parent.as_display_value();
141141
let mode = self.parent.mode;

src/unit/duration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use std::{fmt, time};
2-
3-
use humantime::format_duration;
1+
use std::fmt;
42

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

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

119
impl DisplayValue for Duration {
1210
fn display_current_value(&self, w: &mut dyn fmt::Write, value: Step, _upper: Option<Step>) -> fmt::Result {
13-
w.write_str(&format_duration(time::Duration::new(value as u64, 0)).to_string())
11+
let dur = jiff::SignedDuration::from_secs(value as i64);
12+
w.write_str(&format!("{dur:#}"))
1413
}
1514
fn separator(&self, w: &mut dyn fmt::Write, _value: Step, _upper: Option<Step>) -> fmt::Result {
1615
w.write_str(" of ")
1716
}
1817
fn display_upper_bound(&self, w: &mut dyn fmt::Write, upper_bound: Step, _value: Step) -> fmt::Result {
19-
w.write_str(&format_duration(time::Duration::new(upper_bound as u64, 0)).to_string())
18+
let dur = jiff::SignedDuration::from_secs(upper_bound as i64);
19+
w.write_str(&format!("{dur:#}"))
2020
}
2121

2222
fn dyn_hash(&self, state: &mut dyn std::hash::Hasher) {

0 commit comments

Comments
 (0)