mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
feat: show full name relative to cwd on searching
This commit is contained in:
parent
becf62417a
commit
06cb708a80
5 changed files with 18 additions and 12 deletions
|
|
@ -5,7 +5,6 @@ use tokio::fs;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct File {
|
pub struct File {
|
||||||
pub name: String,
|
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub meta: Metadata,
|
pub meta: Metadata,
|
||||||
pub length: Option<u64>,
|
pub length: Option<u64>,
|
||||||
|
|
@ -27,9 +26,8 @@ impl File {
|
||||||
meta = fs::metadata(&path).await.unwrap_or(meta);
|
meta = fs::metadata(&path).await.unwrap_or(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
let name = path.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
|
|
||||||
let length = if meta.is_dir() { None } else { Some(meta.len()) };
|
let length = if meta.is_dir() { None } else { Some(meta.len()) };
|
||||||
let is_hidden = name.starts_with('.');
|
let is_hidden = path.file_name().map(|s| s.to_string_lossy().starts_with('.')).unwrap_or(false);
|
||||||
File { name, path: path.to_path_buf(), meta, length, is_link, is_hidden, is_selected: false }
|
File { path: path.to_path_buf(), meta, length, is_link, is_hidden, is_selected: false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ impl Files {
|
||||||
|
|
||||||
let reverse = self.sort.reverse;
|
let reverse = self.sort.reverse;
|
||||||
match self.sort.by {
|
match self.sort.by {
|
||||||
SortBy::Alphabetical => self.items.sort_by(|_, a, _, b| cmp(&a.name, &b.name, reverse)),
|
SortBy::Alphabetical => self.items.sort_by(|_, a, _, b| cmp(&a.path, &b.path, reverse)),
|
||||||
SortBy::Created => self.items.sort_by(|_, a, _, b| {
|
SortBy::Created => self.items.sort_by(|_, a, _, b| {
|
||||||
if let (Ok(a), Ok(b)) = (a.meta.created(), b.meta.created()) {
|
if let (Ok(a), Ok(b)) = (a.meta.created(), b.meta.created()) {
|
||||||
return cmp(a, b, reverse);
|
return cmp(a, b, reverse);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,14 @@ pub fn absolute_path(p: &Path) -> PathBuf {
|
||||||
p.to_path_buf()
|
p.to_path_buf()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn readable_path(p: &Path) -> String {
|
pub fn readable_path(p: &Path, base: &Path) -> String {
|
||||||
|
if let Ok(p) = p.strip_prefix(base) {
|
||||||
|
return p.display().to_string();
|
||||||
|
}
|
||||||
|
p.display().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn readable_home(p: &Path) -> String {
|
||||||
if let Ok(home) = env::var("HOME") {
|
if let Ok(home) = env::var("HOME") {
|
||||||
if let Ok(p) = p.strip_prefix(home) {
|
if let Ok(p) = p.strip_prefix(home) {
|
||||||
return format!("~/{}", p.display());
|
return format!("~/{}", p.display());
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use ratatui::{buffer::Buffer, layout::{self, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Paragraph, Widget}};
|
use ratatui::{buffer::Buffer, layout::{self, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Paragraph, Widget}};
|
||||||
|
|
||||||
use super::tabs::Tabs;
|
use super::tabs::Tabs;
|
||||||
use crate::{misc::readable_path, ui::Ctx};
|
use crate::{misc::readable_home, ui::Ctx};
|
||||||
|
|
||||||
pub struct Layout<'a> {
|
pub struct Layout<'a> {
|
||||||
cx: &'a Ctx,
|
cx: &'a Ctx,
|
||||||
|
|
@ -20,9 +20,9 @@ impl<'a> Widget for Layout<'a> {
|
||||||
|
|
||||||
let current = &self.cx.manager.current();
|
let current = &self.cx.manager.current();
|
||||||
let location = if current.in_search {
|
let location = if current.in_search {
|
||||||
format!("{} (search)", readable_path(¤t.cwd))
|
format!("{} (search)", readable_home(¤t.cwd))
|
||||||
} else {
|
} else {
|
||||||
format!("{}", readable_path(¤t.cwd))
|
format!("{}", readable_home(¤t.cwd))
|
||||||
};
|
};
|
||||||
|
|
||||||
Paragraph::new(location).style(Style::default().fg(Color::Cyan)).render(chunks[0], buf);
|
Paragraph::new(location).style(Style::default().fg(Color::Cyan)).render(chunks[0], buf);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use ratatui::{buffer::Buffer, layout::Rect, style::{Color, Modifier, Style}, widgets::{List, ListItem, Widget}};
|
use ratatui::{buffer::Buffer, layout::Rect, style::{Color, Modifier, Style}, widgets::{List, ListItem, Widget}};
|
||||||
|
|
||||||
use crate::{config::THEME, core};
|
use crate::{config::THEME, core, misc::readable_path};
|
||||||
|
|
||||||
pub struct Folder<'a> {
|
pub struct Folder<'a> {
|
||||||
folder: &'a core::manager::Folder,
|
folder: &'a core::manager::Folder,
|
||||||
|
|
@ -41,10 +41,11 @@ impl<'a> Widget for Folder<'a> {
|
||||||
.map(|x| x.display.as_ref())
|
.map(|x| x.display.as_ref())
|
||||||
.unwrap_or("");
|
.unwrap_or("");
|
||||||
|
|
||||||
|
let name = readable_path(&v.path, &self.folder.cwd);
|
||||||
let item = ListItem::new(if v.is_selected {
|
let item = ListItem::new(if v.is_selected {
|
||||||
format!("> {} {}", icon, v.name)
|
format!("> {} {}", icon, name)
|
||||||
} else {
|
} else {
|
||||||
format!("{} {}", icon, v.name)
|
format!("{} {}", icon, name)
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue