add new option use-progress-bar

fix panic when artwork is 404
This commit is contained in:
2022-03-26 15:55:26 +08:00
parent 59f6923159
commit ad2e199b80
12 changed files with 329 additions and 104 deletions

1
src/opt/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod use_progress_bar;

View 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)
}
}