From d1ed7b0ed8920d37fb3504341c2bf39fccd9e683 Mon Sep 17 00:00:00 2001 From: Jun Jiang Date: Sat, 13 Jan 2024 23:20:36 +0800 Subject: [PATCH 01/15] Remove all ansi_term::Colour usage # Conflicts: # Cargo.lock # substrate/client/informant/Cargo.toml # substrate/client/informant/src/display.rs # substrate/client/informant/src/lib.rs # substrate/client/tracing/Cargo.toml Fix compile Fix compile Fix compile --- Cargo.lock | 4 +- substrate/client/informant/Cargo.toml | 2 +- substrate/client/informant/src/display.rs | 14 ++--- substrate/client/informant/src/lib.rs | 60 +++++++------------ substrate/client/tracing/Cargo.toml | 2 +- .../tracing/src/logging/event_format.rs | 12 ++-- 6 files changed, 40 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 160e7031af70..544579b9da7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17574,7 +17574,7 @@ dependencies = [ name = "sc-informant" version = "0.33.0" dependencies = [ - "ansi_term", + "console", "futures", "futures-timer", "log", @@ -18270,8 +18270,8 @@ dependencies = [ name = "sc-tracing" version = "28.0.0" dependencies = [ - "ansi_term", "chrono", + "console", "criterion", "is-terminal", "lazy_static", diff --git a/substrate/client/informant/Cargo.toml b/substrate/client/informant/Cargo.toml index 9da2296deee3..aa54d9479f5c 100644 --- a/substrate/client/informant/Cargo.toml +++ b/substrate/client/informant/Cargo.toml @@ -16,7 +16,7 @@ workspace = true targets = ["x86_64-unknown-linux-gnu"] [dependencies] -ansi_term = { workspace = true } +console = { workspace = true } futures = { workspace = true } futures-timer = { workspace = true } log = { workspace = true, default-features = true } diff --git a/substrate/client/informant/src/display.rs b/substrate/client/informant/src/display.rs index cdbb83b6596c..a234281037d5 100644 --- a/substrate/client/informant/src/display.rs +++ b/substrate/client/informant/src/display.rs @@ -17,7 +17,7 @@ // along with this program. If not, see . use crate::OutputFormat; -use ansi_term::Colour; +use console::{Attribute, Color}; use log::info; use sc_client_api::ClientInfo; use sc_network::NetworkStatus; @@ -146,15 +146,15 @@ impl InformantDisplay { target: "substrate", "{} {}{} ({} peers), best: #{} ({}), finalized #{} ({}), {} {}", level, - self.format.print_with_color(Colour::White.bold(), status), + self.format.print(Color::White, Some(Attribute::Bold), &status), target, - self.format.print_with_color(Colour::White.bold(), num_connected_peers), - self.format.print_with_color(Colour::White.bold(), best_number), + self.format.print(Color::White, Some(Attribute::Bold), format!("{}", num_connected_peers)), + self.format.print(Color::White, Some(Attribute::Bold), format!("{}", best_number)), best_hash, - self.format.print_with_color(Colour::White.bold(), finalized_number), + self.format.print(Color::White, Some(Attribute::Bold), format!("{}", 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))), + self.format.print(Color::Green, None, format!("⬇ {}", TransferRateFormat(avg_bytes_per_sec_inbound))), + self.format.print(Color::Red, None, format!("⬆ {}", TransferRateFormat(avg_bytes_per_sec_outbound))), ) } } diff --git a/substrate/client/informant/src/lib.rs b/substrate/client/informant/src/lib.rs index af778529ffc5..8f584d8a8519 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, Style}; +use console::{style, Attribute, Color}; use futures::prelude::*; use futures_timer::Delay; use log::{debug, info, trace}; @@ -51,41 +51,15 @@ impl Default for OutputFormat { } } -enum ColorOrStyle { - Color(Colour), - Style(Style), -} - -impl From for ColorOrStyle { - fn from(value: Colour) -> Self { - Self::Color(value) - } -} - -impl From