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: CurrentDisplayMode: None: allow no display mode

Changed files
+54 -36
src
+54 -36
src/app.rs
··· 97 97 Oscilloscope, 98 98 Vectorscope, 99 99 Spectroscope, 100 + None, 100 101 } 101 102 102 103 pub struct App { ··· 316 317 let mut datasets = Vec::new(); 317 318 let graph = self.graph.clone(); // TODO cheap fix... 318 319 if self.graph.references { 319 - datasets.append(&mut self.current_display_mut().references(&graph)); 320 + if let Some(current_display) = self.current_display() { 321 + datasets.append(&mut current_display.references(&graph)); 322 + } 320 323 } 321 - datasets.append(&mut self.current_display_mut().process(&graph, &channels)); 324 + if let Some(current_display) = self.current_display_mut() { 325 + datasets.append(&mut current_display.process(&graph, &channels)); 326 + } 322 327 terminal 323 328 .draw(|f| { 324 329 let mut size = f.size(); 325 330 render_frame(new_state.clone(), f); 326 - if self.graph.show_ui { 327 - f.render_widget( 328 - make_header( 329 - &self.graph, 330 - &self.current_display().header(&self.graph), 331 - self.current_display().mode_str(), 332 - framerate, 333 - self.graph.pause, 334 - ), 335 - Rect { 336 - x: size.x, 337 - y: size.y + 6, 338 - width: size.width, 339 - height: 1, 340 - }, 341 - ); 342 - size.height -= 7; 343 - size.y += 7; 331 + if let Some(current_display) = self.current_display() { 332 + if self.graph.show_ui { 333 + f.render_widget( 334 + make_header( 335 + &self.graph, 336 + &current_display.header(&self.graph), 337 + current_display.mode_str(), 338 + framerate, 339 + self.graph.pause, 340 + ), 341 + Rect { 342 + x: size.x, 343 + y: size.y + 7, 344 + width: size.width, 345 + height: 1, 346 + }, 347 + ); 348 + size.height -= 8; 349 + size.y += 8; 350 + } 351 + let chart = Chart::new(datasets.iter().map(|x| x.into()).collect()) 352 + .x_axis(current_display.axis(&self.graph, Dimension::X)) // TODO allow to have axis sometimes? 353 + .y_axis(current_display.axis(&self.graph, Dimension::Y)); 354 + f.render_widget(chart, size) 344 355 } 345 - let chart = Chart::new(datasets.iter().map(|x| x.into()).collect()) 346 - .x_axis(self.current_display().axis(&self.graph, Dimension::X)) // TODO allow to have axis sometimes? 347 - .y_axis(self.current_display().axis(&self.graph, Dimension::Y)); 348 - f.render_widget(chart, size) 349 356 }) 350 357 .unwrap(); 351 358 } ··· 360 367 { 361 368 return; 362 369 } 363 - self.current_display_mut().handle(event); 370 + if let Some(current_display) = self.current_display_mut() { 371 + current_display.handle(event); 372 + } 364 373 } 365 374 } 366 375 } 367 376 368 - fn current_display_mut(&mut self) -> &mut dyn DisplayMode { 377 + fn current_display_mut(&mut self) -> Option<&mut dyn DisplayMode> { 369 378 match self.mode { 370 - CurrentDisplayMode::Oscilloscope => &mut self.oscilloscope as &mut dyn DisplayMode, 371 - CurrentDisplayMode::Vectorscope => &mut self.vectorscope as &mut dyn DisplayMode, 372 - CurrentDisplayMode::Spectroscope => &mut self.spectroscope as &mut dyn DisplayMode, 379 + CurrentDisplayMode::Oscilloscope => { 380 + Some(&mut self.oscilloscope as &mut dyn DisplayMode) 381 + } 382 + CurrentDisplayMode::Vectorscope => Some(&mut self.vectorscope as &mut dyn DisplayMode), 383 + CurrentDisplayMode::Spectroscope => { 384 + Some(&mut self.spectroscope as &mut dyn DisplayMode) 385 + } 386 + CurrentDisplayMode::None => None, 373 387 } 374 388 } 375 389 376 - fn current_display(&self) -> &dyn DisplayMode { 390 + fn current_display(&self) -> Option<&dyn DisplayMode> { 377 391 match self.mode { 378 - CurrentDisplayMode::Oscilloscope => &self.oscilloscope as &dyn DisplayMode, 379 - CurrentDisplayMode::Vectorscope => &self.vectorscope as &dyn DisplayMode, 380 - CurrentDisplayMode::Spectroscope => &self.spectroscope as &dyn DisplayMode, 392 + CurrentDisplayMode::Oscilloscope => Some(&self.oscilloscope as &dyn DisplayMode), 393 + CurrentDisplayMode::Vectorscope => Some(&self.vectorscope as &dyn DisplayMode), 394 + CurrentDisplayMode::Spectroscope => Some(&self.spectroscope as &dyn DisplayMode), 395 + CurrentDisplayMode::None => None, 381 396 } 382 397 } 383 398 ··· 477 492 // switch modes 478 493 match self.mode { 479 494 CurrentDisplayMode::Oscilloscope => { 480 - self.mode = CurrentDisplayMode::Vectorscope 495 + self.mode = CurrentDisplayMode::Vectorscope; 481 496 } 482 497 CurrentDisplayMode::Vectorscope => { 483 - self.mode = CurrentDisplayMode::Spectroscope 498 + self.mode = CurrentDisplayMode::Spectroscope; 484 499 } 485 500 CurrentDisplayMode::Spectroscope => { 486 - self.mode = CurrentDisplayMode::Oscilloscope 501 + self.mode = CurrentDisplayMode::None; 502 + } 503 + CurrentDisplayMode::None => { 504 + self.mode = CurrentDisplayMode::Oscilloscope; 487 505 } 488 506 } 489 507 }