chore(rust): update rust edition to 2024 and version to 1.87 (#528)

This commit is contained in:
Alex Pasmantier 2025-06-05 15:01:27 +02:00 committed by GitHub
parent aac7e4dc45
commit 738fe08fbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 87 additions and 80 deletions

View File

@ -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 <alex.pasmant@gmail.com>"]
@ -24,7 +24,7 @@ include = [
"build.rs",
"man",
]
rust-version = "1.83"
rust-version = "1.87"
build = "build.rs"
[lib]

View File

@ -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},

View File

@ -1,3 +1,3 @@
[toolchain]
channel = "1.83"
channel = "1.87"
components = ["rustfmt", "clippy", "rust-analyzer"]

View File

@ -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)

View File

@ -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)]

View File

@ -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
}

View File

@ -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;

View File

@ -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<String, String>, &'a str, Cable) {
fn guess_channel_from_prompt_setup<'a>()
-> (FxHashMap<String, String>, &'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());

View File

@ -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<Key, String> {
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))

View File

@ -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<ProjectDirs> {

View File

@ -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::{

View File

@ -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,
};

View File

@ -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;

View File

@ -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,
};

View File

@ -123,6 +123,7 @@ impl Picker {
}
}
#[allow(clippy::doc_overindented_list_items)]
#[cfg(test)]
mod tests {
use super::*;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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,

View File

@ -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};

View File

@ -21,8 +21,7 @@ pub fn build_logo_paragraph<'a>() -> Paragraph<'a> {
.lines()
.map(std::convert::Into::into)
.collect::<Vec<_>>();
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::<Vec<_>>();
let logo_paragraph = Paragraph::new(lines);
logo_paragraph
Paragraph::new(lines)
}

View File

@ -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},

View File

@ -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(

View File

@ -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()

View File

@ -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;

View File

@ -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};

View File

@ -82,7 +82,7 @@ impl Clipboard {
#[cfg(unix)]
pub async fn set(&self, s: impl AsRef<std::ffi::OsStr>) {
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 {

View File

@ -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;

View File

@ -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.
///