(
terminal: &mut Terminal<B>,
music_path: Option<PathBuf>,
)
| 16 | }; |
| 17 | |
| 18 | pub fn run_app<B: Backend>( |
| 19 | terminal: &mut Terminal<B>, |
| 20 | music_path: Option<PathBuf>, |
| 21 | ) -> io::Result<()> { |
| 22 | terminal.clear()?; |
| 23 | terminal.hide_cursor()?; |
| 24 | |
| 25 | let music_path = music_path.unwrap_or_else(|| Path::new("example_music").to_path_buf()); |
| 26 | let mut jukebox_state = jukebox_state::JukeboxState::new(&music_path); |
| 27 | let mut canvas_state = canvas_state::CanvasState::new(); |
| 28 | loop { |
| 29 | terminal.draw(|f| { |
| 30 | let size = f.area(); |
| 31 | |
| 32 | let vertical_chunks = make_vertical_chunks(size, &[80, 20]); |
| 33 | |
| 34 | let top_chunks = make_horizontal_chunks(vertical_chunks[0], &[70, 30]); |
| 35 | |
| 36 | let jukebox_chunk = top_chunks[0]; // Show jukebox matrix |
| 37 | let controls_info_chunk = make_horizontal_chunks(vertical_chunks[1], &[50, 50]); |
| 38 | let controls_chunk = controls_info_chunk[0]; // Show controls |
| 39 | let info_chunk = controls_info_chunk[1]; // Show info block |
| 40 | let song_chunk = top_chunks[1]; // Show playlist side |
| 41 | |
| 42 | render_info_block(f, info_chunk, &jukebox_state); |
| 43 | render_playlist_side(f, song_chunk, &jukebox_state); |
| 44 | render_jukebox_matrix(f, jukebox_chunk, &mut canvas_state, &jukebox_state); |
| 45 | render_controls_block(f, controls_chunk); |
| 46 | })?; |
| 47 | |
| 48 | // Check if the song has ended |
| 49 | jukebox_state.handle_song_end(); |
| 50 | |
| 51 | if event::poll(std::time::Duration::from_millis(100))? { |
| 52 | if let event::Event::Key(key) = event::read()? { |
| 53 | if key.kind == event::KeyEventKind::Press { |
| 54 | match key.code { |
| 55 | event::KeyCode::Char('q') => break, |
| 56 | event::KeyCode::Char('p') => jukebox_state.play(), |
| 57 | event::KeyCode::Char('s') => jukebox_state.pause(), |
| 58 | event::KeyCode::Char('+') => jukebox_state.add_volume(10), |
| 59 | event::KeyCode::Char('-') => jukebox_state.sub_volume(10), |
| 60 | event::KeyCode::Down => jukebox_state.move_selection(1), |
| 61 | event::KeyCode::Up => jukebox_state.move_selection(-1), |
| 62 | event::KeyCode::Enter => jukebox_state.play(), |
| 63 | _ => {} |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | Ok(()) |
| 70 | } |
no test coverage detected