1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use anyhow::Result;
use async_trait::async_trait;
use std::path::PathBuf;
use tokio::sync::mpsc::UnboundedSender;

/// File handling and production of directories to work with
pub mod dirs;
/// Command-line execution runners
pub mod exec;
/// Creating different behaviours from the program options
pub mod factory;
/// Program and command line options
pub mod options;
/// Render the directory's outputs as text
pub mod renderers;
/// Styling for commands
pub mod styling;
/// Managing the tags
pub mod tag;

pub mod cmds;

#[async_trait]
pub trait DirRunner: Send + Sync {
    async fn process(
        &self,
        dir: PathBuf,
        sender: UnboundedSender<CommandMessage>,
    ) -> Result<CommandOutput>;
}

pub trait Renderer {
    fn process(&self, msg: CommandMessage) -> Result<()>;
}

#[derive(Debug)]
pub enum CommandMessage {
    Increment(CommandOutput),
    Progress(CommandProgress),
    Final(Result<CommandOutput>),
}

#[derive(Debug)]
pub struct CommandProgress {
    progress: u32,
    out_of: u32,
    message: String,
    dir: PathBuf,
}

#[derive(Debug)]
pub struct CommandOutput {
    output: String,
    error: String,
    dir: PathBuf,
}

pub struct DebugRenderer {}

impl Renderer for DebugRenderer {
    fn process(&self, msg: CommandMessage) -> Result<()> {
        dbg!(&msg);
        Ok(())
    }
}