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 {
type Target = yazi_core::tab::Preview;
fn deref(&self) -> &Self::Target {
&self.tab.preview
}
fn deref(&self) -> &Self::Target { &self.tab.preview }
}
impl Preview {

View file

@ -4,8 +4,8 @@ const EXPECTED: &str = "expected a table containing a line and a length";
#[derive(Clone, Debug)]
pub struct HighlightPosition {
pub line: usize,
pub col: usize,
pub line: usize,
pub col: usize,
pub length: usize,
}
@ -24,8 +24,8 @@ impl FromLua for HighlightPosition {
fn from_lua(value: Value, _: &Lua) -> mlua::Result<Self> {
match value {
Value::Table(tbl) => Ok(Self {
line: tbl.raw_get("line")?,
col: tbl.raw_get("col")?,
line: tbl.raw_get("line")?,
col: tbl.raw_get("col")?,
length: tbl.raw_get("length")?,
}),
_ => 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 ratatui_core::{
layout::Size,
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 ratatui_core::{layout::Size, text::{Line, Span, Text}};
use syntect::{LoadingError, dumps, easy::HighlightLines, highlighting::{self, Theme, ThemeSet}, parsing::{SyntaxReference, SyntaxSet}};
use yazi_binding::elements::HighlightPosition;
use yazi_config::{THEME, YAZI};
use yazi_runner::previewer::PeekError;
use yazi_shared::{
id::{Id, Ids},
replace_to_printable,
};
use yazi_shared::{id::{Id, Ids}, replace_to_printable};
use yazi_shim::ratatui::LineIter;
static INCR: Ids = Ids::new();
pub struct Highlighter {
path: PathBuf,
path: PathBuf,
reader: BufReader<std::fs::File>,
skip: usize,
size: Size,
skip: usize,
size: Size,
ticket: Id,
theme: &'static Theme,
theme: &'static Theme,
syntaxes: &'static SyntaxSet,
inner: Option<HighlightLines<'static>>,
syntax: Option<&'static SyntaxReference>,
inner: Option<HighlightLines<'static>>,
syntax: Option<&'static SyntaxReference>,
}
impl Highlighter {
@ -77,9 +63,7 @@ impl Highlighter {
})
}
pub fn abort() {
INCR.next();
}
pub fn abort() { INCR.next(); }
fn highlight(mut self, position: Option<HighlightPosition>) -> Result<Text<'static>, PeekError> {
self.load_syntax()?;
@ -265,7 +249,7 @@ impl Highlighter {
Span {
content: s.into(),
style: ratatui_core::style::Style {
style: ratatui_core::style::Style {
fg: Self::to_ansi_color(style.foreground),
// bg: Self::to_ansi_color(style.background),
add_modifier: modifier,

View file

@ -44,14 +44,14 @@ impl MgrProxy {
pub fn update_peeked_error(job: PeekJob, error: String) {
let area = LAYOUT.get().preview;
Self::update_peeked(PreviewLock {
url: job.file.url,
cha: job.file.cha,
url: job.file.url,
cha: job.file.cha,
mime: job.mime,
skip: job.skip,
skip: job.skip,
search_idx: job.search_idx,
area: area.into(),
data: vec![
area: area.into(),
data: vec![
Renderable::Clear(Default::default()).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_fs::{Entries, FilesOp, cha::Cha, file::File};
use yazi_macro::render;
use yazi_runner::{
RUNNER,
previewer::{PeekError, PeekJob},
};
use yazi_shared::{
pool::Symbol,
url::{UrlBuf, UrlLike},
};
use yazi_runner::{RUNNER, previewer::{PeekError, PeekJob}};
use yazi_shared::{pool::Symbol, url::{UrlBuf, UrlLike}};
use yazi_vfs::{VfsEntries, VfsFilesOp};
use crate::{AppProxy, Highlighter, MgrProxy, tab::PreviewLock};
#[derive(Default, Debug)]
pub struct Preview {
pub lock: Option<PreviewLock>,
pub skip: usize,
pub lock: Option<PreviewLock>,
pub skip: usize,
pub search_idx: Option<usize>,
handle: Option<JoinHandle<()>>,
handle: Option<JoinHandle<()>>,
pub folder_lock: Option<UrlBuf>,
folder_loader: Option<JoinHandle<()>>,
folder_loader: Option<JoinHandle<()>>,
}
impl Preview {
@ -104,9 +98,7 @@ impl Preview {
ADAPTOR.image_hide().ok();
}
pub fn same_url(&self, url: &UrlBuf) -> bool {
matches!(&self.lock, Some(l) if l.url == *url)
}
pub fn same_url(&self, url: &UrlBuf) -> bool { matches!(&self.lock, Some(l) if l.url == *url) }
pub fn same_file(&self, file: &File, mime: &str) -> bool {
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)
}
pub fn same_folder(&self, url: &UrlBuf) -> bool {
self.folder_lock.as_ref() == Some(url)
}
pub fn same_folder(&self, url: &UrlBuf) -> bool { self.folder_lock.as_ref() == Some(url) }
}

View file

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

View file

@ -3,39 +3,33 @@ use yazi_shared::{event::ActionCow, url::UrlBuf};
#[derive(Debug, Default)]
pub struct PeekForm {
pub skip: Option<usize>,
pub force: bool,
pub only_if: Option<UrlBuf>,
pub skip: Option<usize>,
pub force: bool,
pub only_if: Option<UrlBuf>,
pub upper_bound: bool,
pub search_idx: Option<usize>,
pub search_idx: Option<usize>,
}
impl From<ActionCow> for PeekForm {
fn from(mut a: ActionCow) -> Self {
Self {
skip: a.first().ok(),
force: a.bool("force"),
only_if: a.take("only-if").ok(),
skip: a.first().ok(),
force: a.bool("force"),
only_if: a.take("only-if").ok(),
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 {
fn from(force: bool) -> Self {
Self { force, ..Default::default() }
}
fn from(force: bool) -> Self { Self { force, ..Default::default() } }
}
impl FromLua for PeekForm {
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> {
Err("unsupported".into_lua_err())
}
fn from_lua(_: Value, _: &Lua) -> mlua::Result<Self> { Err("unsupported".into_lua_err()) }
}
impl IntoLua for PeekForm {
fn into_lua(self, _: &Lua) -> mlua::Result<Value> {
Err("unsupported".into_lua_err())
}
fn into_lua(self, _: &Lua) -> mlua::Result<Value> { 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 tokio::{
io::{AsyncBufReadExt, BufReader},
process::Command,
sync::mpsc::{self, UnboundedReceiver},
};
use tokio::{io::{AsyncBufReadExt, BufReader}, process::Command, sync::mpsc::{self, UnboundedReceiver}};
use yazi_fs::{FsUrl, file::File};
use yazi_shared::url::{AsUrl, UrlBuf, UrlLike};
use yazi_vfs::VfsFile;
pub struct RgOpt {
pub cwd: UrlBuf,
pub hidden: bool,
pub cwd: UrlBuf,
pub hidden: bool,
pub subject: String,
pub args: Vec<String>,
pub args: Vec<String>,
}
pub fn rg(opt: RgOpt) -> Result<UnboundedReceiver<File>> {

View file

@ -1,8 +1,5 @@
use mlua::{ExternalError, Function, IntoLuaMulti, Lua, Table, Value};
use yazi_binding::{
Error,
elements::{Area, HighlightPosition},
};
use yazi_binding::{Error, elements::{Area, HighlightPosition}};
use yazi_core::{Highlighter, MgrProxy, tab::PreviewLock};
use yazi_fs::FsUrl;
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> {
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)]
pub struct PeekJob {
pub previewer: PreviewerArc,
pub file: File,
pub mime: Symbol<str>,
pub skip: usize,
pub previewer: PreviewerArc,
pub file: File,
pub mime: Symbol<str>,
pub skip: usize,
pub search_idx: Option<usize>,
}
@ -31,7 +31,7 @@ impl IntoLua for PeekJob {
// --- Seek
#[derive(Clone, Debug)]
pub struct SeekJob {
pub file: File,
pub file: File,
pub units: i16,
}