diff --git a/Cargo.lock b/Cargo.lock index 083f1ae..86b0718 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,16 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.0.1" @@ -35,24 +24,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "colored" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd" -dependencies = [ - "atty", - "lazy_static", - "winapi", -] - [[package]] name = "dnsd" version = "0.1.0" dependencies = [ - "colored", - "termcolor", "tokio", + "ttycolor", ] [[package]] @@ -73,12 +50,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.93" @@ -286,6 +257,15 @@ dependencies = [ "syn", ] +[[package]] +name = "ttycolor" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9fae6447ca6172ccd0b4adbc83c84a5b8dae5afe3fff233c4fdc28fcba54de4" +dependencies = [ + "termcolor", +] + [[package]] name = "unicode-xid" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 81221ac..e9b0b8e 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,5 +8,4 @@ edition = "2018" [dependencies] tokio = { version = "1.5.0", features = ["full"] } # An event-driven, non-blocking I/O platform for writing asynchronous I/O backed applications. -colored = "2.0.0" # The most simple way to add colors in your terminal -termcolor = "1.1.2" # A simple cross platform library for writing colored text to a terminal. +ttycolor = "0.1.0" # easy way to use termcolor diff --git a/src/color.rs b/src/color.rs deleted file mode 100644 index fa78cd8..0000000 --- a/src/color.rs +++ /dev/null @@ -1,162 +0,0 @@ -extern crate termcolor; -use std::fmt::Display; -use termcolor::Color::*; -use termcolor::{Color, ColorSpec, StandardStream, WriteColor}; - -pub struct ColorString { - input: String, - fg: Option, - bg: Option, - bold: bool, - italic: bool, - underline: bool, -} - -impl Default for ColorString { - fn default() -> Self { - Self { - input: "".to_string(), - fg: None, - bg: None, - bold: false, - italic: false, - underline: false, - } - } -} - -pub trait ColorTrait -where - Self: Sized, -{ - fn fg(self, color: Color) -> ColorString; - fn bg(self, color: Color) -> ColorString; - fn bold(self) -> ColorString; - fn italic(self) -> ColorString; - fn underline(self) -> ColorString; - fn green(self) -> ColorString { - self.fg(Green) - } - fn red(self) -> ColorString { - self.fg(Red) - } - fn cyan(self) -> ColorString { - self.fg(Cyan) - } - fn magenta(self) -> ColorString { - self.fg(Magenta) - } - fn white(self) -> ColorString { - self.fg(White) - } - fn black(self) -> ColorString { - self.fg(Black) - } - fn blue(self) -> ColorString { - self.fg(Blue) - } - fn bg_green(self) -> ColorString { - self.bg(Green) - } - fn bg_red(self) -> ColorString { - self.bg(Red) - } - fn bg_cyan(self) -> ColorString { - self.bg(Cyan) - } - fn bg_magenta(self) -> ColorString { - self.bg(Magenta) - } - fn bg_white(self) -> ColorString { - self.bg(White) - } - fn bg_black(self) -> ColorString { - self.bg(Black) - } - fn bg_blue(self) -> ColorString { - self.bg(Blue) - } -} - -impl ColorTrait for &str { - fn fg(self, color: Color) -> ColorString { - let mut to = ColorString::default(); - to.input = self.to_string(); - to.fg = Some(color); - to - } - - fn bg(self, color: Color) -> ColorString { - let mut to = ColorString::default(); - to.input = self.to_string(); - to.bg = Some(color); - to - } - - fn bold(self) -> ColorString { - let mut to = ColorString::default(); - to.input = self.to_string(); - to.bold = true; - to - } - - fn italic(self) -> ColorString { - let mut to = ColorString::default(); - to.input = self.to_string(); - to.italic = true; - to - } - - fn underline(self) -> ColorString { - let mut to = ColorString::default(); - to.input = self.to_string(); - to.underline = true; - to - } -} - -impl ColorTrait for ColorString { - fn fg(mut self, color: Color) -> ColorString { - self.fg = Some(color); - self - } - - fn bg(mut self, color: Color) -> ColorString { - self.bg = Some(color); - self - } - - fn bold(mut self) -> ColorString { - self.bold = true; - self - } - - fn italic(mut self) -> ColorString { - self.italic = true; - self - } - - fn underline(mut self) -> ColorString { - self.underline = true; - self - } -} - -impl Display for ColorString { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut stdout = StandardStream::stdout(termcolor::ColorChoice::Auto); - stdout - .set_color( - ColorSpec::new() - .set_fg(self.fg) - .set_bg(self.bg) - .set_bold(self.bold) - .set_italic(self.italic) - .set_underline(self.underline), - ) - .unwrap_or_default(); - let result = write!(f, "{}", self.input); - stdout.reset().unwrap_or_default(); - result - } -} diff --git a/src/main.rs b/src/main.rs index fa0a773..4786218 100755 --- a/src/main.rs +++ b/src/main.rs @@ -4,8 +4,8 @@ use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; use tokio::net::UdpSocket; -mod color; -use color::ColorTrait; +extern crate ttycolor; +use ttycolor::*; const DEBUG: bool = false;