atom/
log.rs

1//! logging stubs for consistent progress and task presentation
2use tracing::Span;
3use tracing_indicatif::span_ext::IndicatifSpanExt;
4use tracing_indicatif::style::ProgressStyle;
5
6/// Set up the given span to be styled as a subtask of another span
7pub fn set_sub_task(span: &Span, msg: &str) {
8    span.pb_set_style(
9        &ProgressStyle::with_template("  {span_child_prefix} {spinner:.blue} {wide_msg}")
10            .unwrap_or(ProgressStyle::default_spinner()),
11    );
12    span.pb_set_message(msg);
13}
14
15/// Set up the given span to be styled as a progress bar
16pub fn set_bar(span: &Span, msg: &str, len: u64) {
17    let style = ProgressStyle::with_template(
18        "{elapsed} ░ {prefix} ░ {bar:30.green/black} {percent}% ░ {msg}",
19    )
20    .unwrap_or(ProgressStyle::default_bar())
21    .progress_chars("█▒ ");
22    span.pb_set_style(&style);
23    span.pb_set_message(msg);
24    span.pb_set_length(len);
25}
26
27/// given a size hint, calculate the best size
28pub fn best_size(size_hint: (usize, Option<usize>)) -> usize {
29    match size_hint {
30        (l, None) => l,
31        (_, Some(u)) => u,
32    }
33}