Skip to content

Commit 17a3514

Browse files
committed
refactored: output cycling logic
1 parent d4c1a75 commit 17a3514

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/app/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ pub mod selected_tab;
1313
pub struct App {
1414
pub connections: Arc<Mutex<Vec<Connection>>>,
1515
pub output_fmt: OutputFmt,
16+
17+
/// The index of the connection displayed in the Log tab.
1618
pub selected_tab: SelectedTab,
19+
20+
/// The index of the connection displayed in the Log tab.
1721
log_conn_idx: usize,
22+
23+
/// Indicates if the user has begun quitting the app.
1824
is_closing: bool,
1925
}
2026

@@ -56,11 +62,8 @@ impl App {
5662
)
5763
}
5864

59-
pub const fn cycle_output_fmt(&mut self) {
60-
self.output_fmt = match self.output_fmt {
61-
OutputFmt::Line => OutputFmt::Bullet,
62-
OutputFmt::Bullet => OutputFmt::Line,
63-
};
65+
pub fn cycle_output_fmt(&mut self) {
66+
self.output_fmt = self.output_fmt.next();
6467
}
6568

6669
pub fn next_log_conn(&mut self) {

src/app/output_fmt.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use clap::{ValueEnum, builder::PossibleValue};
2+
use strum::EnumIter;
3+
use strum::IntoEnumIterator;
24

3-
#[derive(Default, Copy, Clone)]
5+
#[derive(Default, Copy, Clone, EnumIter, PartialEq, Eq)]
46
pub enum OutputFmt {
57
#[default]
68
Line,
@@ -20,3 +22,17 @@ impl ValueEnum for OutputFmt {
2022
}
2123
}
2224
}
25+
26+
impl OutputFmt {
27+
/// Returns the "next" output format, in cyclic fashion.
28+
///
29+
/// Is using a cycling `strum` iterator overkill for this? Probably.
30+
/// Whatever. It's scalable, yo.
31+
pub fn next(self) -> Self {
32+
let mut iter = Self::iter().cycle();
33+
34+
iter.find(|f| *f == self);
35+
36+
iter.next().unwrap()
37+
}
38+
}

0 commit comments

Comments
 (0)