From b76a6e129145e7799647555fc1c075504988c55a Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Thu, 20 Jul 2023 10:57:17 -0400 Subject: [PATCH] Swap out color backend --- Cargo.toml | 4 ++-- src/cli/config.rs | 5 ++--- src/cli/logging.rs | 29 ++++++++++++++++++++++------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 640270e..98dfa8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,19 +18,19 @@ protomask-tun = { path = "protomask-tun", version = "0.1.0" } tokio = { version = "1.29.1", features = [ "macros", "rt-multi-thread", - "process", + # "process", "sync" ] } clap = { version = "4.3.11", features = ["derive"] } serde = { version = "1.0.171", features = ["derive"] } ipnet = { version = "2.8.0", features = ["serde"] } hyper = { version = "0.14.27", features = ["server", "http1", "tcp"] } +owo-colors = { version = "3.5.0", features = ["supports-colors"] } toml = "0.7.6" log = "0.4.19" fern = "0.6.2" serde_path_to_error = "0.1.13" thiserror = "1.0.43" -colored = "2.0.4" tun-tap = "0.1.3" bimap = "0.6.3" pnet_packet = "0.33.0" diff --git a/src/cli/config.rs b/src/cli/config.rs index 6909890..50e46f6 100644 --- a/src/cli/config.rs +++ b/src/cli/config.rs @@ -6,7 +6,6 @@ use std::{ time::Duration, }; -use colored::Colorize; use ipnet::{Ipv4Net, Ipv6Net}; /// A static mapping rule @@ -74,8 +73,8 @@ impl Config { Err(e) => { eprintln!( "Failed to parse config file due to:\n {}\n at {}", - e.inner().message().bright_red(), - e.path().to_string().bright_cyan() + e.inner().message(), + e.path() ); std::process::exit(1); } diff --git a/src/cli/logging.rs b/src/cli/logging.rs index f727fc6..38da6e0 100644 --- a/src/cli/logging.rs +++ b/src/cli/logging.rs @@ -1,4 +1,4 @@ -use colored::Colorize; +use owo_colors::{OwoColorize, Stream::Stdout}; /// Enable the logger #[allow(dead_code)] @@ -11,18 +11,33 @@ pub fn enable_logger(verbose: bool) { "{}{}", // Level messages are padded to keep the output looking somewhat sane match record.level() { - log::Level::Error => "ERROR".red().bold().to_string(), - log::Level::Warn => "WARN ".yellow().bold().to_string(), - log::Level::Info => "INFO ".green().bold().to_string(), - log::Level::Debug => "DEBUG".bright_blue().bold().to_string(), - log::Level::Trace => "TRACE".bright_white().bold().to_string(), + log::Level::Error => "ERROR" + .if_supports_color(Stdout, |text| text.red()) + .if_supports_color(Stdout, |text| text.bold()) + .to_string(), + log::Level::Warn => "WARN " + .if_supports_color(Stdout, |text| text.yellow()) + .if_supports_color(Stdout, |text| text.bold()) + .to_string(), + log::Level::Info => "INFO " + .if_supports_color(Stdout, |text| text.green()) + .if_supports_color(Stdout, |text| text.bold()) + .to_string(), + log::Level::Debug => "DEBUG" + .if_supports_color(Stdout, |text| text.bright_blue()) + .if_supports_color(Stdout, |text| text.bold()) + .to_string(), + log::Level::Trace => "TRACE" + .if_supports_color(Stdout, |text| text.bright_white()) + .if_supports_color(Stdout, |text| text.bold()) + .to_string(), }, // Only show the outer package name if verbose logging is enabled (otherwise nothing) match verbose { true => format!(" [{}]", record.target().split("::").nth(0).unwrap()), false => String::new(), } - .bright_black() + .if_supports_color(Stdout, |text| text.bright_black()) ), message ))