diff --git a/substrate/client/cli/src/config.rs b/substrate/client/cli/src/config.rs index b842df5a690a2..170173c8c28b1 100644 --- a/substrate/client/cli/src/config.rs +++ b/substrate/client/cli/src/config.rs @@ -27,8 +27,8 @@ use names::{Generator, Name}; use sc_service::{ config::{ BasePath, Configuration, DatabaseSource, KeystoreConfig, NetworkConfiguration, - NodeKeyConfig, OffchainWorkerConfig, PrometheusConfig, PruningMode, Role, RpcMethods, - TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod, + NodeKeyConfig, OffchainWorkerConfig, OutputFormat, PrometheusConfig, PruningMode, Role, + RpcMethods, TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod, }, BlocksPruning, ChainSpec, TracingReceiver, }; @@ -516,7 +516,7 @@ pub trait CliConfiguration: Sized { announce_block: self.announce_block()?, role, base_path, - informant_output_format: Default::default(), + informant_output_format: OutputFormat { enable_color: !self.disable_log_color()? }, runtime_cache_size, }) } diff --git a/substrate/client/informant/src/display.rs b/substrate/client/informant/src/display.rs index bcf3794032fe8..cdbb83b6596c2 100644 --- a/substrate/client/informant/src/display.rs +++ b/substrate/client/informant/src/display.rs @@ -142,37 +142,20 @@ impl InformantDisplay { ("⚙️ ", format!("Preparing{}", speed), format!(", target=#{target}")), }; - if self.format.enable_color { - info!( - target: "substrate", - "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", - level, - Colour::White.bold().paint(&status), - target, - Colour::White.bold().paint(format!("{}", num_connected_peers)), - Colour::White.bold().paint(format!("{}", best_number)), - best_hash, - Colour::White.bold().paint(format!("{}", finalized_number)), - info.chain.finalized_hash, - Colour::Green.paint(format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))), - Colour::Red.paint(format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))), - ) - } else { - info!( - target: "substrate", - "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", - level, - status, - target, - num_connected_peers, - best_number, - best_hash, - finalized_number, - info.chain.finalized_hash, - TransferRateFormat(avg_bytes_per_sec_inbound), - TransferRateFormat(avg_bytes_per_sec_outbound), - ) - } + info!( + target: "substrate", + "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", + level, + self.format.print_with_color(Colour::White.bold(), status), + target, + self.format.print_with_color(Colour::White.bold(), num_connected_peers), + self.format.print_with_color(Colour::White.bold(), best_number), + best_hash, + self.format.print_with_color(Colour::White.bold(), finalized_number), + info.chain.finalized_hash, + self.format.print_with_color(Colour::Green, format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))), + self.format.print_with_color(Colour::Red, format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))), + ) } } diff --git a/substrate/client/informant/src/lib.rs b/substrate/client/informant/src/lib.rs index b072f8551f9f4..7db80bb2d9725 100644 --- a/substrate/client/informant/src/lib.rs +++ b/substrate/client/informant/src/lib.rs @@ -18,7 +18,7 @@ //! Console informant. Prints sync progress and block events. Runs on the calling thread. -use ansi_term::Colour; +use ansi_term::{Colour, Style}; use futures::prelude::*; use futures_timer::Delay; use log::{debug, info, trace}; @@ -51,6 +51,47 @@ impl Default for OutputFormat { } } +enum ColorOrStyle { + Color(Colour), + Style(Style), +} + +impl From for ColorOrStyle { + fn from(value: Colour) -> Self { + Self::Color(value) + } +} + +impl From