aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins/sequence/src/state/command_entry.rs
blob: 4ca9350aa3e01375d724d093030868c3fc5c18b6 (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
use super::{ChainType, CommandStatus};
use std::path::PathBuf;
use zellij_tile::prelude::PaneId;

#[derive(Debug, Clone)]
pub struct CommandEntry {
    text: String,
    cwd: Option<PathBuf>,
    pub(super) chain_type: ChainType,
    pub(super) status: CommandStatus,
}

impl Default for CommandEntry {
    fn default() -> Self {
        CommandEntry {
            text: String::default(),
            cwd: None,
            chain_type: ChainType::default(),
            status: CommandStatus::default(),
        }
    }
}

impl CommandEntry {
    pub fn new(text: &str, cwd: Option<PathBuf>) -> Self {
        CommandEntry {
            text: text.to_owned(),
            cwd,
            ..Default::default()
        }
    }
    pub fn get_text(&self) -> String {
        self.text.clone()
    }
    pub fn set_text(&mut self, text: String) {
        self.text = text;
    }
    pub fn clear_text(&mut self) {
        self.text.clear();
    }
    pub fn get_chain_type(&self) -> ChainType {
        self.chain_type
    }
    pub fn set_chain_type(&mut self, chain_type: ChainType) {
        self.chain_type = chain_type;
    }
    pub fn get_status(&self) -> CommandStatus {
        self.status.clone()
    }
    pub fn set_status(&mut self, status: CommandStatus) {
        self.status = status;
    }
    pub fn get_pane_id(&self) -> Option<PaneId> {
        self.status.get_pane_id()
    }
    pub fn is_empty(&self) -> bool {
        self.text.trim().is_empty()
    }
    pub fn fill_chain_type_if_empty(&mut self) {
        if let ChainType::None = self.chain_type {
            self.chain_type = ChainType::And;
        }
    }
    pub fn clear_chain_type(&mut self) {
        self.chain_type = ChainType::None;
    }
    pub fn clear_status(&mut self) {
        self.status = CommandStatus::Pending;
    }
    pub fn get_cwd(&self) -> Option<PathBuf> {
        self.cwd.clone()
    }
    pub fn set_cwd(&mut self, cwd: Option<PathBuf>) {
        self.cwd = cwd;
    }
}