1

Swap out color backend

This commit is contained in:
Evan Pratten 2023-07-20 10:57:17 -04:00
parent 77266548c8
commit b76a6e1291
3 changed files with 26 additions and 12 deletions

View File

@ -18,19 +18,19 @@ protomask-tun = { path = "protomask-tun", version = "0.1.0" }
tokio = { version = "1.29.1", features = [ tokio = { version = "1.29.1", features = [
"macros", "macros",
"rt-multi-thread", "rt-multi-thread",
"process", # "process",
"sync" "sync"
] } ] }
clap = { version = "4.3.11", features = ["derive"] } clap = { version = "4.3.11", features = ["derive"] }
serde = { version = "1.0.171", features = ["derive"] } serde = { version = "1.0.171", features = ["derive"] }
ipnet = { version = "2.8.0", features = ["serde"] } ipnet = { version = "2.8.0", features = ["serde"] }
hyper = { version = "0.14.27", features = ["server", "http1", "tcp"] } hyper = { version = "0.14.27", features = ["server", "http1", "tcp"] }
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
toml = "0.7.6" toml = "0.7.6"
log = "0.4.19" log = "0.4.19"
fern = "0.6.2" fern = "0.6.2"
serde_path_to_error = "0.1.13" serde_path_to_error = "0.1.13"
thiserror = "1.0.43" thiserror = "1.0.43"
colored = "2.0.4"
tun-tap = "0.1.3" tun-tap = "0.1.3"
bimap = "0.6.3" bimap = "0.6.3"
pnet_packet = "0.33.0" pnet_packet = "0.33.0"

View File

@ -6,7 +6,6 @@ use std::{
time::Duration, time::Duration,
}; };
use colored::Colorize;
use ipnet::{Ipv4Net, Ipv6Net}; use ipnet::{Ipv4Net, Ipv6Net};
/// A static mapping rule /// A static mapping rule
@ -74,8 +73,8 @@ impl Config {
Err(e) => { Err(e) => {
eprintln!( eprintln!(
"Failed to parse config file due to:\n {}\n at {}", "Failed to parse config file due to:\n {}\n at {}",
e.inner().message().bright_red(), e.inner().message(),
e.path().to_string().bright_cyan() e.path()
); );
std::process::exit(1); std::process::exit(1);
} }

View File

@ -1,4 +1,4 @@
use colored::Colorize; use owo_colors::{OwoColorize, Stream::Stdout};
/// Enable the logger /// Enable the logger
#[allow(dead_code)] #[allow(dead_code)]
@ -11,18 +11,33 @@ pub fn enable_logger(verbose: bool) {
"{}{}", "{}{}",
// Level messages are padded to keep the output looking somewhat sane // Level messages are padded to keep the output looking somewhat sane
match record.level() { match record.level() {
log::Level::Error => "ERROR".red().bold().to_string(), log::Level::Error => "ERROR"
log::Level::Warn => "WARN ".yellow().bold().to_string(), .if_supports_color(Stdout, |text| text.red())
log::Level::Info => "INFO ".green().bold().to_string(), .if_supports_color(Stdout, |text| text.bold())
log::Level::Debug => "DEBUG".bright_blue().bold().to_string(), .to_string(),
log::Level::Trace => "TRACE".bright_white().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) // Only show the outer package name if verbose logging is enabled (otherwise nothing)
match verbose { match verbose {
true => format!(" [{}]", record.target().split("::").nth(0).unwrap()), true => format!(" [{}]", record.target().split("::").nth(0).unwrap()),
false => String::new(), false => String::new(),
} }
.bright_black() .if_supports_color(Stdout, |text| text.bright_black())
), ),
message message
)) ))