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::{

0 commit comments

Comments
 (0)