mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
..
This commit is contained in:
parent
1af7d728d6
commit
0feb025dcf
10 changed files with 43 additions and 45 deletions
|
|
@ -36,7 +36,7 @@ impl Ctx {
|
||||||
}
|
}
|
||||||
Position::Hovered(rect @ Rect { mut x, y, width, height }) => {
|
Position::Hovered(rect @ Rect { mut x, y, width, height }) => {
|
||||||
let Some(r) =
|
let Some(r) =
|
||||||
self.manager.hovered().and_then(|h| self.manager.current().rect_current(&h.path))
|
self.manager.hovered().and_then(|h| self.manager.current().rect_current(h.path()))
|
||||||
else {
|
else {
|
||||||
return self.area(&Position::Top(*rect));
|
return self.area(&Position::Top(*rect));
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ impl<'a> Folder<'a> {
|
||||||
THEME
|
THEME
|
||||||
.filetypes
|
.filetypes
|
||||||
.iter()
|
.iter()
|
||||||
.find(|x| x.matches(&file.path, mimetype.get(&file.path).cloned(), file.meta.is_dir()))
|
.find(|x| x.matches(file.path(), mimetype.get(file.path()), file.meta.is_dir()))
|
||||||
.map(|x| x.style.get())
|
.map(|x| x.style.get())
|
||||||
.unwrap_or_else(Style::new)
|
.unwrap_or_else(Style::new)
|
||||||
}
|
}
|
||||||
|
|
@ -60,11 +60,11 @@ impl<'a> Widget for Folder<'a> {
|
||||||
let icon = THEME
|
let icon = THEME
|
||||||
.icons
|
.icons
|
||||||
.iter()
|
.iter()
|
||||||
.find(|x| x.name.match_path(&f.path, Some(f.meta.is_dir())))
|
.find(|x| x.name.match_path(f.path(), Some(f.meta.is_dir())))
|
||||||
.map(|x| x.display.as_ref())
|
.map(|x| x.display.as_ref())
|
||||||
.unwrap_or("");
|
.unwrap_or("");
|
||||||
|
|
||||||
let is_selected = self.folder.files.is_selected(&f.path);
|
let is_selected = self.folder.files.is_selected(f.path());
|
||||||
if (!self.is_selection && is_selected)
|
if (!self.is_selection && is_selected)
|
||||||
|| (self.is_selection && mode.pending(i, is_selected))
|
|| (self.is_selection && mode.pending(i, is_selected))
|
||||||
{
|
{
|
||||||
|
|
@ -78,7 +78,7 @@ impl<'a> Widget for Folder<'a> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hovered = matches!(self.folder.hovered, Some(ref h) if h.path == f.path);
|
let hovered = matches!(self.folder.hovered, Some(ref h) if h.path() == f.path());
|
||||||
let style = if self.is_preview && hovered {
|
let style = if self.is_preview && hovered {
|
||||||
THEME.preview.hovered.get()
|
THEME.preview.hovered.get()
|
||||||
} else if hovered {
|
} else if hovered {
|
||||||
|
|
@ -87,7 +87,7 @@ impl<'a> Widget for Folder<'a> {
|
||||||
self.file_style(f)
|
self.file_style(f)
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut path = format!(" {icon} {}", readable_path(&f.path, &self.folder.cwd));
|
let mut path = format!(" {icon} {}", readable_path(f.path(), &self.folder.cwd));
|
||||||
if let Some(ref link_to) = f.link_to {
|
if let Some(ref link_to) = f.link_to {
|
||||||
if MANAGER.show_symlink {
|
if MANAGER.show_symlink {
|
||||||
path.push_str(&format!(" -> {}", link_to.display()));
|
path.push_str(&format!(" -> {}", link_to.display()));
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ impl<'a> Preview<'a> {
|
||||||
impl<'a> Widget for Preview<'a> {
|
impl<'a> Widget for Preview<'a> {
|
||||||
fn render(self, area: Rect, buf: &mut Buffer) {
|
fn render(self, area: Rect, buf: &mut Buffer) {
|
||||||
let manager = &self.cx.manager;
|
let manager = &self.cx.manager;
|
||||||
let Some(hovered) = manager.hovered().map(|h| &h.path) else {
|
let Some(hovered) = manager.hovered().map(|h| h.path()) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ pub struct Filetype {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Filetype {
|
impl Filetype {
|
||||||
pub fn matches(&self, path: &Path, mime: Option<String>, is_dir: bool) -> bool {
|
pub fn matches(&self, path: &Path, mime: Option<impl AsRef<str>>, is_dir: bool) -> bool {
|
||||||
if self.name.as_ref().map_or(false, |e| e.match_path(path, Some(is_dir))) {
|
if self.name.as_ref().map_or(false, |e| e.match_path(path, Some(is_dir))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if let Some(mime) = mime {
|
if let Some(mime) = mime {
|
||||||
return self.mime.as_ref().map_or(false, |m| m.matches(&mime));
|
return self.mime.as_ref().map_or(false, |m| m.matches(mime));
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ use tokio::fs;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub path: PathBuf,
|
pub(super) path: PathBuf,
|
||||||
pub meta: Metadata,
|
pub meta: Metadata,
|
||||||
pub length: Option<u64>,
|
pub length: Option<u64>,
|
||||||
pub link_to: Option<PathBuf>,
|
pub link_to: Option<PathBuf>,
|
||||||
pub is_link: bool,
|
pub is_link: bool,
|
||||||
pub is_hidden: bool,
|
pub is_hidden: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl File {
|
impl File {
|
||||||
|
|
@ -40,10 +40,7 @@ impl File {
|
||||||
pub fn path(&self) -> &PathBuf { &self.path }
|
pub fn path(&self) -> &PathBuf { &self.path }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn set_path(mut self, path: PathBuf) -> Self {
|
pub fn set_path(&mut self, path: PathBuf) { self.path = path; }
|
||||||
self.path = path;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn name(&self) -> Option<Cow<str>> { self.path.file_name().map(|s| s.to_string_lossy()) }
|
pub fn name(&self) -> Option<Cow<str>> { self.path.file_name().map(|s| s.to_string_lossy()) }
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ impl Folder {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hover_force(&mut self, file: File) -> bool {
|
pub fn hover_force(&mut self, file: File) -> bool {
|
||||||
if self.hover(&file.path) {
|
if self.hover(file.path()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,11 +63,11 @@ impl Manager {
|
||||||
|
|
||||||
let mime = if hovered.meta.is_dir() {
|
let mime = if hovered.meta.is_dir() {
|
||||||
MIME_DIR.to_owned()
|
MIME_DIR.to_owned()
|
||||||
} else if let Some(m) = self.mimetype.get(&hovered.path).cloned() {
|
} else if let Some(m) = self.mimetype.get(hovered.path()).cloned() {
|
||||||
m
|
m
|
||||||
} else {
|
} else {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
if let Ok(mimes) = external::file(&[hovered.path]).await {
|
if let Ok(mimes) = external::file(&[hovered.path()]).await {
|
||||||
emit!(Mimetype(mimes));
|
emit!(Mimetype(mimes));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -75,9 +75,9 @@ impl Manager {
|
||||||
};
|
};
|
||||||
|
|
||||||
if sequent {
|
if sequent {
|
||||||
self.active_mut().preview.sequent(&hovered.path, &mime, show_image);
|
self.active_mut().preview.sequent(hovered.path(), &mime, show_image);
|
||||||
} else {
|
} else {
|
||||||
self.active_mut().preview.go(&hovered.path, &mime, show_image);
|
self.active_mut().preview.go(hovered.path(), &mime, show_image);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
@ -117,7 +117,7 @@ impl Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn open(&mut self, interactive: bool) -> bool {
|
pub fn open(&mut self, interactive: bool) -> bool {
|
||||||
let mut files = self
|
let mut files: Vec<_> = self
|
||||||
.selected()
|
.selected()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| {
|
.map(|f| {
|
||||||
|
|
@ -126,11 +126,11 @@ impl Manager {
|
||||||
if f.meta.is_dir() {
|
if f.meta.is_dir() {
|
||||||
Some(MIME_DIR.to_owned())
|
Some(MIME_DIR.to_owned())
|
||||||
} else {
|
} else {
|
||||||
self.mimetype.get(&f.path).cloned()
|
self.mimetype.get(f.path()).cloned()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect();
|
||||||
|
|
||||||
if files.is_empty() {
|
if files.is_empty() {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -339,7 +339,7 @@ impl Manager {
|
||||||
.or_insert_with(|| Folder::new(&path))
|
.or_insert_with(|| Folder::new(&path))
|
||||||
.update(op);
|
.update(op);
|
||||||
|
|
||||||
matches!(self.hovered(), Some(h) if h.path == path)
|
matches!(self.hovered(), Some(h) if h.path() == &path)
|
||||||
};
|
};
|
||||||
|
|
||||||
b |= self.active_mut().parent.as_mut().map_or(false, |p| p.hover(&cwd));
|
b |= self.active_mut().parent.as_mut().map_or(false, |p| p.hover(&cwd));
|
||||||
|
|
@ -402,7 +402,7 @@ impl Manager {
|
||||||
};
|
};
|
||||||
|
|
||||||
if hovered.meta.is_dir() {
|
if hovered.meta.is_dir() {
|
||||||
self.watcher.trigger_dirs(&[&hovered.path]);
|
self.watcher.trigger_dirs(&[hovered.path()]);
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,7 @@ impl Tab {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let rep = self.history_new(&hovered.path);
|
let rep = self.history_new(hovered.path());
|
||||||
let rep = mem::replace(&mut self.current, rep);
|
let rep = mem::replace(&mut self.current, rep);
|
||||||
if !rep.in_search {
|
if !rep.in_search {
|
||||||
self.history.insert(rep.cwd.clone(), rep);
|
self.history.insert(rep.cwd.clone(), rep);
|
||||||
|
|
@ -140,7 +140,7 @@ impl Tab {
|
||||||
if let Some(rep) = self.parent.take() {
|
if let Some(rep) = self.parent.take() {
|
||||||
self.history.insert(rep.cwd.clone(), rep);
|
self.history.insert(rep.cwd.clone(), rep);
|
||||||
}
|
}
|
||||||
self.parent = Some(self.history_new(hovered.path.parent().unwrap()));
|
self.parent = Some(self.history_new(hovered.path().parent().unwrap()));
|
||||||
|
|
||||||
emit!(Refresh);
|
emit!(Refresh);
|
||||||
true
|
true
|
||||||
|
|
@ -151,7 +151,7 @@ impl Tab {
|
||||||
.current
|
.current
|
||||||
.hovered
|
.hovered
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|h| h.path.parent())
|
.and_then(|h| h.path().parent())
|
||||||
.and_then(|p| if p == self.current.cwd { None } else { Some(p) })
|
.and_then(|p| if p == self.current.cwd { None } else { Some(p) })
|
||||||
.or_else(|| self.current.cwd.parent());
|
.or_else(|| self.current.cwd.parent());
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ impl Tab {
|
||||||
|
|
||||||
pub fn select(&mut self, state: Option<bool>) -> bool {
|
pub fn select(&mut self, state: Option<bool>) -> bool {
|
||||||
if let Some(ref hovered) = self.current.hovered {
|
if let Some(ref hovered) = self.current.hovered {
|
||||||
return self.current.files.select(&hovered.path, state);
|
return self.current.files.select(hovered.path(), state);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
@ -209,10 +209,10 @@ impl Tab {
|
||||||
let mut it = self.selected().into_iter().peekable();
|
let mut it = self.selected().into_iter().peekable();
|
||||||
while let Some(f) = it.next() {
|
while let Some(f) = it.next() {
|
||||||
s.push(match type_ {
|
s.push(match type_ {
|
||||||
"path" => f.path.as_os_str(),
|
"path" => f.path().as_os_str(),
|
||||||
"dirname" => f.path.parent().map_or(OsStr::new(""), |p| p.as_os_str()),
|
"dirname" => f.path().parent().map_or(OsStr::new(""), |p| p.as_os_str()),
|
||||||
"filename" => f.path.file_name().unwrap_or(OsStr::new("")),
|
"filename" => f.path().file_name().unwrap_or(OsStr::new("")),
|
||||||
"name_without_ext" => f.path.file_stem().unwrap_or(OsStr::new("")),
|
"name_without_ext" => f.path().file_stem().unwrap_or(OsStr::new("")),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
});
|
});
|
||||||
if it.peek().is_some() {
|
if it.peek().is_some() {
|
||||||
|
|
@ -288,7 +288,7 @@ impl Tab {
|
||||||
let selected: Vec<_> = self
|
let selected: Vec<_> = self
|
||||||
.selected()
|
.selected()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|f| (f.path.as_os_str().to_owned(), Default::default()))
|
.map(|f| (f.path().as_os_str().to_owned(), Default::default()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut exec = exec.to_owned();
|
let mut exec = exec.to_owned();
|
||||||
|
|
@ -315,7 +315,7 @@ impl Tab {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if path.as_ref().map(|p| *p != hovered.path).unwrap_or(false) {
|
if path.as_ref().map(|p| p != hovered.path()).unwrap_or(false) {
|
||||||
return;
|
return;
|
||||||
} else if !self.preview.arrow(step, path.is_some()) {
|
} else if !self.preview.arrow(step, path.is_some()) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -333,7 +333,7 @@ impl Tab {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_preview(&mut self, lock: PreviewLock) -> bool {
|
pub fn update_preview(&mut self, lock: PreviewLock) -> bool {
|
||||||
let Some(hovered) = self.current.hovered.as_ref().map(|h| &h.path) else {
|
let Some(hovered) = self.current.hovered.as_ref().map(|h| h.path()) else {
|
||||||
return self.preview.reset();
|
return self.preview.reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,8 @@ impl Watcher {
|
||||||
Ok(items) => {
|
Ok(items) => {
|
||||||
let mut files = Vec::with_capacity(items.len());
|
let mut files = Vec::with_capacity(items.len());
|
||||||
for item in items {
|
for item in items {
|
||||||
let file = item.clone().set_path(ori.join(item.path.strip_prefix(path).unwrap()));
|
let mut file = item.clone();
|
||||||
|
file.set_path(ori.join(item.path().strip_prefix(path).unwrap()));
|
||||||
files.push(file);
|
files.push(file);
|
||||||
}
|
}
|
||||||
FilesOp::Read(ori, files)
|
FilesOp::Read(ori, files)
|
||||||
|
|
|
||||||
|
|
@ -228,11 +228,11 @@ impl Tasks {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn precache_mime(&self, targets: &[File], mimetype: &HashMap<PathBuf, String>) -> bool {
|
pub fn precache_mime(&self, targets: &[File], mimetype: &HashMap<PathBuf, String>) -> bool {
|
||||||
let targets = targets
|
let targets: Vec<_> = targets
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|f| f.meta.is_file() && !mimetype.contains_key(&f.path))
|
.filter(|f| f.meta.is_file() && !mimetype.contains_key(f.path()))
|
||||||
.map(|f| f.path.clone())
|
.map(|f| f.path().clone())
|
||||||
.collect::<Vec<_>>();
|
.collect();
|
||||||
|
|
||||||
if !targets.is_empty() {
|
if !targets.is_empty() {
|
||||||
self.scheduler.precache_mime(targets);
|
self.scheduler.precache_mime(targets);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue