Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit cd86c58

Browse files
committed
Change OutputFormat enum to struct
1 parent d3c1d52 commit cd86c58

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

client/cli/src/runner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ impl<C: SubstrateCli> Runner<C> {
212212
let prefix = self.config.informant_prefix.clone();
213213
let service = service_builder(self.config)?;
214214

215-
let informant_future = sc_informant::build(&service, sc_informant::OutputFormat::Coloured {
215+
let informant_future = sc_informant::build(&service, sc_informant::OutputFormat {
216+
colors: true,
216217
prefix,
217218
});
218219
let _informant_handle = self.tokio_runtime.spawn(informant_future);

client/informant/src/display.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ impl<B: BlockT> InformantDisplay<B> {
7373
(SyncState::Downloading, Some(n)) => ("⚙️ ", format!("Syncing{}", speed), format!(", target=#{}", n)),
7474
};
7575

76-
match &self.format {
77-
OutputFormat::Coloured { prefix } => info!(
76+
if self.format.colors {
77+
info!(
7878
target: "substrate",
7979
"{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}",
8080
level,
81-
prefix,
81+
self.format.prefix,
8282
Colour::White.bold().paint(&status),
8383
target,
8484
Colour::White.bold().paint(format!("{}", num_connected_peers)),
@@ -88,12 +88,13 @@ impl<B: BlockT> InformantDisplay<B> {
8888
info.chain.finalized_hash,
8989
Colour::Green.paint(format!("⬇ {}", TransferRateFormat(net_status.average_download_per_sec))),
9090
Colour::Red.paint(format!("⬆ {}", TransferRateFormat(net_status.average_upload_per_sec))),
91-
),
92-
OutputFormat::Plain { prefix } => info!(
91+
)
92+
} else {
93+
info!(
9394
target: "substrate",
9495
"{} {}{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}",
9596
level,
96-
prefix,
97+
self.format.prefix,
9798
status,
9899
target,
99100
num_connected_peers,
@@ -103,7 +104,7 @@ impl<B: BlockT> InformantDisplay<B> {
103104
info.chain.finalized_hash,
104105
TransferRateFormat(net_status.average_download_per_sec),
105106
TransferRateFormat(net_status.average_upload_per_sec),
106-
),
107+
)
107108
}
108109
}
109110
}

client/informant/src/lib.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,9 @@ mod display;
3030

3131
/// The format to print telemetry output in.
3232
#[derive(Clone)]
33-
pub enum OutputFormat {
34-
Coloured {
35-
prefix: String,
36-
},
37-
Plain {
38-
prefix: String,
39-
},
33+
pub struct OutputFormat {
34+
pub prefix: String,
35+
pub colors: bool,
4036
}
4137

4238
/// Creates an informant in the form of a `Future` that must be polled regularly.
@@ -101,16 +97,18 @@ pub fn build(service: &impl AbstractService, format: OutputFormat) -> impl futur
10197
last_best = Some((n.header.number().clone(), n.hash.clone()));
10298
}
10399

104-
match &format {
105-
OutputFormat::Coloured { prefix } => info!(
100+
if format.colors {
101+
info!(
106102
target: "substrate",
107103
"✨ {}Imported #{} ({})",
108-
prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash,
109-
),
110-
OutputFormat::Plain { prefix } => info!(
111-
target: "substrate", "✨ {}Imported #{} ({})",
112-
prefix, n.header.number(), n.hash,
113-
),
104+
format.prefix, Colour::White.bold().paint(n.header.number().to_string()), n.hash,
105+
)
106+
} else {
107+
info!(
108+
target: "substrate",
109+
"✨ {}Imported #{} ({})",
110+
format.prefix, n.header.number(), n.hash,
111+
)
114112
}
115113

116114
future::ready(())

utils/browser/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn start_client(mut service: impl AbstractService) -> Client {
121121
wasm_bindgen_futures::spawn_local(
122122
sc_informant::build(
123123
&service,
124-
sc_informant::OutputFormat::Plain { prefix: Default::default() },
124+
sc_informant::OutputFormat { colors: false, prefix: Default::default() },
125125
).map(drop)
126126
);
127127

0 commit comments

Comments
 (0)