Skip to content

Commit 2f745f1

Browse files
committed
feat: visual feedback on action
1 parent faf5a7d commit 2f745f1

File tree

2 files changed

+52
-14
lines changed

2 files changed

+52
-14
lines changed

src/terminal/app.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::usecases::services_manager::ServicesManager;
2424

2525
use super::components::details::ServiceDetails;
2626
use super::components::filter::{Filter, InputMode};
27-
use super::components::list::TableServices;
27+
use super::components::list::{TableServices, ServiceAction};
2828
use super::components::log::ServiceLog;
2929

3030
#[derive(PartialEq)]
@@ -46,7 +46,8 @@ pub enum Actions {
4646
UpdateDetails,
4747
Filter(String),
4848
UpdateIgnoreListKeys(bool),
49-
EditCurrentService
49+
EditCurrentService,
50+
ServiceAction(ServiceAction)
5051
}
5152

5253
pub enum AppEvent {
@@ -174,6 +175,9 @@ fn spawn_key_event_listener(&self) {
174175
details.on_key_event(key);
175176
}
176177
},
178+
AppEvent::Action(Actions::ServiceAction(action)) => {
179+
table_service.act_on_selected_service(action);
180+
}
177181
AppEvent::Action(Actions::UpdateIgnoreListKeys(bool)) => {
178182
table_service.set_ignore_key_events(bool);
179183
}

src/terminal/components/list.rs

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,50 @@ impl TableServices {
219219
return;
220220
}
221221

222+
self.set_ignore_key_events(true);
223+
224+
match key.code {
225+
KeyCode::Char('r') => {
226+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::Restart))).unwrap();
227+
return;
228+
}
229+
KeyCode::Char('s') => {
230+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::Start))).unwrap();
231+
return;
232+
}
233+
KeyCode::Char('x') => {
234+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::Stop))).unwrap();
235+
return;
236+
}
237+
KeyCode::Char('e') => {
238+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::Enable))).unwrap();
239+
return;
240+
}
241+
KeyCode::Char('d') => {
242+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::Disable))).unwrap();
243+
return;
244+
}
245+
KeyCode::Char('u') => {
246+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::RefreshAll))).unwrap();
247+
return;
248+
}
249+
KeyCode::Char('v') => {
250+
self.sender.send(AppEvent::Action(Actions::GoLog)).unwrap();
251+
return;
252+
}
253+
KeyCode::Char('f') => {
254+
self.sender.send(AppEvent::Action(Actions::ServiceAction(ServiceAction::ToggleFilter))).unwrap();
255+
return;
256+
}
257+
KeyCode::Char('c') => {
258+
self.sender.send(AppEvent::Action(Actions::GoDetails)).unwrap();
259+
return;
260+
}
261+
_ => {}
262+
}
263+
264+
self.set_ignore_key_events(false);
265+
222266
let up_keys = [KeyCode::Up, KeyCode::Char('k')];
223267
let down_keys = [KeyCode::Down, KeyCode::Char('j')];
224268

@@ -227,17 +271,6 @@ impl TableServices {
227271
code if up_keys.contains(&code) => self.select_previous(),
228272
KeyCode::PageDown => self.select_page_down(),
229273
KeyCode::PageUp => self.select_page_up(),
230-
KeyCode::Char('r') => self.act_on_selected_service(ServiceAction::Restart),
231-
KeyCode::Char('s') => self.act_on_selected_service(ServiceAction::Start),
232-
KeyCode::Char('e') => self.act_on_selected_service(ServiceAction::Enable),
233-
KeyCode::Char('d') => self.act_on_selected_service(ServiceAction::Disable),
234-
KeyCode::Char('u') => self.act_on_selected_service(ServiceAction::RefreshAll),
235-
KeyCode::Char('x') => self.act_on_selected_service(ServiceAction::Stop),
236-
KeyCode::Char('v') => self.sender.send(AppEvent::Action(Actions::GoLog)).unwrap(),
237-
KeyCode::Char('f') => self.act_on_selected_service(ServiceAction::ToggleFilter),
238-
KeyCode::Char('c') => {
239-
self.sender.send(AppEvent::Action(Actions::GoDetails)).unwrap();
240-
}
241274
_ => {}
242275
}
243276
}
@@ -298,7 +331,7 @@ impl TableServices {
298331
}
299332
}
300333

301-
fn act_on_selected_service(&mut self, action: ServiceAction) {
334+
pub fn act_on_selected_service(&mut self, action: ServiceAction) {
302335
if let Some(service) = self.get_selected_service() {
303336
let binding_usecase = self.usecase.clone();
304337
let usecase = binding_usecase.borrow();
@@ -319,6 +352,7 @@ impl TableServices {
319352
},
320353
}
321354
}
355+
self.set_ignore_key_events(false);
322356
}
323357

324358
fn handle_service_result(&mut self, result: Result<Service, Box<dyn Error>>) {

0 commit comments

Comments
 (0)