feat: Fix linter

This commit is contained in:
Jed 2026-07-06 22:09:33 +02:00
parent b1d0f10cec
commit 529ecbe6a6
10 changed files with 65 additions and 105 deletions

View file

@ -13,9 +13,7 @@ pub(super) struct Preview {
impl Deref for Preview { impl Deref for Preview {
type Target = yazi_core::tab::Preview; type Target = yazi_core::tab::Preview;
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target { &self.tab.preview }
&self.tab.preview
}
} }
impl Preview { impl Preview {

View file

@ -4,8 +4,8 @@ const EXPECTED: &str = "expected a table containing a line and a length";
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct HighlightPosition { pub struct HighlightPosition {
pub line: usize, pub line: usize,
pub col: usize, pub col: usize,
pub length: usize, pub length: usize,
} }
@ -24,8 +24,8 @@ impl FromLua for HighlightPosition {
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> { fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
match value { match value {
Value::Table(tbl) => Ok(Self { Value::Table(tbl) => Ok(Self {
line: tbl.raw_get("line")?, line: tbl.raw_get("line")?,
col: tbl.raw_get("col")?, col: tbl.raw_get("col")?,
length: tbl.raw_get("length")?, length: tbl.raw_get("length")?,
}), }),
_ => Err(EXPECTED.into_lua_err()), _ => Err(EXPECTED.into_lua_err()),

View file

@ -1,42 +1,28 @@
use std::{io::{BufRead, BufReader, Cursor, Seek}, path::PathBuf, sync::OnceLock};
use anyhow::{Result, anyhow, bail}; use anyhow::{Result, anyhow, bail};
use ratatui_core::{ use ratatui_core::{layout::Size, text::{Line, Span, Text}};
layout::Size, use syntect::{LoadingError, dumps, easy::HighlightLines, highlighting::{self, Theme, ThemeSet}, parsing::{SyntaxReference, SyntaxSet}};
text::{Line, Span, Text},
};
use std::{
io::{BufRead, BufReader, Cursor, Seek},
path::PathBuf,
sync::OnceLock,
};
use syntect::{
LoadingError, dumps,
easy::HighlightLines,
highlighting::{self, Theme, ThemeSet},
parsing::{SyntaxReference, SyntaxSet},
};
use yazi_binding::elements::HighlightPosition; use yazi_binding::elements::HighlightPosition;
use yazi_config::{THEME, YAZI}; use yazi_config::{THEME, YAZI};
use yazi_runner::previewer::PeekError; use yazi_runner::previewer::PeekError;
use yazi_shared::{ use yazi_shared::{id::{Id, Ids}, replace_to_printable};
id::{Id, Ids},
replace_to_printable,
};
use yazi_shim::ratatui::LineIter; use yazi_shim::ratatui::LineIter;
static INCR: Ids = Ids::new(); static INCR: Ids = Ids::new();
pub struct Highlighter { pub struct Highlighter {
path: PathBuf, path: PathBuf,
reader: BufReader<std::fs::File>, reader: BufReader<std::fs::File>,
skip: usize, skip: usize,
size: Size, size: Size,
ticket: Id, ticket: Id,
theme: &'static Theme, theme: &'static Theme,
syntaxes: &'static SyntaxSet, syntaxes: &'static SyntaxSet,
inner: Option<HighlightLines<'static>>, inner: Option<HighlightLines<'static>>,
syntax: Option<&'static SyntaxReference>, syntax: Option<&'static SyntaxReference>,
} }
impl Highlighter { impl Highlighter {
@ -77,9 +63,7 @@ impl Highlighter {
}) })
} }
pub fn abort() { pub fn abort() { INCR.next(); }
INCR.next();
}
fn highlight(mut self, position: Option<HighlightPosition>) -> Result<Text<'static>, PeekError> { fn highlight(mut self, position: Option<HighlightPosition>) -> Result<Text<'static>, PeekError> {
self.load_syntax()?; self.load_syntax()?;
@ -265,7 +249,7 @@ impl Highlighter {
Span { Span {
content: s.into(), content: s.into(),
style: ratatui_core::style::Style { style: ratatui_core::style::Style {
fg: Self::to_ansi_color(style.foreground), fg: Self::to_ansi_color(style.foreground),
// bg: Self::to_ansi_color(style.background), // bg: Self::to_ansi_color(style.background),
add_modifier: modifier, add_modifier: modifier,

View file

@ -44,14 +44,14 @@ impl MgrProxy {
pub fn update_peeked_error(job: PeekJob, error: String) { pub fn update_peeked_error(job: PeekJob, error: String) {
let area = LAYOUT.get().preview; let area = LAYOUT.get().preview;
Self::update_peeked(PreviewLock { Self::update_peeked(PreviewLock {
url: job.file.url, url: job.file.url,
cha: job.file.cha, cha: job.file.cha,
mime: job.mime, mime: job.mime,
skip: job.skip, skip: job.skip,
search_idx: job.search_idx, search_idx: job.search_idx,
area: area.into(), area: area.into(),
data: vec![ data: vec![
Renderable::Clear(Default::default()).with_area(area), Renderable::Clear(Default::default()).with_area(area),
Renderable::from(Error::custom(error)).with_area(area), Renderable::from(Error::custom(error)).with_area(area),
], ],

View file

@ -6,27 +6,21 @@ use yazi_adapter::ADAPTOR;
use yazi_config::{LAYOUT, YAZI}; use yazi_config::{LAYOUT, YAZI};
use yazi_fs::{Entries, FilesOp, cha::Cha, file::File}; use yazi_fs::{Entries, FilesOp, cha::Cha, file::File};
use yazi_macro::render; use yazi_macro::render;
use yazi_runner::{ use yazi_runner::{RUNNER, previewer::{PeekError, PeekJob}};
RUNNER, use yazi_shared::{pool::Symbol, url::{UrlBuf, UrlLike}};
previewer::{PeekError, PeekJob},
};
use yazi_shared::{
pool::Symbol,
url::{UrlBuf, UrlLike},
};
use yazi_vfs::{VfsEntries, VfsFilesOp}; use yazi_vfs::{VfsEntries, VfsFilesOp};
use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock}; use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock};
#[derive(Default, Debug)] #[derive(Default, Debug)]
pub struct Preview { pub struct Preview {
pub lock: Option<PreviewLock>, pub lock: Option<PreviewLock>,
pub skip: usize, pub skip: usize,
pub search_idx: Option<usize>, pub search_idx: Option<usize>,
handle: Option<JoinHandle<()>>, handle: Option<JoinHandle<()>>,
pub folder_lock: Option<UrlBuf>, pub folder_lock: Option<UrlBuf>,
folder_loader: Option<JoinHandle<()>>, folder_loader: Option<JoinHandle<()>>,
} }
impl Preview { impl Preview {
@ -104,9 +98,7 @@ impl Preview {
ADAPTOR.image_hide().ok(); ADAPTOR.image_hide().ok();
} }
pub fn same_url(&self, url: &UrlBuf) -> bool { pub fn same_url(&self, url: &UrlBuf) -> bool { matches!(&self.lock, Some(l) if l.url == *url) }
matches!(&self.lock, Some(l) if l.url == *url)
}
pub fn same_file(&self, file: &File, mime: &str) -> bool { pub fn same_file(&self, file: &File, mime: &str) -> bool {
self.same_url(&file.url) self.same_url(&file.url)
@ -118,7 +110,5 @@ impl Preview {
&& matches!(&self.lock, Some(l) if l.skip == self.skip && l.search_idx == self.search_idx) && matches!(&self.lock, Some(l) if l.skip == self.skip && l.search_idx == self.search_idx)
} }
pub fn same_folder(&self, url: &UrlBuf) -> bool { pub fn same_folder(&self, url: &UrlBuf) -> bool { self.folder_lock.as_ref() == Some(url) }
self.folder_lock.as_ref() == Some(url)
}
} }

View file

@ -7,14 +7,14 @@ use yazi_widgets::Renderable;
#[derive(Clone, Debug, Default)] #[derive(Clone, Debug, Default)]
pub struct PreviewLock { pub struct PreviewLock {
pub url: yazi_shared::url::UrlBuf, pub url: yazi_shared::url::UrlBuf,
pub cha: yazi_fs::cha::Cha, pub cha: yazi_fs::cha::Cha,
pub mime: Symbol<str>, pub mime: Symbol<str>,
pub skip: usize, pub skip: usize,
pub search_idx: Option<usize>, pub search_idx: Option<usize>,
pub area: Rect, pub area: Rect,
pub data: Vec<Renderable>, pub data: Vec<Renderable>,
} }
impl_data_any!(PreviewLock); impl_data_any!(PreviewLock);
@ -26,14 +26,14 @@ impl TryFrom<Table> for PreviewLock {
let file: FileRef = t.raw_get("file")?; let file: FileRef = t.raw_get("file")?;
file.borrow(|f| { file.borrow(|f| {
Ok(Self { Ok(Self {
url: f.url_owned(), url: f.url_owned(),
cha: f.cha, cha: f.cha,
mime: t.raw_get::<mlua::String>("mime")?.to_str()?.intern(), mime: t.raw_get::<mlua::String>("mime")?.to_str()?.intern(),
skip: t.raw_get("skip")?, skip: t.raw_get("skip")?,
search_idx: t.raw_get("search_idx")?, search_idx: t.raw_get("search_idx")?,
area: t.raw_get("area")?, area: t.raw_get("area")?,
data: Default::default(), data: Default::default(),
}) })
}) })
} }

View file

@ -3,39 +3,33 @@ use yazi_shared::{event::ActionCow, url::UrlBuf};
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct PeekForm { pub struct PeekForm {
pub skip: Option<usize>, pub skip: Option<usize>,
pub force: bool, pub force: bool,
pub only_if: Option<UrlBuf>, pub only_if: Option<UrlBuf>,
pub upper_bound: bool, pub upper_bound: bool,
pub search_idx: Option<usize>, pub search_idx: Option<usize>,
} }
impl From<ActionCow> for PeekForm { impl From<ActionCow> for PeekForm {
fn from(mut a: ActionCow) -> Self { fn from(mut a: ActionCow) -> Self {
Self { Self {
skip: a.first().ok(), skip: a.first().ok(),
force: a.bool("force"), force: a.bool("force"),
only_if: a.take("only-if").ok(), only_if: a.take("only-if").ok(),
upper_bound: a.bool("upper-bound"), upper_bound: a.bool("upper-bound"),
search_idx: a.take("search-idx").ok(), search_idx: a.take("search-idx").ok(),
} }
} }
} }
impl From<bool> for PeekForm { impl From<bool> for PeekForm {
fn from(force: bool) -> Self { fn from(force: bool) -> Self { Self { force, ..Default::default() } }
Self { force, ..Default::default() }
}
} }
impl FromLua for PeekForm { impl FromLua for PeekForm {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
Err("unsupported".into_lua_err())
}
} }
impl IntoLua for PeekForm { impl IntoLua for PeekForm {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { fn into_lua(self, _: &Lua) -> mlua::Result<Value> { Err("unsupported".into_lua_err()) }
Err("unsupported".into_lua_err())
}
} }

View file

@ -1,20 +1,16 @@
use std::{fmt::format, process::Stdio}; use std::process::Stdio;
use anyhow::Result; use anyhow::Result;
use tokio::{ use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
io::{AsyncBufReadExt, BufReader},
process::Command,
sync::mpsc::{self, UnboundedReceiver},
};
use yazi_fs::{FsUrl, file::File}; use yazi_fs::{FsUrl, file::File};
use yazi_shared::url::{AsUrl, UrlBuf, UrlLike}; use yazi_shared::url::{AsUrl, UrlBuf, UrlLike};
use yazi_vfs::VfsFile; use yazi_vfs::VfsFile;
pub struct RgOpt { pub struct RgOpt {
pub cwd: UrlBuf, pub cwd: UrlBuf,
pub hidden: bool, pub hidden: bool,
pub subject: String, pub subject: String,
pub args: Vec<String>, pub args: Vec<String>,
} }
pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> { pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {

View file

@ -1,8 +1,5 @@
use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value}; use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value};
use yazi_binding::{ use yazi_binding::{Error, elements::{Area, HighlightPosition}};
Error,
elements::{Area, HighlightPosition},
};
use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock}; use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock};
use yazi_fs::FsUrl; use yazi_fs::FsUrl;
use yazi_runner::previewer::PeekError; use yazi_runner::previewer::PeekError;
@ -38,7 +35,8 @@ impl Utils {
}) })
} }
// Note: You need to implement or update Highlighter::oneshot_with_highlight to accept line/column and highlight accordingly. // Note: You need to implement or update Highlighter::oneshot_with_highlight to
// accept line/column and highlight accordingly.
pub(super) fn preview_widget(lua: &Lua) -> mlua::Result<Function> { pub(super) fn preview_widget(lua: &Lua) -> mlua::Result<Function> {
lua.create_async_function(|_, (t, value): (Table, Value)| async move { lua.create_async_function(|_, (t, value): (Table, Value)| async move {

View file

@ -6,10 +6,10 @@ use yazi_shared::{data::Sendable, pool::Symbol};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct PeekJob { pub struct PeekJob {
pub previewer: PreviewerArc, pub previewer: PreviewerArc,
pub file: File, pub file: File,
pub mime: Symbol<str>, pub mime: Symbol<str>,
pub skip: usize, pub skip: usize,
pub search_idx: Option<usize>, pub search_idx: Option<usize>,
} }
@ -31,7 +31,7 @@ impl IntoLua for PeekJob {
// --- Seek // --- Seek
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SeekJob { pub struct SeekJob {
pub file: File, pub file: File,
pub units: i16, pub units: i16,
} }