Skip to content

Commit f85cf1e

Browse files
committed
chore: Make progress spinner template reusable through a LazyLock, and use span filtering toc ontrol indicatif output
NOTE: Use `fields(indicatif.pb_show = true)` on instrumented functions that should have progress reporting
1 parent 487df5a commit f85cf1e

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

rust/stackable-cockpit/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ pub mod platform;
1111
pub mod utils;
1212
pub mod xfer;
1313

14-
pub(crate) static PROGRESS_BAR_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
14+
pub static PROGRESS_BAR_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
1515
ProgressStyle::with_template(
16-
"{span_child_prefix} Progress {msg}: {wide_bar:.magenta/cyan} {pos}/{len}",
16+
"{span_child_prefix_indent}Progress: {wide_bar:.magenta/cyan} {pos}/{len}",
1717
)
1818
.expect("valid progress template")
1919
});
20+
21+
pub static PROGRESS_SPINNER_STYLE: LazyLock<ProgressStyle> = LazyLock::new(|| {
22+
ProgressStyle::with_template("{span_child_prefix_indent}{spinner} {msg}")
23+
.expect("valid progress template")
24+
});

rust/stackablectl/src/main.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
use clap::Parser;
22
use dotenvy::dotenv;
3-
use indicatif::ProgressStyle;
3+
use stackable_cockpit::PROGRESS_SPINNER_STYLE;
44
use stackablectl::cli::{Cli, Error};
55
use tracing::{Level, metadata::LevelFilter};
6-
use tracing_indicatif::{IndicatifLayer, indicatif_eprintln};
7-
use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt};
6+
use tracing_indicatif::{
7+
IndicatifLayer,
8+
filter::{IndicatifFilter, hide_indicatif_span_fields},
9+
indicatif_eprintln,
10+
};
11+
use tracing_subscriber::{
12+
Layer as _,
13+
fmt::{self, format::DefaultFields},
14+
layer::SubscriberExt,
15+
util::SubscriberInitExt,
16+
};
817

918
#[snafu::report]
1019
#[tokio::main]
@@ -19,16 +28,12 @@ async fn main() -> Result<(), Error> {
1928
.with_target(false);
2029

2130
let indicatif_layer = IndicatifLayer::new()
22-
.with_progress_style(ProgressStyle::with_template("").expect("valid progress template"))
23-
.with_max_progress_bars(
24-
15,
25-
Some(
26-
ProgressStyle::with_template(
27-
"...and {pending_progress_bars} more processes not shown above.",
28-
)
29-
.expect("valid progress template"),
30-
),
31-
);
31+
.with_span_field_formatter(
32+
// If the `{span_fields}` interpolation is used in a template, then we want to hide the
33+
// indicatif control fields "indicatif.pb_show" and "indicatif.pb_hide"
34+
hide_indicatif_span_fields(DefaultFields::new()),
35+
)
36+
.with_progress_style(PROGRESS_SPINNER_STYLE.clone());
3237

3338
if let Some(level) = app.log_level {
3439
tracing_subscriber::registry()
@@ -43,7 +48,7 @@ async fn main() -> Result<(), Error> {
4348
} else {
4449
tracing_subscriber::registry()
4550
.with(LevelFilter::from_level(Level::INFO))
46-
.with(indicatif_layer)
51+
.with(indicatif_layer.with_filter(IndicatifFilter::new(false)))
4752
.init();
4853
}
4954

0 commit comments

Comments
 (0)