added quiet mode

master
Avril 4 years ago
parent 6fd8627a33
commit c93ddd7709
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "lolistealer"
version = "1.2.0"
version = "1.3.0"
authors = ["Avril <flanchan@cumallover.me>"]
edition = "2018"

@ -17,14 +17,24 @@ lazy_static! {
/// Print usage then exit with code `1`
pub fn usage() -> !
{
println!("lolistealer version {}\n", env!("CARGO_PKG_VERSION"));
println!("Usage: {} [--rating <filter expr>] [--tags <tag rules>][<outputs...>]", &PROGRAM_NAME[..]);
println!("lolistealer version {}", env!("CARGO_PKG_VERSION"));
println!(" written by {} with <3", env!("CARGO_PKG_AUTHORS"));
println!(" licensed with GNU GPL 3.0 or later\n");
println!("Usage: {} [-q] [--rating <rating>] [--tags <filter expr>] [<outputs...>]", &PROGRAM_NAME[..]);
println!("Usage: {} --help", &PROGRAM_NAME[..]);
println!("Filter expression:");
println!("Options:");
println!(" -q\t\t\tQuiet mode, do not output progress");
println!(" --rating <rating>\tEither `s`afe, `q`uestionable, or `e`xplicit");
println!(" --tags <filter expr>\tFilter downloaded images out by tags, see below for format.");
println!("Tags filter expreession:");
println!(" tag_name\tMust contain this tag");
println!(" -tag_name\tMust not contains this tag");
println!(" +tag_name\tMust contains at least one tag prepended with `+`");
println!("Note:");
println!(" Tag filter expreession is a single argument, tags must be seperated with spaces. e.g. 'tag1 -tag2 +tag3 +tag4'");
#[cfg(feature="async")]
println!("\n (compiled with threading support)");
std::process::exit(1)
}
@ -64,6 +74,7 @@ where I: IntoIterator<Item=String>
let mut one = String::default();
let mut reading = true;
let mut tags = Vec::new();
let mut verbose = Default::default();
macro_rules! take_one {
() => {
@ -84,6 +95,7 @@ where I: IntoIterator<Item=String>
match arg.to_lowercase().trim() {
"-" => reading = false,
"--help" => return Ok(Mode::Help),
"-q" => verbose = config::Verbosity::Silent,
"--rating" if take_one!() => rating = one.parse::<config::Rating>()?,
"--tags" if take_one!() => tags = tags::parse(&one),
_ => paths.push(try_dir(arg)?),
@ -97,7 +109,7 @@ where I: IntoIterator<Item=String>
return Err(Error::NoOutput);
}
Ok(Mode::Normal(config::Config{rating, output: paths, tags}))
Ok(Mode::Normal(config::Config{rating, output: paths, tags, verbose}))
}
#[derive(Debug)]

@ -25,6 +25,21 @@ impl Rating
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum Verbosity
{
Full,
Silent,
}
impl Default for Verbosity
{
fn default() -> Self
{
Self::Full
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum OutputType
{
@ -37,6 +52,7 @@ pub struct Config
pub rating: Rating,
pub output: Vec<OutputType>,
pub tags: Vec<tags::Tag>,
pub verbose: Verbosity,
}
impl Default for Rating
@ -54,6 +70,7 @@ impl Default for Config
rating: Rating::default(),
output: Vec::new(),
tags: Vec::new(),
verbose: Default::default(),
}
}
}

@ -86,15 +86,27 @@ pub async fn perform(url: impl AsRef<str>, path: impl AsRef<Path>, progress: &mu
Ok(())
}
pub async fn work(conf: config::Config) -> Result<(), Box<dyn std::error::Error>>
{
let rating = conf.rating;
let mut children = Vec::with_capacity(conf.output.len());
let prog = progress::AsyncProgressCounter::new("Initialising...", 1);
let mut prog_writer = prog.writer();
let prog = prog.host();
let (mut prog_writer, prog) = match conf.verbose {
config::Verbosity::Full => {
let prog = progress::AsyncProgressCounter::<termprogress::progress::Bar>::new("Initialising...", 1);
let prog_writer = prog.writer();
let prog = prog.host();
(prog_writer, prog)
},
config::Verbosity::Silent => {
let prog = progress::AsyncProgressCounter::<progress::Silent>::new("Initialising...", 1);
let prog_writer = prog.writer();
let prog = prog.host();
(prog_writer, prog)
},
};
for path in conf.output.into_iter()
{

@ -47,7 +47,8 @@ impl std::ops::Drop for Command
}
}
pub struct AsyncProgressCounter
pub struct AsyncProgressCounter<T>
where T: termprogress::ProgressBar + WithTitle + std::marker::Send + std::marker::Sync +'static,
{
writer: Sender<Command>,
reader: Receiver<Command>,
@ -55,6 +56,8 @@ pub struct AsyncProgressCounter
small: u64,
large: u64,
_phantom: std::marker::PhantomData<T>,
}
#[derive(Clone)]
@ -226,7 +229,8 @@ impl CommandCallback
}
}
impl AsyncProgressCounter
impl<T> AsyncProgressCounter<T>
where T: termprogress::ProgressBar + WithTitle + std::marker::Send + std::marker::Sync +'static,
{
/// Create a new `AsyncProgressCounter`
pub fn new(title: impl Into<String>, max: u64) -> Self
@ -239,6 +243,8 @@ impl AsyncProgressCounter
title: title.into(),
small: 0,
large: max,
_phantom: std::marker::PhantomData,
}
}
@ -257,7 +263,7 @@ impl AsyncProgressCounter
pub fn host(mut self) -> JoinHandle<()>
{
//let mut spin = spinner::Spin::with_title(&self.title[..], Default::default());
let mut bar = termprogress::progress::Bar::with_title(50, &self.title[..]);
let mut bar = T::with_title(50, &self.title[..]);
bar.update();
@ -317,3 +323,54 @@ impl AsyncProgressCounter
})
}
}
pub trait WithTitle: Sized + ProgressBar + Display
{
fn with_title(len: usize, string: impl AsRef<str>) -> Self;
fn update(&mut self);
fn complete(self);
}
impl WithTitle for termprogress::progress::Bar
{
fn with_title(len: usize, string: impl AsRef<str>) -> Self
{
Self::with_title(len, string)
}
fn update(&mut self)
{
self.update();
}
fn complete(self)
{
self.complete();
}
}
#[derive(Debug)]
pub struct Silent;
impl termprogress::Display for Silent
{
fn println(&self, _: &str){}
fn refresh(&self){}
fn blank(&self){}
fn get_title(&self) -> &str{""}
fn set_title(&mut self, _: &str){}
fn update_dimensions(&mut self, _:usize){}
}
impl termprogress::ProgressBar for Silent
{
fn set_progress(&mut self, _:f64){}
fn get_progress(&self) -> f64{0.0}
}
impl WithTitle for Silent
{
fn with_title(_: usize, _: impl AsRef<str>) -> Self{Self}
fn update(&mut self) {}
fn complete(self) {}
}

Loading…
Cancel
Save