Merge pull request #174 from lj3954/refactor_theme_switching

refactor: Modify theme in place
This commit is contained in:
Chris Titus 2024-09-02 16:36:04 -05:00 committed by GitHub
commit 33840d3330
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View File

@ -202,8 +202,8 @@ impl AppState {
self.refresh_tab(); self.refresh_tab();
} }
KeyCode::Char('/') => self.enter_search(), KeyCode::Char('/') => self.enter_search(),
KeyCode::Char('t') => self.theme = self.theme.next(), KeyCode::Char('t') => self.theme.next(),
KeyCode::Char('T') => self.theme = self.theme.prev(), KeyCode::Char('T') => self.theme.prev(),
_ => {} _ => {}
}, },
Focus::List if key.kind != KeyEventKind::Release => match key.code { Focus::List if key.kind != KeyEventKind::Release => match key.code {
@ -220,8 +220,8 @@ impl AppState {
} }
KeyCode::Char('/') => self.enter_search(), KeyCode::Char('/') => self.enter_search(),
KeyCode::Tab => self.focus = Focus::TabList, KeyCode::Tab => self.focus = Focus::TabList,
KeyCode::Char('t') => self.theme = self.theme.next(), KeyCode::Char('t') => self.theme.next(),
KeyCode::Char('T') => self.theme = self.theme.prev(), KeyCode::Char('T') => self.theme.prev(),
_ => {} _ => {}
}, },
_ => {} _ => {}

View File

@ -86,17 +86,15 @@ impl Theme {
} }
impl Theme { impl Theme {
#[allow(unused)] pub fn next(&mut self) {
pub fn next(self) -> Self { let position = *self as usize;
let position = self as usize;
let types = Theme::value_variants(); let types = Theme::value_variants();
types[(position + 1) % types.len()].into() *self = types[(position + 1) % types.len()];
} }
#[allow(unused)] pub fn prev(&mut self) {
pub fn prev(self) -> Self { let position = *self as usize;
let position = self as usize;
let types = Theme::value_variants(); let types = Theme::value_variants();
types[(position + types.len() - 1) % types.len()].into() *self = types[(position + types.len() - 1) % types.len()];
} }
} }