mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
add new option use-progress-bar
fix panic when artwork is 404
This commit is contained in:
1
src/opt/mod.rs
Normal file
1
src/opt/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod use_progress_bar;
|
||||
62
src/opt/use_progress_bar.rs
Normal file
62
src/opt/use_progress_bar.rs
Normal file
@@ -0,0 +1,62 @@
|
||||
use crate::ext::use_or_not::ToBool;
|
||||
use crate::ext::use_or_not::UseOrNot;
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct UseProgressBar {
|
||||
v: UseOrNot,
|
||||
stream: atty::Stream,
|
||||
}
|
||||
|
||||
impl AsRef<Self> for UseProgressBar {
|
||||
fn as_ref(&self) -> &Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<UseOrNot> for UseProgressBar {
|
||||
fn as_ref(&self) -> &UseOrNot {
|
||||
self.v.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for UseProgressBar {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
v: UseOrNot::Auto,
|
||||
stream: atty::Stream::Stdout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<bool> for UseProgressBar {
|
||||
fn from(v: bool) -> Self {
|
||||
Self {
|
||||
v: UseOrNot::from(v),
|
||||
stream: atty::Stream::Stdout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<atty::Stream> for UseProgressBar {
|
||||
fn from(stream: atty::Stream) -> Self {
|
||||
Self {
|
||||
v: UseOrNot::Auto,
|
||||
stream,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UseOrNot> for UseProgressBar {
|
||||
fn from(v: UseOrNot) -> Self {
|
||||
Self {
|
||||
v,
|
||||
stream: atty::Stream::Stdout,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToBool for UseProgressBar {
|
||||
fn detect(&self) -> bool {
|
||||
atty::is(self.stream)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user