imdl/subcommand/torrent/create/
create_step.rs

1use crate::common::*;
2
3#[derive(Clone, Copy)]
4pub(crate) enum CreateStep<'a> {
5  Searching { input: &'a InputTarget },
6  Hashing,
7  Writing { output: &'a OutputTarget },
8}
9
10impl Step for CreateStep<'_> {
11  fn n(&self) -> usize {
12    match self {
13      Self::Searching { .. } => 1,
14      Self::Hashing => 2,
15      Self::Writing { .. } => 3,
16    }
17  }
18
19  fn symbol(&self) -> &str {
20    match self {
21      Self::Searching { .. } => "\u{1F9FF}",
22      Self::Hashing => "\u{1F9EE}",
23      Self::Writing { .. } => "\u{1F4BE}",
24    }
25  }
26
27  fn total() -> usize {
28    3
29  }
30
31  fn write_message(&self, write: &mut dyn Write) -> io::Result<()> {
32    match self {
33      Self::Searching { input } => match input {
34        InputTarget::Path(path) => write!(write, "Searching `{}` for files…", path.display()),
35        InputTarget::Stdin => write!(write, "Creating single-file torrent from standard input…"),
36      },
37
38      Self::Hashing => write!(write, "Hashing pieces…"),
39      Self::Writing { output } => write!(write, "Writing metainfo to {output}…"),
40    }
41  }
42}