tasklist opt string

cli-redesign
Avril 4 years ago
parent 970a221170
commit 28f3eba2b8
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -67,7 +67,7 @@ pub async fn work(conf: config::Config) -> Result<(), Box<dyn std::error::Error>
for path in conf.output.into_iter()
{
let url = url::parse(&rating);
let mut prog = prog_writer.clone();
let mut prog = prog_writer.clone_with(format!("-> {:?}", path));
children.push(tokio::task::spawn(async move {
//println!("Starting download ({})...", url);

@ -61,7 +61,7 @@ pub struct AsyncProgressCounter
}
#[derive(Clone)]
pub struct CommandSender(Sender<Command>);
pub struct CommandSender(Sender<Command>, Option<String>);
pub struct CommandCallback(UnboundedReceiver<()>);
@ -116,10 +116,34 @@ macro_rules! prog_send {
impl CommandSender
{
/// Clone with a new opt string
pub fn clone_with(&self, opt: impl Into<String>) -> Self
{
Self (
self.0.clone(),
Some(opt.into())
)
}
fn opt_str(&self, string: impl AsRef<str>) -> String
{
if let Some(opt) = &self.1 {
format!("[{}] {}", opt, string.as_ref())
} else {
string.as_ref().into()
}
}
/// Get or set an opt string
pub fn opt(&mut self) -> &mut Option<String>
{
&mut self.1
}
/// Print a line
pub async fn println(&mut self, string: impl Into<String>) -> Result<CommandCallback, error::Error>
pub async fn println(&mut self, string: impl AsRef<str>) -> Result<CommandCallback, error::Error>
{
let (com, call) = Command::new(CommandInternal::PrintLine(string.into()));
let (com, call) = Command::new(CommandInternal::PrintLine(self.opt_str(string)));
self.0.send(com).await?;
Ok(call)
}
@ -141,9 +165,9 @@ impl CommandSender
}
/// Finalise the progress counter and print a line
pub async fn kill_with(&mut self, string: String) -> Result<CommandCallback, error::Error>
pub async fn kill_with(&mut self, string: impl AsRef<str>) -> Result<CommandCallback, error::Error>
{
let (com, call) = Command::new(CommandInternal::Kill(Some(string)));
let (com, call) = Command::new(CommandInternal::Kill(Some(self.opt_str(string))));
self.0.send(com).await?;
Ok(call)
}
@ -188,11 +212,16 @@ impl AsyncProgressCounter
title: title.into(),
}
}
/// Create a new writer with an opt string
pub fn writer_with(&self, opt: impl Into<String>) -> CommandSender
{
CommandSender(self.writer.clone(), Some(opt.into()))
}
/// Create a new writer
pub fn writer(&self) -> CommandSender
{
CommandSender(self.writer.clone())
CommandSender(self.writer.clone(), None)
}
/// Consume the instance and host it's receiver

@ -65,7 +65,7 @@ impl TaskList
pub fn recalc_buffer(&mut self)
{
self.1 = self.0.iter().map(|(_, s)| s.as_str()).collect();
self.1 = self.0.iter().map(|(_, s)| s.as_str()).collect(); //TODO: Iterator extension join method for strings
}
pub fn as_str(&self) -> &str

Loading…
Cancel
Save