1#[derive(Default)]
5pub struct ErrorModal {
6 pub active: bool,
7 pub message: String,
8 pub scroll: usize,
10}
11
12impl ErrorModal {
13 pub fn new() -> Self {
14 Self::default()
15 }
16
17 pub fn show(&mut self, message: String) {
18 log::error!(target: "datui", "{message}");
21 self.active = true;
22 self.message = message;
23 self.scroll = 0;
24 }
25
26 pub fn hide(&mut self) {
27 self.active = false;
28 self.message.clear();
29 self.scroll = 0;
30 }
31}
32
33pub struct Flash {
39 pub message: String,
40 pub(crate) path_from: Option<usize>,
43 pub(crate) expires: std::time::Instant,
44}
45
46impl Flash {
47 pub(crate) fn new(message: String) -> Self {
48 Self {
49 message,
50 path_from: None,
51 expires: std::time::Instant::now() + std::time::Duration::from_secs(2),
52 }
53 }
54
55 pub(crate) fn path(prefix: &str, path: &std::path::Path) -> Self {
57 let mut flash = Self::new(format!("{prefix}{}", path.display()));
58 flash.path_from = Some(prefix.len());
59 flash
60 }
61
62 pub(crate) fn expired(&self) -> bool {
63 std::time::Instant::now() >= self.expires
64 }
65}
66
67pub struct ConfirmationModal {
68 pub active: bool,
69 pub message: String,
70 pub focus_yes: bool, pub yes_label: &'static str,
73 pub no_label: &'static str,
75 pub scroll: usize,
77}
78
79impl Default for ConfirmationModal {
80 fn default() -> Self {
81 Self {
82 active: false,
83 message: String::new(),
84 focus_yes: true,
85 yes_label: "Yes",
86 no_label: "No",
87 scroll: 0,
88 }
89 }
90}
91
92impl ConfirmationModal {
93 pub fn new() -> Self {
94 Self::default()
95 }
96
97 pub fn show(&mut self, message: String) {
98 self.active = true;
99 self.message = message;
100 self.focus_yes = true; self.yes_label = "Yes";
102 self.no_label = "No";
103 self.scroll = 0;
104 }
105
106 pub fn show_choice(
108 &mut self,
109 message: String,
110 yes_label: &'static str,
111 no_label: &'static str,
112 ) {
113 self.show(message);
114 self.yes_label = yes_label;
115 self.no_label = no_label;
116 }
117
118 pub fn show_destructive(&mut self, message: String, yes_label: &'static str) {
121 self.active = true;
122 self.message = message;
123 self.focus_yes = false;
124 self.yes_label = yes_label;
125 self.no_label = "No";
126 self.scroll = 0;
127 }
128
129 pub fn hide(&mut self) {
130 self.active = false;
131 self.message.clear();
132 self.focus_yes = true;
133 self.yes_label = "Yes";
134 self.no_label = "No";
135 self.scroll = 0;
136 }
137}