leetcode_tui_core/
progress.rs

1pub struct ProgressCtx {
2    pub(crate) progress: u32,
3    pub(crate) total: u32,
4    pub(crate) title: String,
5    pub(crate) is_visible: bool,
6}
7
8impl Default for ProgressCtx {
9    fn default() -> Self {
10        Self {
11            progress: 0,
12            total: 100,
13            title: "Nothing".into(),
14            is_visible: false,
15        }
16    }
17}
18
19impl ProgressCtx {
20    pub fn set_progress(&mut self, title: String, progress: u32, total: u32) {
21        self.progress = progress;
22        self.total = total;
23        self.title = title;
24        if self.progress == total || self.progress == 0 {
25            self.is_visible = false;
26        } else {
27            self.is_visible = true;
28        }
29    }
30
31    pub fn get_title(&self) -> &str {
32        self.title.as_str()
33    }
34
35    pub fn get_total(&self) -> u32 {
36        self.total
37    }
38
39    pub fn get_progress(&self) -> u32 {
40        self.progress
41    }
42
43    pub fn is_visible(&self) -> bool {
44        self.is_visible
45    }
46}