2020-03-12 22:05:49 -07:00
|
|
|
use crate::common::*;
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
2020-04-06 09:11:17 -07:00
|
|
|
pub(crate) enum CreateStep<'a> {
|
|
|
|
Searching { input: &'a InputTarget },
|
2020-03-12 22:05:49 -07:00
|
|
|
Hashing,
|
2020-04-06 09:11:17 -07:00
|
|
|
Writing { output: &'a OutputTarget },
|
2020-03-12 22:05:49 -07:00
|
|
|
}
|
|
|
|
|
2020-04-06 09:11:17 -07:00
|
|
|
impl<'a> Step for CreateStep<'a> {
|
2020-03-12 22:05:49 -07:00
|
|
|
fn n(&self) -> usize {
|
|
|
|
match self {
|
2020-04-06 09:11:17 -07:00
|
|
|
Self::Searching { .. } => 1,
|
2020-03-12 22:05:49 -07:00
|
|
|
Self::Hashing => 2,
|
|
|
|
Self::Writing { .. } => 3,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn symbol(&self) -> &str {
|
|
|
|
match self {
|
2020-04-06 09:11:17 -07:00
|
|
|
Self::Searching { .. } => "\u{1F9FF}",
|
2020-03-12 22:05:49 -07:00
|
|
|
Self::Hashing => "\u{1F9EE}",
|
|
|
|
Self::Writing { .. } => "\u{1F4BE}",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn total() -> usize {
|
|
|
|
3
|
|
|
|
}
|
|
|
|
|
|
|
|
fn write_message(&self, write: &mut dyn Write) -> io::Result<()> {
|
|
|
|
match self {
|
2020-04-06 09:11:17 -07:00
|
|
|
Self::Searching { input } => match input {
|
|
|
|
InputTarget::Path(path) => write!(write, "Searching `{}` for files…", path.display()),
|
|
|
|
InputTarget::Stdin => write!(write, "Creating single-file torrent from standard input…"),
|
|
|
|
},
|
|
|
|
|
2020-03-12 22:05:49 -07:00
|
|
|
Self::Hashing => write!(write, "Hashing pieces…"),
|
|
|
|
Self::Writing { output } => write!(write, "Writing metainfo to {}…", output),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|