From 738fe08fbb5fae9f1185b9980c7c344652b7b9d4 Mon Sep 17 00:00:00 2001 From: Alex Pasmantier <47638216+alexpasmantier@users.noreply.github.com> Date: Thu, 5 Jun 2025 15:01:27 +0200 Subject: [PATCH] chore(rust): update rust edition to 2024 and version to 1.87 (#528) --- Cargo.toml | 4 ++-- benches/main/ui.rs | 6 +++--- rust-toolchain.toml | 2 +- television/app.rs | 6 +++--- television/cable.rs | 4 ++-- television/channels/entry.rs | 7 +++++-- television/channels/prototypes.rs | 20 ++++++++++---------- television/channels/remote_control.rs | 2 +- television/cli/mod.rs | 8 ++++---- television/config/keybindings.rs | 7 +++---- television/config/mod.rs | 21 ++++++++++----------- television/draw.rs | 2 +- television/event.rs | 4 ++-- television/logging.rs | 2 +- television/main.rs | 9 +++++---- television/picker.rs | 1 + television/previewer/mod.rs | 10 +++++++--- television/render.rs | 2 +- television/screen/help.rs | 2 +- television/screen/input.rs | 4 ++-- television/screen/logo.rs | 6 ++---- television/screen/preview.rs | 6 +++--- television/screen/remote_control.rs | 2 +- television/screen/results.rs | 10 ++++++---- television/television.rs | 6 +++--- television/tui.rs | 6 +++--- television/utils/clipboard.rs | 4 ++-- television/utils/files.rs | 2 +- television/utils/strings.rs | 2 +- 29 files changed, 87 insertions(+), 80 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 525df69..78e8de7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "television" version = "0.11.9" -edition = "2021" +edition = "2024" description = "A cross-platform, fast and extensible general purpose fuzzy finder TUI." license = "MIT" authors = ["Alexandre Pasmantier "] @@ -24,7 +24,7 @@ include = [ "build.rs", "man", ] -rust-version = "1.83" +rust-version = "1.87" build = "build.rs" [lib] diff --git a/benches/main/ui.rs b/benches/main/ui.rs index b3285d4..73f6174 100644 --- a/benches/main/ui.rs +++ b/benches/main/ui.rs @@ -1,17 +1,17 @@ use criterion::criterion_group; -use criterion::{black_box, Criterion}; +use criterion::{Criterion, black_box}; use devicons::FileIcon; +use ratatui::Terminal; use ratatui::backend::TestBackend; use ratatui::layout::Alignment; use ratatui::layout::Rect; use ratatui::prelude::{Line, Style}; use ratatui::style::Color; use ratatui::widgets::{Block, BorderType, Borders, ListDirection, Padding}; -use ratatui::Terminal; use television::{ action::Action, channels::{ - entry::{into_ranges, Entry}, + entry::{Entry, into_ranges}, prototypes::Cable, }, config::{Config, ConfigEnv}, diff --git a/rust-toolchain.toml b/rust-toolchain.toml index e7c9a01..c1bb234 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.83" +channel = "1.87" components = ["rustfmt", "clippy", "rust-analyzer"] diff --git a/television/app.rs b/television/app.rs index ec6a122..fedff04 100644 --- a/television/app.rs +++ b/television/app.rs @@ -10,10 +10,10 @@ use crate::{ entry::Entry, prototypes::{Cable, ChannelPrototype}, }, - config::{default_tick_rate, Config}, + config::{Config, default_tick_rate}, event::{Event, EventLoop, Key}, keymap::Keymap, - render::{render, RenderingTask, UiState}, + render::{RenderingTask, UiState, render}, television::{Mode, Television}, }; @@ -417,7 +417,7 @@ impl App { // forward action to the television handler if let Some(action) = self.television.update(&action)? { self.action_tx.send(action)?; - }; + } } } Ok(ActionOutcome::None) diff --git a/television/cable.rs b/television/cable.rs index fa8fbca..f031313 100644 --- a/television/cable.rs +++ b/television/cable.rs @@ -104,10 +104,10 @@ where let p = p.as_ref(); p.file_stem() .and_then(|s| s.to_str()) - .map_or(false, |s| s.ends_with(CABLE_FILE_NAME_SUFFIX)) + .map_or_else(|| false, |s| s.ends_with(CABLE_FILE_NAME_SUFFIX)) && p.extension() .and_then(|e| e.to_str()) - .map_or(false, |e| e.to_lowercase() == CABLE_FILE_FORMAT) + .map_or_else(|| false, |e| e.to_lowercase() == CABLE_FILE_FORMAT) } #[cfg(test)] diff --git a/television/channels/entry.rs b/television/channels/entry.rs index 256b52e..8279bb2 100644 --- a/television/channels/entry.rs +++ b/television/channels/entry.rs @@ -1,4 +1,7 @@ -use std::hash::{Hash, Hasher}; +use std::{ + fmt::Write, + hash::{Hash, Hasher}, +}; use devicons::FileIcon; @@ -131,7 +134,7 @@ impl Entry { pub fn stdout_repr(&self) -> String { let mut repr = self.name.clone(); if let Some(line_number) = self.line_number { - repr.push_str(&format!(":{line_number}")); + write!(repr, ":{}", line_number).unwrap(); } repr } diff --git a/television/channels/prototypes.rs b/television/channels/prototypes.rs index bb1f473..8d2efb0 100644 --- a/television/channels/prototypes.rs +++ b/television/channels/prototypes.rs @@ -16,21 +16,21 @@ use crate::{ /// /// The prototype contains the following fields: /// - `name`: The name of the channel. This will be used to identify the -/// channel throughout the application and in UI menus. +/// channel throughout the application and in UI menus. /// - `source_command`: The command to run to get the source for the channel. -/// This is a shell command that will be run in the background. +/// This is a shell command that will be run in the background. /// - `interactive`: Whether the source command should be run in an interactive -/// shell. This is useful for commands that need the user's environment e.g. -/// `alias`. +/// shell. This is useful for commands that need the user's environment e.g. +/// `alias`. /// - `preview_command`: The command to run on each entry to get the preview -/// for the channel. If this is not `None`, the channel will display a preview -/// pane with the output of this command. +/// for the channel. If this is not `None`, the channel will display a preview +/// pane with the output of this command. /// - `preview_delimiter`: The delimiter to use to split an entry into -/// multiple parts that can then be referenced in the preview command (e.g. -/// `{1} + {2}`). +/// multiple parts that can then be referenced in the preview command (e.g. +/// `{1} + {2}`). /// - `preview_offset`: a litteral expression that will be interpreted later on -/// in order to determine the vertical offset at which the preview should be -/// displayed. +/// in order to determine the vertical offset at which the preview should be +/// displayed. /// /// # Example /// The default files channel might look something like this: diff --git a/television/channels/remote_control.rs b/television/channels/remote_control.rs index ae5b855..66cfae6 100644 --- a/television/channels/remote_control.rs +++ b/television/channels/remote_control.rs @@ -3,7 +3,7 @@ use crate::{ entry::Entry, prototypes::{Cable, ChannelPrototype}, }, - matcher::{config::Config, Matcher}, + matcher::{Matcher, config::Config}, }; use anyhow::Result; use devicons::FileIcon; diff --git a/television/cli/mod.rs b/television/cli/mod.rs index e751d91..bd72f59 100644 --- a/television/cli/mod.rs +++ b/television/cli/mod.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use std::path::Path; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use tracing::debug; use crate::{ @@ -11,7 +11,7 @@ use crate::{ prototypes::{Cable, ChannelPrototype}, }, cli::args::{Cli, Command}, - config::{get_config_dir, get_data_dir, KeyBindings}, + config::{KeyBindings, get_config_dir, get_data_dir}, }; pub mod args; @@ -327,8 +327,8 @@ mod tests { } /// Returns a tuple containing a command mapping and a fallback channel. - fn guess_channel_from_prompt_setup<'a>( - ) -> (FxHashMap, &'a str, Cable) { + fn guess_channel_from_prompt_setup<'a>() + -> (FxHashMap, &'a str, Cable) { let mut command_mapping = FxHashMap::default(); command_mapping.insert("vim".to_string(), "files".to_string()); command_mapping.insert("export".to_string(), "env".to_string()); diff --git a/television/config/keybindings.rs b/television/config/keybindings.rs index be56759..b520ec6 100644 --- a/television/config/keybindings.rs +++ b/television/config/keybindings.rs @@ -1,5 +1,5 @@ use crate::action::Action; -use crate::event::{convert_raw_event_to_key, Key}; +use crate::event::{Key, convert_raw_event_to_key}; use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; use rustc_hash::FxHashMap; use serde::{Deserialize, Deserializer, Serialize}; @@ -144,7 +144,7 @@ fn extract_modifiers(raw: &str) -> (&str, KeyModifiers) { current = &rest[6..]; } _ => break, // break out of the loop if no known prefix is detected - }; + } } (current, modifiers) @@ -273,8 +273,7 @@ pub fn parse_key(raw: &str) -> anyhow::Result { raw } else { let raw = raw.strip_prefix('<').unwrap_or(raw); - let raw = raw.strip_suffix('>').unwrap_or(raw); - raw + raw.strip_suffix('>').unwrap_or(raw) }; let key_event = parse_key_event(raw)?; Ok(convert_raw_event_to_key(key_event)) diff --git a/television/config/mod.rs b/television/config/mod.rs index 078bb58..eb6e240 100644 --- a/television/config/mod.rs +++ b/television/config/mod.rs @@ -8,7 +8,7 @@ use std::{ use anyhow::{Context, Result}; use directories::ProjectDirs; pub use keybindings::merge_keybindings; -pub use keybindings::{parse_key, Binding, KeyBindings}; +pub use keybindings::{Binding, KeyBindings, parse_key}; use serde::{Deserialize, Serialize}; use shell_integration::ShellIntegrationConfig; pub use themes::Theme; @@ -138,7 +138,10 @@ impl Config { Ok(final_cfg) } else { // otherwise, create the default configuration file - warn!("No config file found at {:?}, creating default configuration file at that location.", config_env.config_dir); + warn!( + "No config file found at {:?}, creating default configuration file at that location.", + config_env.config_dir + ); // create the default configuration file in the user's config directory std::fs::write( config_env.config_dir.join(CONFIG_FILE_NAME), @@ -213,14 +216,13 @@ pub fn get_data_dir() -> PathBuf { .filter(|p| p.is_absolute()) }); - let directory = if let Some(s) = data_folder { + if let Some(s) = data_folder { s } else if let Some(proj_dirs) = project_directory() { proj_dirs.data_local_dir().to_path_buf() } else { PathBuf::from("../../../../..").join(".data") - }; - directory + } } pub fn get_config_dir() -> PathBuf { @@ -235,14 +237,12 @@ pub fn get_config_dir() -> PathBuf { .map(|p| p.join(PROJECT_NAME)) .filter(|p| p.is_absolute()) }); - let directory = if let Some(s) = config_dir { + if let Some(s) = config_dir { s } else if cfg!(unix) { // default to ~/.config/television for unix systems if let Some(base_dirs) = directories::BaseDirs::new() { - let cfg_dir = - base_dirs.home_dir().join(".config").join("television"); - cfg_dir + base_dirs.home_dir().join(".config").join("television") } else { PathBuf::from("../../../../..").join(".config") } @@ -250,8 +250,7 @@ pub fn get_config_dir() -> PathBuf { proj_dirs.config_local_dir().to_path_buf() } else { PathBuf::from("../../../../..").join("../../../../../.config") - }; - directory + } } fn project_directory() -> Option { diff --git a/television/draw.rs b/television/draw.rs index 56ab151..197af62 100644 --- a/television/draw.rs +++ b/television/draw.rs @@ -1,7 +1,7 @@ use std::{hash::Hash, time::Instant}; use anyhow::Result; -use ratatui::{layout::Rect, Frame}; +use ratatui::{Frame, layout::Rect}; use rustc_hash::FxHashSet; use crate::{ diff --git a/television/event.rs b/television/event.rs index dd043dd..b5ff369 100644 --- a/television/event.rs +++ b/television/event.rs @@ -8,8 +8,8 @@ use std::{ use crossterm::event::{ KeyCode::{ - BackTab, Backspace, Char, Delete, Down, End, Enter, Esc, Home, Insert, - Left, PageDown, PageUp, Right, Tab, Up, F, + BackTab, Backspace, Char, Delete, Down, End, Enter, Esc, F, Home, + Insert, Left, PageDown, PageUp, Right, Tab, Up, }, KeyEvent, KeyEventKind, KeyModifiers, }; diff --git a/television/logging.rs b/television/logging.rs index 1ed37fe..0ff7afb 100644 --- a/television/logging.rs +++ b/television/logging.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use tracing_subscriber::{fmt, prelude::*, EnvFilter}; +use tracing_subscriber::{EnvFilter, fmt, prelude::*}; use crate::config::get_data_dir; diff --git a/television/main.rs b/television/main.rs index 7a9d721..fc7eda1 100644 --- a/television/main.rs +++ b/television/main.rs @@ -1,5 +1,5 @@ use std::env; -use std::io::{stdout, BufWriter, IsTerminal, Write}; +use std::io::{BufWriter, IsTerminal, Write, stdout}; use std::path::Path; use std::process::exit; @@ -15,14 +15,15 @@ use tracing::{debug, error, info}; use television::app::{App, AppOptions}; use television::cli::{ + PostProcessedCli, args::{Cli, Command}, - guess_channel_from_prompt, list_channels, PostProcessedCli, + guess_channel_from_prompt, list_channels, }; -use television::config::{merge_keybindings, Config, ConfigEnv}; +use television::config::{Config, ConfigEnv, merge_keybindings}; use television::utils::shell::render_autocomplete_script_template; use television::utils::{ - shell::{completion_script, Shell}, + shell::{Shell, completion_script}, stdin::is_readable_stdin, }; diff --git a/television/picker.rs b/television/picker.rs index 6e69795..527f402 100644 --- a/television/picker.rs +++ b/television/picker.rs @@ -123,6 +123,7 @@ impl Picker { } } +#[allow(clippy::doc_overindented_list_items)] #[cfg(test)] mod tests { use super::*; diff --git a/television/previewer/mod.rs b/television/previewer/mod.rs index afbf32c..1e6e193 100644 --- a/television/previewer/mod.rs +++ b/television/previewer/mod.rs @@ -14,7 +14,7 @@ use crate::{ channels::{entry::Entry, preview::PreviewCommand}, utils::{ command::shell_command, - strings::{replace_non_printable, ReplaceNonPrintableConfig}, + strings::{ReplaceNonPrintableConfig, replace_non_printable}, }, }; @@ -193,12 +193,16 @@ impl Previewer { } } Request::Shutdown => { - debug!("Received shutdown signal, breaking out of the previewer loop."); + debug!( + "Received shutdown signal, breaking out of the previewer loop." + ); break; } } } else { - debug!("Preview request channel closed and no messages left, breaking out of the previewer loop."); + debug!( + "Preview request channel closed and no messages left, breaking out of the previewer loop." + ); break; } } diff --git a/television/render.rs b/television/render.rs index c2a7145..aeeccfa 100644 --- a/television/render.rs +++ b/television/render.rs @@ -2,7 +2,7 @@ use anyhow::Result; use crossterm::terminal::{BeginSynchronizedUpdate, EndSynchronizedUpdate}; use crossterm::{execute, queue}; use ratatui::layout::Rect; -use std::io::{stderr, stdout, LineWriter}; +use std::io::{LineWriter, stderr, stdout}; use tracing::{debug, warn}; use tokio::sync::mpsc; diff --git a/television/screen/help.rs b/television/screen/help.rs index e9e3f91..01695cc 100644 --- a/television/screen/help.rs +++ b/television/screen/help.rs @@ -5,10 +5,10 @@ use crate::screen::metadata::build_metadata_table; use crate::screen::mode::mode_color; use crate::television::Mode; use crate::utils::metadata::AppMetadata; +use ratatui::Frame; use ratatui::layout::Rect; use ratatui::prelude::{Color, Style}; use ratatui::widgets::{Block, BorderType, Borders, Padding, Table}; -use ratatui::Frame; pub fn draw_logo_block( f: &mut Frame, diff --git a/television/screen/input.rs b/television/screen/input.rs index 6ecbb49..eb8c2a8 100644 --- a/television/screen/input.rs +++ b/television/screen/input.rs @@ -1,15 +1,15 @@ use crate::utils::input::Input; use anyhow::Result; use ratatui::{ + Frame, layout::{ Alignment, Constraint, Direction, Layout as RatatuiLayout, Rect, }, style::{Style, Stylize}, text::{Line, Span}, widgets::{ - block::Position, Block, BorderType, Borders, ListState, Paragraph, + Block, BorderType, Borders, ListState, Paragraph, block::Position, }, - Frame, }; use crate::screen::{colors::Colorscheme, spinner::Spinner}; diff --git a/television/screen/logo.rs b/television/screen/logo.rs index 2538de3..5cc9aba 100644 --- a/television/screen/logo.rs +++ b/television/screen/logo.rs @@ -21,8 +21,7 @@ pub fn build_logo_paragraph<'a>() -> Paragraph<'a> { .lines() .map(std::convert::Into::into) .collect::>(); - let logo_paragraph = Paragraph::new(lines); - logo_paragraph + Paragraph::new(lines) } const REMOTE_LOGO: &str = r" @@ -51,6 +50,5 @@ pub fn build_remote_logo_paragraph<'a>() -> Paragraph<'a> { .lines() .map(std::convert::Into::into) .collect::>(); - let logo_paragraph = Paragraph::new(lines); - logo_paragraph + Paragraph::new(lines) } diff --git a/television/screen/preview.rs b/television/screen/preview.rs index de1ad1c..8fff4bf 100644 --- a/television/screen/preview.rs +++ b/television/screen/preview.rs @@ -1,14 +1,14 @@ use crate::previewer::state::PreviewState; use crate::screen::colors::Colorscheme; use crate::utils::strings::{ - replace_non_printable, shrink_with_ellipsis, ReplaceNonPrintableConfig, - EMPTY_STRING, + EMPTY_STRING, ReplaceNonPrintableConfig, replace_non_printable, + shrink_with_ellipsis, }; use ansi_to_tui::IntoText; use anyhow::Result; use devicons::FileIcon; -use ratatui::widgets::{Block, BorderType, Borders, Padding, Paragraph}; use ratatui::Frame; +use ratatui::widgets::{Block, BorderType, Borders, Padding, Paragraph}; use ratatui::{ layout::{Alignment, Rect}, prelude::{Color, Line, Span, Style, Stylize, Text}, diff --git a/television/screen/remote_control.rs b/television/screen/remote_control.rs index 9a08ea2..faf6d77 100644 --- a/television/screen/remote_control.rs +++ b/television/screen/remote_control.rs @@ -7,6 +7,7 @@ use crate::television::Mode; use crate::utils::input::Input; use anyhow::Result; +use ratatui::Frame; use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect}; use ratatui::prelude::Style; use ratatui::style::{Color, Stylize}; @@ -14,7 +15,6 @@ use ratatui::text::{Line, Span}; use ratatui::widgets::{ Block, BorderType, Borders, ListDirection, ListState, Padding, Paragraph, }; -use ratatui::Frame; #[allow(clippy::too_many_arguments)] pub fn draw_remote_control( diff --git a/television/screen/results.rs b/television/screen/results.rs index 473d330..23d2b2d 100644 --- a/television/screen/results.rs +++ b/television/screen/results.rs @@ -4,14 +4,15 @@ use crate::screen::layout::InputPosition; use crate::utils::indices::truncate_highlighted_string; use crate::utils::strings::make_matched_string_printable; use anyhow::Result; +use ratatui::Frame; use ratatui::layout::{Alignment, Rect}; use ratatui::prelude::{Color, Line, Span, Style}; use ratatui::style::Stylize; use ratatui::widgets::{ Block, BorderType, Borders, List, ListDirection, ListState, Padding, }; -use ratatui::Frame; use rustc_hash::FxHashSet; +use std::fmt::Write; use std::str::FromStr; use unicode_width::UnicodeWidthStr; @@ -73,7 +74,8 @@ fn build_result_line<'a>( entry, area_width, use_icons, - selected_entries.map_or(false, |selected| selected.contains(entry)), + selected_entries + .map_or_else(|| false, |selected| selected.contains(entry)), ); // optional selection symbol if let Some(selected_entries) = selected_entries { @@ -257,10 +259,10 @@ pub fn draw_results_list( ) -> Result<()> { let mut toggle_hints = String::new(); if !no_help { - toggle_hints.push_str(&format!(" help: <{help_keybinding}> ",)); + write!(toggle_hints, " help: <{}> ", help_keybinding)?; } if preview_togglable { - toggle_hints.push_str(&format!(" preview: <{preview_keybinding}> ",)); + write!(toggle_hints, " preview: <{}> ", preview_keybinding)?; } let results_block = Block::default() diff --git a/television/television.rs b/television/television.rs index 670ee02..16d7c25 100644 --- a/television/television.rs +++ b/television/television.rs @@ -11,8 +11,8 @@ use crate::{ input::convert_action_to_input_request, picker::Picker, previewer::{ - state::PreviewState, Config as PreviewerConfig, Preview, Previewer, - Request as PreviewRequest, Ticket, + Config as PreviewerConfig, Preview, Previewer, + Request as PreviewRequest, Ticket, state::PreviewState, }, render::UiState, screen::{ @@ -29,7 +29,7 @@ use rustc_hash::{FxBuildHasher, FxHashSet}; use serde::{Deserialize, Serialize}; use std::collections::HashSet; use tokio::sync::mpsc::{ - unbounded_channel, UnboundedReceiver, UnboundedSender, + UnboundedReceiver, UnboundedSender, unbounded_channel, }; use tracing::debug; diff --git a/television/tui.rs b/television/tui.rs index a124d81..c646f85 100644 --- a/television/tui.rs +++ b/television/tui.rs @@ -1,5 +1,5 @@ use std::{ - io::{stderr, LineWriter, Write}, + io::{LineWriter, Write, stderr}, ops::{Deref, DerefMut}, }; @@ -9,8 +9,8 @@ use crossterm::{ event::DisableMouseCapture, execute, terminal::{ - disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, - EnterAlternateScreen, LeaveAlternateScreen, + EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, + enable_raw_mode, is_raw_mode_enabled, }, }; use ratatui::{backend::CrosstermBackend, layout::Size}; diff --git a/television/utils/clipboard.rs b/television/utils/clipboard.rs index 86c58d2..c0a097b 100644 --- a/television/utils/clipboard.rs +++ b/television/utils/clipboard.rs @@ -82,7 +82,7 @@ impl Clipboard { #[cfg(unix)] pub async fn set(&self, s: impl AsRef) { use std::{ - io::{stderr, BufWriter}, + io::{BufWriter, stderr}, process::Stdio, }; @@ -150,7 +150,7 @@ impl Clipboard { mod osc52 { use std::ffi::OsStr; - use base64::{engine::general_purpose, Engine}; + use base64::{Engine, engine::general_purpose}; #[derive(Debug)] pub struct SetClipboard { diff --git a/television/utils/files.rs b/television/utils/files.rs index 7e03cfa..f868147 100644 --- a/television/utils/files.rs +++ b/television/utils/files.rs @@ -10,7 +10,7 @@ use std::sync::OnceLock; use tracing::{debug, warn}; use crate::utils::strings::{ - proportion_of_printable_ascii_characters, PRINTABLE_ASCII_THRESHOLD, + PRINTABLE_ASCII_THRESHOLD, proportion_of_printable_ascii_characters, }; use crate::utils::threads::default_num_threads; diff --git a/television/utils/strings.rs b/television/utils/strings.rs index 4c027c4..4a32549 100644 --- a/television/utils/strings.rs +++ b/television/utils/strings.rs @@ -1,4 +1,4 @@ -use lazy_regex::{regex, Lazy, Regex}; +use lazy_regex::{Lazy, Regex, regex}; /// Returns the index of the next character boundary in the given string. ///