From 5c9bbe8952001582c543c476ae805fe414a227c2 Mon Sep 17 00:00:00 2001 From: Alexandre Pasmantier Date: Mon, 5 May 2025 20:32:03 +0200 Subject: [PATCH] wip: a bit of linting --- television/app.rs | 6 ++--- television/channels/mod.rs | 2 +- television/cli/mod.rs | 2 +- television/main.rs | 2 +- television/preview/previewer.rs | 6 +---- television/screen/preview.rs | 2 +- television/television.rs | 1 + tests/app.rs | 46 ++++++++++++++++++++++----------- 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/television/app.rs b/television/app.rs index 329eb17..744b6b6 100644 --- a/television/app.rs +++ b/television/app.rs @@ -142,7 +142,7 @@ impl App { config: Config, input: Option, options: AppOptions, - cable_channels: CableChannelPrototypes, + cable_channels: &CableChannelPrototypes, ) -> Self { let (action_tx, action_rx) = mpsc::unbounded_channel(); let (render_tx, render_rx) = mpsc::unbounded_channel(); @@ -160,7 +160,7 @@ impl App { options.no_remote, options.no_help, options.exact, - CableChannelPrototypes(cable_channels.clone()), + CableChannelPrototypes((*cable_channels).clone()), ); Self { @@ -452,7 +452,7 @@ mod test { Config::default(), None, AppOptions::default(), - CableChannelPrototypes::default(), + &CableChannelPrototypes::default(), ); app.television .results_picker diff --git a/television/channels/mod.rs b/television/channels/mod.rs index e39fc79..f28e822 100644 --- a/television/channels/mod.rs +++ b/television/channels/mod.rs @@ -136,7 +136,7 @@ impl TelevisionChannel { TelevisionChannel::RemoteControl(remote_control) => { remote_control.zap(channel_name) } - _ => unreachable!(), + TelevisionChannel::Cable(_) => unreachable!(), } } diff --git a/television/cli/mod.rs b/television/cli/mod.rs index 43c2d90..0eaee0c 100644 --- a/television/cli/mod.rs +++ b/television/cli/mod.rs @@ -121,7 +121,7 @@ impl From for PostProcessedCli { if let Some(preview_cmd) = &preview_command { channel.preview_command = Some(preview_cmd.command.clone()); channel.preview_delimiter = Some(preview_cmd.delimiter.clone()); - channel.preview_offset = preview_cmd.offset_expr.clone(); + channel.preview_offset.clone_from(&preview_cmd.offset_expr); } Self { diff --git a/television/main.rs b/television/main.rs index 82ff12f..88374e7 100644 --- a/television/main.rs +++ b/television/main.rs @@ -78,7 +78,7 @@ async fn main() -> Result<()> { config.application.tick_rate, ); let mut app = - App::new(channel, config, args.input, options, cable_channels); + App::new(channel, config, args.input, options, &cable_channels); stdout().flush()?; debug!("Running application..."); let output = app.run(stdout().is_terminal(), false).await?; diff --git a/television/preview/previewer.rs b/television/preview/previewer.rs index 1954a1a..1ab5c36 100644 --- a/television/preview/previewer.rs +++ b/television/preview/previewer.rs @@ -132,10 +132,6 @@ pub fn try_preview( impl From<&CableChannelPrototype> for Option { fn from(value: &CableChannelPrototype) -> Self { - if let Some(preview_command) = value.into() { - Some(Previewer::new(preview_command)) - } else { - None - } + Option::::from(value).map(Previewer::new) } } diff --git a/television/screen/preview.rs b/television/screen/preview.rs index b468b29..eb2dff6 100644 --- a/television/screen/preview.rs +++ b/television/screen/preview.rs @@ -51,7 +51,7 @@ pub fn draw_preview_content_block( pub fn build_preview_paragraph( inner: Rect, preview_content: &PreviewContent, - target_line: Option, + #[allow(unused_variables)] target_line: Option, preview_scroll: u16, ) -> Paragraph<'_> { let preview_block = diff --git a/television/television.rs b/television/television.rs index 78f6dff..2db4a32 100644 --- a/television/television.rs +++ b/television/television.rs @@ -66,6 +66,7 @@ pub struct Television { } impl Television { + #[allow(clippy::too_many_arguments)] #[must_use] pub fn new( action_tx: UnboundedSender, diff --git a/tests/app.rs b/tests/app.rs index 5886388..c04c736 100644 --- a/tests/app.rs +++ b/tests/app.rs @@ -3,7 +3,9 @@ use std::{collections::HashSet, path::PathBuf, time::Duration}; use television::{ action::Action, app::{App, AppOptions}, - channels::{cable::prototypes::CableChannelPrototype, TelevisionChannel}, + channels::cable::prototypes::{ + CableChannelPrototype, CableChannelPrototypes, + }, config::default_config_from_file, }; use tokio::{task::JoinHandle, time::timeout}; @@ -21,19 +23,19 @@ const DEFAULT_TIMEOUT: Duration = Duration::from_millis(100); /// The app is started in a separate task and can be interacted with by sending /// actions to the action channel. fn setup_app( - channel: Option, + channel_prototype: Option, select_1: bool, exact: bool, ) -> ( JoinHandle, tokio::sync::mpsc::UnboundedSender, ) { - let chan: TelevisionChannel = channel.unwrap_or_else(|| { + let chan: CableChannelPrototype = channel_prototype.unwrap_or_else(|| { let target_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")) .join("tests") .join("target_dir"); std::env::set_current_dir(&target_dir).unwrap(); - TelevisionChannel::Cable(CableChannelPrototype::default().into()) + CableChannelPrototype::default() }); let mut config = default_config_from_file().unwrap(); // this speeds up the tests @@ -47,7 +49,13 @@ fn setup_app( false, config.application.tick_rate, ); - let mut app = App::new(chan, config, input, options); + let mut app = App::new( + chan, + config, + input, + options, + &CableChannelPrototypes::default(), + ); // retrieve the app's action channel handle in order to send a quit action let tx = app.action_tx.clone(); @@ -212,11 +220,15 @@ async fn test_app_exact_search_positive() { #[tokio::test(flavor = "multi_thread", worker_threads = 3)] async fn test_app_exits_when_select_1_and_only_one_result() { - let channel = - TelevisionChannel::Stdin(television::channels::stdin::Channel::from( - vec!["file1.txt".to_string()], - )); - let (f, tx) = setup_app(Some(channel), true, false); + let prototype = CableChannelPrototype::new( + "cable", + "echo file1.txt", + false, + None, + None, + None, + ); + let (f, tx) = setup_app(Some(prototype), true, false); // tick a few times to get the results for _ in 0..=10 { @@ -246,11 +258,15 @@ async fn test_app_exits_when_select_1_and_only_one_result() { #[tokio::test(flavor = "multi_thread", worker_threads = 3)] async fn test_app_does_not_exit_when_select_1_and_more_than_one_result() { - let channel = - TelevisionChannel::Stdin(television::channels::stdin::Channel::from( - vec!["file1.txt".to_string(), "file2.txt".to_string()], - )); - let (f, tx) = setup_app(Some(channel), true, false); + let prototype = CableChannelPrototype::new( + "cable", + "echo 'file1.txt\nfile2.txt'", + false, + None, + None, + None, + ); + let (f, tx) = setup_app(Some(prototype), true, false); // tick a few times to get the results for _ in 0..=10 {