hex_patch/app/popup/
binary_choice.rs

1use ratatui::text::{Line, Span};
2
3use crate::app::settings::color_settings::ColorSettings;
4
5#[derive(Debug, Clone, Copy, PartialEq)]
6pub enum BinaryChoice {
7    Yes,
8    No,
9}
10
11impl BinaryChoice {
12    pub fn to_line(&self, color_settings: &ColorSettings) -> Line<'static> {
13        let mut ret = Line::from(vec![
14            Span::styled(t!("app.yes"), color_settings.yes),
15            Span::raw("  "),
16            Span::styled(t!("app.no"), color_settings.no),
17        ]);
18
19        match self {
20            BinaryChoice::Yes => ret.spans[0].style = color_settings.yes_selected,
21            BinaryChoice::No => ret.spans[2].style = color_settings.no_selected,
22        }
23
24        ret
25    }
26
27    pub fn next(&self) -> Self {
28        match self {
29            BinaryChoice::Yes => BinaryChoice::No,
30            BinaryChoice::No => BinaryChoice::Yes,
31        }
32    }
33
34    pub fn previous(&self) -> Self {
35        match self {
36            BinaryChoice::Yes => BinaryChoice::No,
37            BinaryChoice::No => BinaryChoice::Yes,
38        }
39    }
40}