Crates.io | ml-progress |
lib.rs | ml-progress |
version | 0.1.0 |
source | src |
created_at | 2022-03-13 12:08:06.073714 |
updated_at | 2022-03-13 12:08:06.073714 |
description | Single line progress indicator for terminal/console. |
homepage | |
repository | https://github.com/malaire/ml-progress |
max_upload_size | |
id | 549189 |
size | 60,108 |
Progress indicator for terminal/console.
\r
Early version - this hasn't yet been tested properly.
Progress
with progress!
macro
(if you don't need custom configuration) orProgressBuilder
with progress_builder!
macro,
set custom options, and then create Progress
with build
.inc
and message
.finish
, finish_and_clear
or finish_at_current_pos
.use ml_progress::progress;
let progress = progress!(10)?;
for _ in 0..10 {
// std::thread::sleep(std::time::Duration::from_millis(500));
progress.inc(1);
}
progress.finish();
# Ok::<(), ml_progress::Error>(())
##############################-------------------- 6/10 (2s)
use ml_progress::progress;
let progress = progress!(
10;
"[" percent "] " pos "/" total " " bar_fill " (" eta_hms ")"
)?;
for _ in 0..10 {
// std::thread::sleep(std::time::Duration::from_millis(500));
progress.inc(1);
}
progress.finish();
# Ok::<(), ml_progress::Error>(())
[ 60%] 6/10 ########################----------------- (0:02)
use ml_progress::progress_builder;
let progress = progress_builder!(
"[" percent "] " pos_group "/" total_group " " bar_fill " (" eta_hms ")"
)
.total(Some(10000))
.thousands_separator(",")
.build()?;
for _ in 0..10 {
// std::thread::sleep(std::time::Duration::from_millis(500));
progress.inc(1000);
}
progress.finish();
# Ok::<(), ml_progress::Error>(())
[ 60%] 6,000/10,000 ###################-------------- (0:02)
Items are used with progress!
and progress_builder!
macros.
bar_fill
)
or multiple tokens surrounded by parentheses (e.g. (eta "{:2}{:1}")
).*_fill
item is allowed.Summary of all possible items. See below for further details.
"foo" // "foo"
bar_fill // "######----"
eta // "5m" ; same as (eta "{}{}")
(eta FORMAT NONE) // u64, &str
eta_hms // "5:23"
message_fill // "foo"
percent // " 23%" ; same as (percent "{:3.0}%")
(percent FORMAT NONE) // f64
pos // "1234567" ; same as (pos "{}" )
pos_group // "1 234 567" ; same as (pos "{:#}" )
pos_bin // "1.18 Mi" ; same as (pos_bin "{:#} {}")
pos_dec // "1.23 M" ; same as (pos_dec "{:#} {}")
(pos FORMAT) // u64
(pos_bin FORMAT) // f64, prefix
(pos_dec FORMAT) // f64, prefix
speed // "1234567" ; same as (speed "{:#}" )
speed_int // "1234567" ; same as (speed_int "{}" )
speed_group // "1 234 567" ; same as (speed_int "{:#}" )
speed_bin // "1.18 Mi" ; same as (speed_bin "{:#} {}")
speed_dec // "1.23 M" ; same as (speed_dec "{:#} {}")
(speed FORMAT NONE) // f64
(speed_int FORMAT NONE) // u64
(speed_bin FORMAT NONE) // f64, prefix
(speed_dec FORMAT NONE) // f64, prefix
total // "1234567" ; same as (total "{}" )
total_group // "1 234 567" ; same as (total "{:#}" )
total_bin // "1.18 Mi" ; same as (total_bin "{:#} {}")
total_dec // "1.23 M" ; same as (total_dec "{:#} {}")
(total FORMAT NONE) // u64
(total_bin FORMAT NONE) // f64, prefix
(total_dec FORMAT NONE) // f64, prefix
(|state| EXPR)
FORMAT
#
"alternate" flag (see below).NONE
None
.
State
about when values are None
._bin
use 1024-based binary prefixes (Ki
, Mi
, Gi
, ...)._dec
use 1000-based decimal prefixes (k
, M
, G
, ...).If value is below 1024 or 1000 then prefix is empty string.
When #
"alternate" flag is used in FORMAT
,
following applies based on type:
u64
is formatted with digits in groups of three.
ProgressBuilder::thousands_separator
,
default is space.1234567
with "{:#}"
is shown as "1 234 567"
with default separatorf64
precision
(default: 4) is considered "fit width" and value is
shown with maximum number of decimals so that it fits this width,
or with no decimals if fit is not possible.pos_bin
, pos_dec
, total_bin
and total_dec
:
Amounts with empty prefix are shown with no decimals.1.2345
with "{:#}"
is shown as "1.23"
12.345
with "{:#}"
is shown as "12.3"
123.45
with "{:#}"
is shown as "123"
1234.5
with "{:#}"
is shown as "1235"
12345
with "{:#}"
is shown as "12345"
prefix
"{:#}"
shows empty prefix as-is
and other prefixes with prepended space."foo" // "foo"
Shows given literal string.
bar_fill
bar_fill // "######----"
Shows progress bar which fills remaining space on the line.
total
is None
.eta
eta // "5m" ; same as (eta "{}{}")
(eta FORMAT) // u64, &str
(eta FORMAT NONE)
Shows estimated time remaining in approximate format: amount and unit,
or NONE
if estimate is not available.
h
(hours), m
(minutes) or s
(seconds)eta_hms
eta_hms // "12:34:56" "0:56"
Shows estimated time remaining as hours/minutes/seconds, or empty string if estimate is not available.
message_fill
message_fill // "foo"
Shows the message set with Progress::message
,
filling the remaining space on the line.
percent
percent // " 23%" ; same as (percent "{:3.0}%")
(percent FORMAT) // f64
(percent FORMAT NONE)
Shows percentual completion or NONE
if total
is None
.
pos
pos // "1234567" ; same as (pos "{}" )
pos_group // "1 234 567" ; same as (pos "{:#}" )
pos_bin // "1.18 Mi" ; same as (pos_bin "{:#} {}")
pos_dec // "1.23 M" ; same as (pos_dec "{:#} {}")
(pos FORMAT) // u64
(pos_bin FORMAT) // f64, prefix
(pos_dec FORMAT) // f64, prefix
Shows position.
pos
- as integerpos_group
- as integer, with digits in groups of threepos_bin
- as floating-point amount with binary prefixpos_dec
- as floating-point amount with decimal prefixspeed
speed // "1234567" ; same as (speed "{:#}" )
speed_int // "1234567" ; same as (speed_int "{}" )
speed_group // "1 234 567" ; same as (speed_int "{:#}" )
speed_bin // "1.18 Mi" ; same as (speed_bin "{:#} {}")
speed_dec // "1.23 M" ; same as (speed_dec "{:#} {}")
(speed FORMAT) // f64
(speed FORMAT NONE)
(speed_int FORMAT) // u64
(speed_int FORMAT NONE)
(speed_bin FORMAT) // f64, prefix
(speed_bin FORMAT NONE)
(speed_dec FORMAT) // f64, prefix
(speed_dec FORMAT NONE)
Shows speed as steps per second or NONE
if speed is not available.
speed
- as floating-pointspeed_int
- as integerspeed_group
- as integer, with digits in groups of threespeed_bin
- as floating-point amount with binary prefixspeed_dec
- as floating-point amount with decimal prefixtotal
total // "1234567" ; same as (total "{}" )
total_group // "1 234 567" ; same as (total "{:#}" )
total_bin // "1.18 Mi" ; same as (total_bin "{:#} {}")
total_dec // "1.23 M" ; same as (total_dec "{:#} {}")
(total FORMAT) // u64
(total FORMAT NONE)
(total_bin FORMAT) // f64, prefix
(total_bin FORMAT NONE)
(total_dec FORMAT) // f64, prefix
(total_dec FORMAT NONE)
Shows total or NONE
if total
is None
.
total
- as integertotal_group
- as integer, with digits in groups of threetotal_bin
- as floating-point amount with binary prefixtotal_dec
- as floating-point amount with decimal prefix(|state| EXPR)
Shows return value of given function
which takes State
as input and returns String
.
(|s| custom_eta(s)) // "12h 34m 56s"
use ml_progress::State;
fn custom_eta(state: &State) -> String {
if let Some(eta) = state.eta() {
let (h, m, s) = ml_progress::duration_hms(eta);
if h > 0 {
format!("{}h {}m {}s", h, m, s)
} else if m > 0 {
format!("{}m {}s", m, s)
} else {
format!("{}s", s)
}
} else {
"".to_string()
}
}