Browse and listen to thousands of radio stations across the globe right from your terminal ๐ŸŒŽ ๐Ÿ“ป ๐ŸŽตโœจ
radio rust tokio web-radio command-line-tool tui

app: App: process_events(): refactor: use closures for common

Changed files
+28 -30
src
+28 -30
src/app.rs
··· 404 404 ) -> Result<bool, io::Error> { 405 405 let mut quit = false; 406 406 407 + let play = |graph: &mut GraphConfig| { 408 + graph.pause = false; 409 + sink_cmd_tx 410 + .send(SinkCommand::Play) 411 + .expect("receiver never dropped"); 412 + }; 413 + 414 + let pause = |graph: &mut GraphConfig| { 415 + graph.pause = true; 416 + sink_cmd_tx 417 + .send(SinkCommand::Pause) 418 + .expect("receiver never dropped"); 419 + }; 420 + 421 + let toggle_play_pause = |graph: &mut GraphConfig| { 422 + graph.pause = !graph.pause; 423 + let sink_cmd = if graph.pause { 424 + SinkCommand::Pause 425 + } else { 426 + SinkCommand::Play 427 + }; 428 + sink_cmd_tx.send(sink_cmd).expect("receiver never dropped"); 429 + }; 430 + 407 431 let lower_volume = || { 408 432 let mut state = state.lock().unwrap(); 409 433 state.volume.change_volume(-1.0); ··· 468 492 0..self.graph.width * 2, 469 493 ), 470 494 KeyCode::Char('q') => quit = true, 471 - KeyCode::Char(' ') => { 472 - self.graph.pause = !self.graph.pause; 473 - let sink_cmd = if self.graph.pause { 474 - SinkCommand::Pause 475 - } else { 476 - SinkCommand::Play 477 - }; 478 - sink_cmd_tx.send(sink_cmd).expect("receiver never dropped"); 479 - } 495 + KeyCode::Char(' ') => toggle_play_pause(&mut self.graph), 480 496 KeyCode::Char('s') => self.graph.scatter = !self.graph.scatter, 481 497 KeyCode::Char('h') => self.graph.show_ui = !self.graph.show_ui, 482 498 KeyCode::Char('r') => self.graph.references = !self.graph.references, ··· 506 522 } 507 523 } 508 524 KeyCode::Media(media_key_code) => match media_key_code { 509 - MediaKeyCode::Play => { 510 - self.graph.pause = false; 511 - sink_cmd_tx 512 - .send(SinkCommand::Play) 513 - .expect("receiver never dropped"); 514 - } 515 - MediaKeyCode::Pause => { 516 - self.graph.pause = true; 517 - sink_cmd_tx 518 - .send(SinkCommand::Pause) 519 - .expect("receiver never dropped"); 520 - } 521 - MediaKeyCode::PlayPause => { 522 - self.graph.pause = !self.graph.pause; 523 - let sink_cmd = if self.graph.pause { 524 - SinkCommand::Pause 525 - } else { 526 - SinkCommand::Play 527 - }; 528 - sink_cmd_tx.send(sink_cmd).expect("receiver never dropped"); 529 - } 525 + MediaKeyCode::Play => play(&mut self.graph), 526 + MediaKeyCode::Pause => pause(&mut self.graph), 527 + MediaKeyCode::PlayPause => toggle_play_pause(&mut self.graph), 530 528 MediaKeyCode::Stop => { 531 529 quit = true; 532 530 }