mirror of
https://github.com/alexpasmantier/television.git
synced 2025-06-07 03:55:23 +00:00
wip: a bit of linting
This commit is contained in:
parent
53989acec1
commit
5c9bbe8952
@ -142,7 +142,7 @@ impl App {
|
|||||||
config: Config,
|
config: Config,
|
||||||
input: Option<String>,
|
input: Option<String>,
|
||||||
options: AppOptions,
|
options: AppOptions,
|
||||||
cable_channels: CableChannelPrototypes,
|
cable_channels: &CableChannelPrototypes,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
let (action_tx, action_rx) = mpsc::unbounded_channel();
|
||||||
let (render_tx, render_rx) = mpsc::unbounded_channel();
|
let (render_tx, render_rx) = mpsc::unbounded_channel();
|
||||||
@ -160,7 +160,7 @@ impl App {
|
|||||||
options.no_remote,
|
options.no_remote,
|
||||||
options.no_help,
|
options.no_help,
|
||||||
options.exact,
|
options.exact,
|
||||||
CableChannelPrototypes(cable_channels.clone()),
|
CableChannelPrototypes((*cable_channels).clone()),
|
||||||
);
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -452,7 +452,7 @@ mod test {
|
|||||||
Config::default(),
|
Config::default(),
|
||||||
None,
|
None,
|
||||||
AppOptions::default(),
|
AppOptions::default(),
|
||||||
CableChannelPrototypes::default(),
|
&CableChannelPrototypes::default(),
|
||||||
);
|
);
|
||||||
app.television
|
app.television
|
||||||
.results_picker
|
.results_picker
|
||||||
|
@ -136,7 +136,7 @@ impl TelevisionChannel {
|
|||||||
TelevisionChannel::RemoteControl(remote_control) => {
|
TelevisionChannel::RemoteControl(remote_control) => {
|
||||||
remote_control.zap(channel_name)
|
remote_control.zap(channel_name)
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
TelevisionChannel::Cable(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ impl From<Cli> for PostProcessedCli {
|
|||||||
if let Some(preview_cmd) = &preview_command {
|
if let Some(preview_cmd) = &preview_command {
|
||||||
channel.preview_command = Some(preview_cmd.command.clone());
|
channel.preview_command = Some(preview_cmd.command.clone());
|
||||||
channel.preview_delimiter = Some(preview_cmd.delimiter.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 {
|
Self {
|
||||||
|
@ -78,7 +78,7 @@ async fn main() -> Result<()> {
|
|||||||
config.application.tick_rate,
|
config.application.tick_rate,
|
||||||
);
|
);
|
||||||
let mut app =
|
let mut app =
|
||||||
App::new(channel, config, args.input, options, cable_channels);
|
App::new(channel, config, args.input, options, &cable_channels);
|
||||||
stdout().flush()?;
|
stdout().flush()?;
|
||||||
debug!("Running application...");
|
debug!("Running application...");
|
||||||
let output = app.run(stdout().is_terminal(), false).await?;
|
let output = app.run(stdout().is_terminal(), false).await?;
|
||||||
|
@ -132,10 +132,6 @@ pub fn try_preview(
|
|||||||
|
|
||||||
impl From<&CableChannelPrototype> for Option<Previewer> {
|
impl From<&CableChannelPrototype> for Option<Previewer> {
|
||||||
fn from(value: &CableChannelPrototype) -> Self {
|
fn from(value: &CableChannelPrototype) -> Self {
|
||||||
if let Some(preview_command) = value.into() {
|
Option::<PreviewCommand>::from(value).map(Previewer::new)
|
||||||
Some(Previewer::new(preview_command))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ pub fn draw_preview_content_block(
|
|||||||
pub fn build_preview_paragraph(
|
pub fn build_preview_paragraph(
|
||||||
inner: Rect,
|
inner: Rect,
|
||||||
preview_content: &PreviewContent,
|
preview_content: &PreviewContent,
|
||||||
target_line: Option<u16>,
|
#[allow(unused_variables)] target_line: Option<u16>,
|
||||||
preview_scroll: u16,
|
preview_scroll: u16,
|
||||||
) -> Paragraph<'_> {
|
) -> Paragraph<'_> {
|
||||||
let preview_block =
|
let preview_block =
|
||||||
|
@ -66,6 +66,7 @@ pub struct Television {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Television {
|
impl Television {
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
action_tx: UnboundedSender<Action>,
|
action_tx: UnboundedSender<Action>,
|
||||||
|
46
tests/app.rs
46
tests/app.rs
@ -3,7 +3,9 @@ use std::{collections::HashSet, path::PathBuf, time::Duration};
|
|||||||
use television::{
|
use television::{
|
||||||
action::Action,
|
action::Action,
|
||||||
app::{App, AppOptions},
|
app::{App, AppOptions},
|
||||||
channels::{cable::prototypes::CableChannelPrototype, TelevisionChannel},
|
channels::cable::prototypes::{
|
||||||
|
CableChannelPrototype, CableChannelPrototypes,
|
||||||
|
},
|
||||||
config::default_config_from_file,
|
config::default_config_from_file,
|
||||||
};
|
};
|
||||||
use tokio::{task::JoinHandle, time::timeout};
|
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
|
/// The app is started in a separate task and can be interacted with by sending
|
||||||
/// actions to the action channel.
|
/// actions to the action channel.
|
||||||
fn setup_app(
|
fn setup_app(
|
||||||
channel: Option<TelevisionChannel>,
|
channel_prototype: Option<CableChannelPrototype>,
|
||||||
select_1: bool,
|
select_1: bool,
|
||||||
exact: bool,
|
exact: bool,
|
||||||
) -> (
|
) -> (
|
||||||
JoinHandle<television::app::AppOutput>,
|
JoinHandle<television::app::AppOutput>,
|
||||||
tokio::sync::mpsc::UnboundedSender<Action>,
|
tokio::sync::mpsc::UnboundedSender<Action>,
|
||||||
) {
|
) {
|
||||||
let chan: TelevisionChannel = channel.unwrap_or_else(|| {
|
let chan: CableChannelPrototype = channel_prototype.unwrap_or_else(|| {
|
||||||
let target_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let target_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
.join("tests")
|
.join("tests")
|
||||||
.join("target_dir");
|
.join("target_dir");
|
||||||
std::env::set_current_dir(&target_dir).unwrap();
|
std::env::set_current_dir(&target_dir).unwrap();
|
||||||
TelevisionChannel::Cable(CableChannelPrototype::default().into())
|
CableChannelPrototype::default()
|
||||||
});
|
});
|
||||||
let mut config = default_config_from_file().unwrap();
|
let mut config = default_config_from_file().unwrap();
|
||||||
// this speeds up the tests
|
// this speeds up the tests
|
||||||
@ -47,7 +49,13 @@ fn setup_app(
|
|||||||
false,
|
false,
|
||||||
config.application.tick_rate,
|
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
|
// retrieve the app's action channel handle in order to send a quit action
|
||||||
let tx = app.action_tx.clone();
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
|
||||||
async fn test_app_exits_when_select_1_and_only_one_result() {
|
async fn test_app_exits_when_select_1_and_only_one_result() {
|
||||||
let channel =
|
let prototype = CableChannelPrototype::new(
|
||||||
TelevisionChannel::Stdin(television::channels::stdin::Channel::from(
|
"cable",
|
||||||
vec!["file1.txt".to_string()],
|
"echo file1.txt",
|
||||||
));
|
false,
|
||||||
let (f, tx) = setup_app(Some(channel), true, false);
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let (f, tx) = setup_app(Some(prototype), true, false);
|
||||||
|
|
||||||
// tick a few times to get the results
|
// tick a few times to get the results
|
||||||
for _ in 0..=10 {
|
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)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 3)]
|
||||||
async fn test_app_does_not_exit_when_select_1_and_more_than_one_result() {
|
async fn test_app_does_not_exit_when_select_1_and_more_than_one_result() {
|
||||||
let channel =
|
let prototype = CableChannelPrototype::new(
|
||||||
TelevisionChannel::Stdin(television::channels::stdin::Channel::from(
|
"cable",
|
||||||
vec!["file1.txt".to_string(), "file2.txt".to_string()],
|
"echo 'file1.txt\nfile2.txt'",
|
||||||
));
|
false,
|
||||||
let (f, tx) = setup_app(Some(channel), true, false);
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
let (f, tx) = setup_app(Some(prototype), true, false);
|
||||||
|
|
||||||
// tick a few times to get the results
|
// tick a few times to get the results
|
||||||
for _ in 0..=10 {
|
for _ in 0..=10 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user