summaryrefslogtreecommitdiffstats
path: root/src/commands/file_ops/paste.rs
blob: 74136c6e8f760188b6cbb07daba1527aed22a8c5 (plain)
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
use crate::commands::{JoshutoCommand, JoshutoRunnable};
use crate::context::JoshutoContext;
use crate::error::JoshutoResult;
use crate::io::Options;
use crate::ui::TuiBackend;

use super::local_state::{FileOp, LocalState};
use super::paste_copy::paste_copy;
use super::paste_cut::paste_cut;

pub struct PasteFiles {
    options: Options,
}

impl JoshutoCommand for PasteFiles {}

impl std::fmt::Display for PasteFiles {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(
            f,
            "{} overwrite={} skip_exist={}",
            Self::command(),
            self.options.overwrite,
            self.options.skip_exist,
        )
    }
}

impl std::fmt::Debug for PasteFiles {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        f.write_str(Self::command())
    }
}

impl JoshutoRunnable for PasteFiles {
    fn execute(&self, context: &mut JoshutoContext, _: &mut TuiBackend) -> JoshutoResult<()> {
        let file_operation = LocalState::get_file_operation();
        let thread = match file_operation {
            FileOp::Copy => paste_copy(context, self.options.clone()),
            FileOp::Cut => paste_cut(context, self.options.clone()),
        };
        let thread = thread?;
        context.add_new_worker(thread);
        Ok(())
    }
}

impl PasteFiles {
    pub fn new(options: Options) -> Self {
        PasteFiles { options }
    }
    pub const fn command() -> &'static str {
        "paste_files"
    }
}