|
|
|
@ -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
|
|
|
|
|