diff --git a/crates/television/app.rs b/crates/television/app.rs index 19d7a07..0f0256d 100644 --- a/crates/television/app.rs +++ b/crates/television/app.rs @@ -52,7 +52,6 @@ */ use std::sync::Arc; - use color_eyre::Result; use tokio::sync::{mpsc, Mutex}; use tracing::{debug, info}; @@ -133,7 +132,7 @@ impl App { frame_rate, is_output_tty, ) - .await + .await }); // event handling loop diff --git a/crates/television/channels/alias.rs b/crates/television/channels/alias.rs index a9aab27..e1f9c52 100644 --- a/crates/television/channels/alias.rs +++ b/crates/television/channels/alias.rs @@ -51,10 +51,7 @@ fn get_raw_aliases(shell: &str) -> Vec { .output() .expect("failed to execute process"); let aliases = String::from_utf8(output.stdout).unwrap(); - aliases - .lines() - .map(ToString::to_string) - .collect() + aliases.lines().map(ToString::to_string).collect() } "zsh" => { let output = std::process::Command::new("zsh") @@ -64,10 +61,7 @@ fn get_raw_aliases(shell: &str) -> Vec { .output() .expect("failed to execute process"); let aliases = String::from_utf8(output.stdout).unwrap(); - aliases - .lines() - .map(ToString::to_string) - .collect() + aliases.lines().map(ToString::to_string).collect() } // TODO: add more shells _ => Vec::new(), @@ -134,7 +128,7 @@ impl OnAir for Channel { .matched_items( offset ..(num_entries + offset) - .min(snapshot.matched_item_count()), + .min(snapshot.matched_item_count()), ) .map(move |item| { snapshot.pattern().column_pattern(0).indices( diff --git a/crates/television/channels/env.rs b/crates/television/channels/env.rs index da80acd..28c5715 100644 --- a/crates/television/channels/env.rs +++ b/crates/television/channels/env.rs @@ -40,9 +40,15 @@ impl Channel { ); let injector = matcher.injector(); for (name, value) in std::env::vars() { - let _ = injector.push(EnvVar { name: preprocess_line(&name), value: preprocess_line(&value) }, |e, cols| { - cols[0] = (e.name.clone() + &e.value).into(); - }); + let _ = injector.push( + EnvVar { + name: preprocess_line(&name), + value: preprocess_line(&value), + }, + |e, cols| { + cols[0] = (e.name.clone() + &e.value).into(); + }, + ); } Channel { matcher, @@ -93,7 +99,7 @@ impl OnAir for Channel { .matched_items( offset ..(num_entries + offset) - .min(snapshot.matched_item_count()), + .min(snapshot.matched_item_count()), ) .map(move |item| { snapshot.pattern().column_pattern(0).indices( diff --git a/crates/television/channels/files.rs b/crates/television/channels/files.rs index b1db775..b7da0d9 100644 --- a/crates/television/channels/files.rs +++ b/crates/television/channels/files.rs @@ -98,7 +98,7 @@ impl OnAir for Channel { .matched_items( offset ..(num_entries + offset) - .min(snapshot.matched_item_count()), + .min(snapshot.matched_item_count()), ) .map(move |item| { snapshot.pattern().column_pattern(0).indices( @@ -165,7 +165,13 @@ async fn load_files(paths: Vec, injector: Injector) { Box::new(move |result| { if let Ok(entry) = result { if entry.file_type().unwrap().is_file() { - let file_path = preprocess_line(&*entry.path().strip_prefix(¤t_dir).unwrap().to_string_lossy()); + let file_path = preprocess_line( + &*entry + .path() + .strip_prefix(¤t_dir) + .unwrap() + .to_string_lossy(), + ); let _ = injector.push(file_path, |e, cols| { cols[0] = e.clone().into(); }); diff --git a/crates/television/channels/git_repos.rs b/crates/television/channels/git_repos.rs index 31347ea..82eab89 100644 --- a/crates/television/channels/git_repos.rs +++ b/crates/television/channels/git_repos.rs @@ -90,7 +90,7 @@ impl OnAir for Channel { .matched_items( offset ..(num_entries + offset) - .min(snapshot.matched_item_count()), + .min(snapshot.matched_item_count()), ) .map(move |item| { snapshot.pattern().column_pattern(0).indices( @@ -197,7 +197,7 @@ async fn crawl_for_repos( Some(walker_overrides_builder.build().unwrap()), Some(get_ignored_paths()), ) - .build_parallel(); + .build_parallel(); walker.run(|| { let injector = injector.clone(); @@ -206,11 +206,9 @@ async fn crawl_for_repos( if entry.file_type().unwrap().is_dir() { // if the entry is a .git directory, add its parent to the list of git repos if entry.path().ends_with(".git") { - let parent_path = preprocess_line(&*entry - .path() - .parent() - .unwrap() - .to_string_lossy()); + let parent_path = preprocess_line( + &*entry.path().parent().unwrap().to_string_lossy(), + ); debug!("Found git repo: {:?}", parent_path); let _ = injector.push(parent_path, |e, cols| { cols[0] = e.clone().into(); diff --git a/crates/television/channels/stdin.rs b/crates/television/channels/stdin.rs index 6364a2f..63f3546 100644 --- a/crates/television/channels/stdin.rs +++ b/crates/television/channels/stdin.rs @@ -90,7 +90,7 @@ impl OnAir for Channel { .matched_items( offset ..(num_entries + offset) - .min(snapshot.matched_item_count()), + .min(snapshot.matched_item_count()), ) .map(move |item| { snapshot.pattern().column_pattern(0).indices( diff --git a/crates/television/event.rs b/crates/television/event.rs index f4ee38b..07fb005 100644 --- a/crates/television/event.rs +++ b/crates/television/event.rs @@ -153,8 +153,7 @@ impl EventLoop { pub fn new(tick_rate: f64, init: bool) -> Self { let (tx, rx) = mpsc::unbounded_channel(); let tx_c = tx.clone(); - let tick_interval = - Duration::from_secs_f64(1.0 / tick_rate); + let tick_interval = Duration::from_secs_f64(1.0 / tick_rate); let (abort, mut abort_recv) = mpsc::unbounded_channel(); diff --git a/crates/television/previewers/files.rs b/crates/television/previewers/files.rs index c5cdcd2..90122b5 100644 --- a/crates/television/previewers/files.rs +++ b/crates/television/previewers/files.rs @@ -81,7 +81,7 @@ impl FilePreviewer { entry.name.clone(), preview.clone(), ) - .await; + .await; // compute the highlighted version in the background let mut reader = @@ -164,10 +164,11 @@ impl FilePreviewer { "Computing highlights in the background for {:?}", entry_c.name ); - let lines: Vec = - reader.lines().map_while(Result::ok).map( - |line| preprocess_line(&line), - ).collect(); + let lines: Vec = reader + .lines() + .map_while(Result::ok) + .map(|line| preprocess_line(&line)) + .collect(); match syntax::compute_highlights_for_path( &PathBuf::from(&entry_c.name), @@ -227,8 +228,8 @@ impl FilePreviewer { if let Ok(bytes_read) = f.read(&mut buffer) { if bytes_read > 0 && proportion_of_printable_ascii_characters( - &buffer[..bytes_read], - ) > PRINTABLE_ASCII_THRESHOLD + &buffer[..bytes_read], + ) > PRINTABLE_ASCII_THRESHOLD { file_type = FileType::Text; } diff --git a/crates/television/television.rs b/crates/television/television.rs index 305aff3..2504d62 100644 --- a/crates/television/television.rs +++ b/crates/television/television.rs @@ -377,8 +377,9 @@ impl Television { // bottom left block: input self.draw_input_box(f, &layout)?; - let selected_entry = - self.get_selected_entry(Some(Mode::Channel)).unwrap_or(ENTRY_PLACEHOLDER); + let selected_entry = self + .get_selected_entry(Some(Mode::Channel)) + .unwrap_or(ENTRY_PLACEHOLDER); let preview = block_on(self.previewer.preview(&selected_entry)); // top right block: preview title diff --git a/crates/television/ui.rs b/crates/television/ui.rs index 3ba67f0..e8deb1b 100644 --- a/crates/television/ui.rs +++ b/crates/television/ui.rs @@ -6,11 +6,11 @@ pub mod keymap; pub mod layout; pub mod logo; pub mod metadata; +mod mode; pub mod preview; mod remote_control; pub mod results; pub mod spinner; -mod mode; // input //const DEFAULT_INPUT_FG: Color = Color::Rgb(200, 200, 200); //const DEFAULT_RESULTS_COUNT_FG: Color = Color::Rgb(150, 150, 150); diff --git a/crates/television/ui/keymap.rs b/crates/television/ui/keymap.rs index ee1553b..df1f945 100644 --- a/crates/television/ui/keymap.rs +++ b/crates/television/ui/keymap.rs @@ -80,8 +80,11 @@ impl Television { // MISC line (quit, help, etc.) // Quit ⏼ let quit_keys = keys_for_action(keymap, &Action::Quit); - let quit_row = - Row::new(build_cells_for_key_groups("⏼ Quit", vec![quit_keys], key_color)); + let quit_row = Row::new(build_cells_for_key_groups( + "⏼ Quit", + vec![quit_keys], + key_color, + )); let widths = vec![Constraint::Fill(1), Constraint::Fill(2)]; @@ -132,8 +135,11 @@ impl Television { // Quit let quit_keys = keys_for_action(keymap, &Action::Quit); - let quit_row = - Row::new(build_cells_for_key_groups("⏼ Quit", vec![quit_keys], key_color)); + let quit_row = Row::new(build_cells_for_key_groups( + "⏼ Quit", + vec![quit_keys], + key_color, + )); Ok(Table::new( vec![results_row, select_entry_row, switch_channels_row, quit_row], @@ -185,8 +191,7 @@ fn build_cells_for_key_groups( key_groups: Vec>, key_color: Color, ) -> Vec { - if key_groups.is_empty() || key_groups.iter().all(Vec::is_empty) - { + if key_groups.is_empty() || key_groups.iter().all(Vec::is_empty) { return vec![group_name.into(), "No keybindings".into()]; } let non_empty_groups = key_groups.iter().filter(|keys| !keys.is_empty()); diff --git a/crates/television/ui/metadata.rs b/crates/television/ui/metadata.rs index 1719ed2..5f26bb5 100644 --- a/crates/television/ui/metadata.rs +++ b/crates/television/ui/metadata.rs @@ -8,7 +8,6 @@ use ratatui::{ use crate::television::Television; use crate::ui::mode::mode_color; - const METADATA_FIELD_NAME_COLOR: Color = Color::DarkGray; const METADATA_FIELD_VALUE_COLOR: Color = Color::Gray; diff --git a/crates/television/ui/mode.rs b/crates/television/ui/mode.rs index f21f887..47b3ba5 100644 --- a/crates/television/ui/mode.rs +++ b/crates/television/ui/mode.rs @@ -5,11 +5,10 @@ const CHANNEL_COLOR: Color = Color::LightYellow; const REMOTE_CONTROL_COLOR: Color = Color::LightMagenta; const SEND_TO_CHANNEL_COLOR: Color = Color::LightCyan; - pub fn mode_color(mode: Mode) -> Color { match mode { Mode::Channel => CHANNEL_COLOR, Mode::RemoteControl => REMOTE_CONTROL_COLOR, Mode::SendToChannel => SEND_TO_CHANNEL_COLOR, } -} \ No newline at end of file +} diff --git a/crates/television/ui/preview.rs b/crates/television/ui/preview.rs index 13fc409..f9ae5c9 100644 --- a/crates/television/ui/preview.rs +++ b/crates/television/ui/preview.rs @@ -174,9 +174,9 @@ impl Television { self.preview_scroll.unwrap_or(0), self.preview_pane_height, ) - .block(preview_block) - .alignment(Alignment::Left) - .scroll((self.preview_scroll.unwrap_or(0), 0)) + .block(preview_block) + .alignment(Alignment::Left) + .scroll((self.preview_scroll.unwrap_or(0), 0)) } // meta PreviewContent::Loading => self diff --git a/crates/television/ui/remote_control.rs b/crates/television/ui/remote_control.rs index e1fa569..7a66cf6 100644 --- a/crates/television/ui/remote_control.rs +++ b/crates/television/ui/remote_control.rs @@ -28,7 +28,7 @@ impl Television { Constraint::Length(3), Constraint::Length(20), ] - .as_ref(), + .as_ref(), ) .split(*area); self.draw_rc_channels(f, &layout[0])?; @@ -56,8 +56,15 @@ impl Television { u32::try_from(self.rc_picker.view_offset)?, ); - let channel_list = - build_results_list(rc_block, &entries, ListDirection::TopToBottom, Some(ResultsListColors::default().result_name_fg(mode_color(self.mode)))); + let channel_list = build_results_list( + rc_block, + &entries, + ListDirection::TopToBottom, + Some( + ResultsListColors::default() + .result_name_fg(mode_color(self.mode)), + ), + ); f.render_stateful_widget( channel_list, @@ -99,7 +106,7 @@ impl Television { .fg(crate::television::DEFAULT_INPUT_FG) .bold(), )) - .block(prompt_symbol_block); + .block(prompt_symbol_block); f.render_widget(arrow, inner_input_chunks[0]); let interactive_input_block = Block::default(); @@ -124,8 +131,8 @@ impl Television { // Put cursor past the end of the input text inner_input_chunks[1].x + u16::try_from( - self.rc_picker.input.visual_cursor().max(scroll) - scroll, - )?, + self.rc_picker.input.visual_cursor().max(scroll) - scroll, + )?, // Move one line down, from the border to the input line inner_input_chunks[1].y, )); @@ -134,8 +141,7 @@ impl Television { } fn draw_rc_logo(f: &mut Frame, area: Rect, color: Color) { - let logo_block = Block::default() - .style(Style::default().fg(color)); + let logo_block = Block::default().style(Style::default().fg(color)); let logo_paragraph = build_remote_logo_paragraph() .alignment(Alignment::Center) diff --git a/crates/television/ui/results.rs b/crates/television/ui/results.rs index 15ad76a..c8f99dc 100644 --- a/crates/television/ui/results.rs +++ b/crates/television/ui/results.rs @@ -134,7 +134,8 @@ where last_match_end, start, ), - Style::default().fg(results_list_colors.result_preview_fg), + Style::default() + .fg(results_list_colors.result_preview_fg), )); spans.push(Span::styled( slice_at_char_boundaries(preview, start, end), @@ -147,7 +148,8 @@ where preview, preview_match_ranges.last().unwrap().1 as usize, )..], - Style::default().fg(results_list_colors.result_preview_fg), + Style::default() + .fg(results_list_colors.result_preview_fg), )); } } else { @@ -159,10 +161,12 @@ where } Line::from(spans) })) - .direction(list_direction) - .highlight_style(Style::default().bg(results_list_colors.result_selected_bg)) - .highlight_symbol("> ") - .block(results_block) + .direction(list_direction) + .highlight_style( + Style::default().bg(results_list_colors.result_selected_bg), + ) + .highlight_symbol("> ") + .block(results_block) } impl Television { diff --git a/crates/television/utils/strings.rs b/crates/television/utils/strings.rs index d6a5ad8..b710196 100644 --- a/crates/television/utils/strings.rs +++ b/crates/television/utils/strings.rs @@ -138,8 +138,8 @@ pub fn preprocess_line(line: &str) -> String { line } } - .trim_end_matches(['\r', '\n', '\0']) - .as_bytes(), + .trim_end_matches(['\r', '\n', '\0']) + .as_bytes(), TAB_WIDTH, ) } @@ -175,8 +175,7 @@ mod tests { test_replace_nonprintable("Hello\tWorld!", "Hello World!"); test_replace_nonprintable( " -- AND -", - " -- AND", +", " -- AND", ) } diff --git a/crates/television_derive/src/lib.rs b/crates/television_derive/src/lib.rs index a95ea15..8e4e789 100644 --- a/crates/television_derive/src/lib.rs +++ b/crates/television_derive/src/lib.rs @@ -36,7 +36,9 @@ pub fn cli_channel_derive(input: TokenStream) -> TokenStream { } fn has_exclude_attr(attrs: &[syn::Attribute]) -> bool { - attrs.iter().any(|attr| attr.path().is_ident("exclude_from_cli")) + attrs + .iter() + .any(|attr| attr.path().is_ident("exclude_from_cli")) } fn impl_cli_channel(ast: &syn::DeriveInput) -> TokenStream {