added colour

master
Avril 4 years ago
parent bcc5daa5e0
commit 1f0f66cefe
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -0,0 +1,63 @@
use super::*;
use std::{
fmt::Display,
};
#[cfg(feature="colour")]
#[macro_export] macro_rules! colour {
($things:path) => {
{
#[allow(unused_imports)]
use recolored::{
Color,
};
$things
}
}
}
#[cfg(not(feature="colour"))]
#[macro_export] macro_rules! colour {
($things:path) => {
()
}
}
#[cfg(not(feature="colour"))]
/// Dummy enum
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
BrightBlack,
BrightRed,
BrightGreen,
BrightYellow,
BrightBlue,
BrightMagenta,
BrightCyan,
BrightWhite,
Palette(u8),
True(u8, u8, u8),
}
#[cfg(feature="colour")] pub type Colour = recolored::Color;
#[cfg(not(feature="colour"))] pub type Colour = ();
#[inline] pub fn style(_col: Colour, from: impl Display) -> impl Display
{
cfg_if! {
if #[cfg(feature="colour")] {
use recolored::Colorize;
let string = format!("{}", from);
string.color(_col)
} else {
from
}
}
}

@ -21,6 +21,7 @@ pub use error::{ErrorExt as _, ResultExt as _};
mod stage; mod stage;
mod leanify; mod leanify;
mod colour;
mod dir; mod dir;
mod fixed_stack; mod fixed_stack;
mod process; mod process;
@ -32,6 +33,8 @@ mod work;
async fn work() -> Result<(), Box<dyn std::error::Error>> async fn work() -> Result<(), Box<dyn std::error::Error>>
{ {
//println!("umm {}", colour::style(colour!(Color::Blue), "hiii"));
let args = arg::parse_args().await.with_prefix("failed to parse args")?; let args = arg::parse_args().await.with_prefix("failed to parse args")?;
let leanify = leanify::find_binary().with_prefix("Couldn't find leanify binary")?; let leanify = leanify::find_binary().with_prefix("Couldn't find leanify binary")?;

@ -59,12 +59,12 @@ async fn do_work(process: impl AsRef<Path>, file: impl AsRef<OsStr>, mut prog: P
if err { if err {
cfg_if!{ cfg_if!{
if #[cfg(feature="progress")] { if #[cfg(feature="progress")] {
let value = format!("[!] {:?}: {}", file, value); let value = format!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
if let Err(_) = prog.eprintln(&value[..]).await { if let Err(_) = prog.eprintln(&value[..]).await {
eprintln!("\n{}", value); eprintln!("\n{}", value);
} }
} else { } else {
eprintln!("[!] {:?}: {}", file, value); eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
} }
} }
} else { } else {
@ -127,7 +127,9 @@ where I: IntoIterator<Item=T>,
}) })
}; };
let mut i=0usize; let mut i=0usize;
let results = join_all(files let results =
join_all(
files
.map(|filename| { .map(|filename| {
let semaphore = semaphore.clone(); let semaphore = semaphore.clone();
let process = Arc::clone(&process); let process = Arc::clone(&process);
@ -159,8 +161,11 @@ where I: IntoIterator<Item=T>,
match worker.1 { match worker.1 {
Ok(strings) => tx.send((filename, strings, i)).await.map_err(|_| "Child panic").unwrap(), Ok(strings) => tx.send((filename, strings, i)).await.map_err(|_| "Child panic").unwrap(),
Err(error) => { Err(error) => {
#[cfg(not(feature="progress"))] eprintln!("[!] {:?}: {}", filename.as_ref(), error); #[cfg(not(feature="progress"))] eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::Yellow),"!"), filename.as_ref(), colour::style(colour!(Color::Yellow), error));
#[cfg(feature="progress")] let _ = progress.eprintln(format!("[!] ({}) {:?}: {}", i, filename.as_ref(), error)).await.or_else(|e| {eprintln!("\n{}",e); Err(e)}); #[cfg(feature="progress")] let _ = progress.eprintln(format!("[{}] ({}) {:?}: {}", colour::style(colour!(Color::Yellow),"!"),i, filename.as_ref(), colour::style(colour!(Color::Yellow), error))).await
.or_else(|e| {
eprintln!("\n{}",e); Err(e)
});
}, },
} }
cfg_if!{ cfg_if!{

Loading…
Cancel
Save