Skip to content

Commit 4d2740e

Browse files
committed
Update list component implementation
1 parent 61f6e62 commit 4d2740e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/terminal/components/list.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ pub enum ServiceAction {
5959
Disable,
6060
RefreshAll,
6161
ToggleFilter,
62-
ToggleMask
62+
ToggleMask,
63+
ToggleActiveFilter,
6364
}
6465

6566
pub struct TableServices {
@@ -73,6 +74,7 @@ pub struct TableServices {
7374
sender: Sender<AppEvent>,
7475
usecase: Rc<RefCell<ServicesManager>>,
7576
filter_all: bool,
77+
show_active_only: bool,
7678
}
7779

7880
impl TableServices {
@@ -131,6 +133,7 @@ impl TableServices {
131133
ignore_key_events: false,
132134
usecase,
133135
filter_all,
136+
show_active_only: false,
134137
}
135138
}
136139

@@ -210,7 +213,13 @@ impl TableServices {
210213
.into_iter()
211214
.filter(|service| {
212215
let name = service.name();
213-
name.to_lowercase().contains(&lower_filter)
216+
let name_matches = name.to_lowercase().contains(&lower_filter);
217+
let active_matches = if self.show_active_only {
218+
service.state().active() == "active"
219+
} else {
220+
true
221+
};
222+
name_matches && active_matches
214223
})
215224
.collect()
216225
}
@@ -251,6 +260,10 @@ impl TableServices {
251260
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::ToggleFilter))).unwrap();
252261
return;
253262
}
263+
KeyCode::Char('a') => {
264+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::ToggleActiveFilter))).unwrap();
265+
return;
266+
}
254267
KeyCode::Char('m') => {
255268
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::ToggleMask))).unwrap();
256269
return;
@@ -360,6 +373,11 @@ impl TableServices {
360373
self.filter_all = !self.filter_all;
361374
self.fetch_and_refresh(self.old_filter_text.clone());
362375
},
376+
ServiceAction::ToggleActiveFilter => {
377+
self.table_state.select(Some(0));
378+
self.show_active_only = !self.show_active_only;
379+
self.refresh(self.old_filter_text.clone());
380+
},
363381
ServiceAction::RefreshAll => {
364382
self.fetch_services();
365383
self.fetch_and_refresh(self.old_filter_text.clone());
@@ -396,7 +414,7 @@ impl TableServices {
396414
)));
397415

398416
help_text.push(Line::from(
399-
"Navigate: ↑/↓ | Switch tab: ←/→ | List all: f | Start: s | Stop: x | Restart: r | Enable: e | Disable: d | Mask/Unmask: m | Refresh list: u | Log: v | Unit File: c"
417+
"Navigate: ↑/↓ | Switch tab: ←/→ | List all: f | Active only: a | Start: s | Stop: x | Restart: r | Enable: e | Disable: d | Mask/Unmask: m | Refresh list: u | Log: v | Unit File: c"
400418
));
401419
}
402420

0 commit comments

Comments
 (0)