summaryrefslogtreecommitdiffstats
path: root/src/context.rs
blob: 863acbc94b31545b6d824425925da8760a954b08 (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
use commands::FileOperationThread;
use config;
use tab::JoshutoTab;
use window::JoshutoView;

pub struct JoshutoContext {
    pub username: String,
    pub hostname: String,
    pub threads: Vec<FileOperationThread>,
    pub views: JoshutoView,
    pub curr_tab_index: usize,
    pub tabs: Vec<JoshutoTab>,
    pub exit: bool,

    pub config_t: config::JoshutoConfig,
}

impl JoshutoContext {
    pub fn new(config_t: config::JoshutoConfig) -> Self {
        let username: String = whoami::username();
        let hostname: String = whoami::hostname();

        let views: JoshutoView = JoshutoView::new(config_t.column_ratio);

        JoshutoContext {
            username,
            hostname,
            threads: Vec::new(),
            views,
            curr_tab_index: 0,
            tabs: Vec::new(),
            exit: false,
            config_t,
        }
    }
    pub fn curr_tab_ref(&self) -> &JoshutoTab {
        &self.tabs[self.curr_tab_index]
    }
    pub fn curr_tab_mut(&mut self) -> &mut JoshutoTab {
        &mut self.tabs[self.curr_tab_index]
    }
}