mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01: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)]
|
||||
pub struct File {
|
||||
pub name: String,
|
||||
pub path: PathBuf,
|
||||
pub meta: Metadata,
|
||||
pub length: Option<u64>,
|
||||
|
|
@ -27,9 +26,8 @@ impl File {
|
|||
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 is_hidden = name.starts_with('.');
|
||||
File { name, path: path.to_path_buf(), meta, length, is_link, is_hidden, is_selected: false }
|
||||
let is_hidden = path.file_name().map(|s| s.to_string_lossy().starts_with('.')).unwrap_or(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;
|
||||
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| {
|
||||
if let (Ok(a), Ok(b)) = (a.meta.created(), b.meta.created()) {
|
||||
return cmp(a, b, reverse);
|
||||
|
|
|
|||
|
|
@ -31,7 +31,14 @@ pub fn absolute_path(p: &Path) -> PathBuf {
|
|||
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(p) = p.strip_prefix(home) {
|
||||
return format!("~/{}", p.display());
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use ratatui::{buffer::Buffer, layout::{self, Constraint, Direction, Rect}, style::{Color, Style}, widgets::{Paragraph, Widget}};
|
||||
|
||||
use super::tabs::Tabs;
|
||||
use crate::{misc::readable_path, ui::Ctx};
|
||||
use crate::{misc::readable_home, ui::Ctx};
|
||||
|
||||
pub struct Layout<'a> {
|
||||
cx: &'a Ctx,
|
||||
|
|
@ -20,9 +20,9 @@ impl<'a> Widget for Layout<'a> {
|
|||
|
||||
let current = &self.cx.manager.current();
|
||||
let location = if current.in_search {
|
||||
format!("{} (search)", readable_path(¤t.cwd))
|
||||
format!("{} (search)", readable_home(¤t.cwd))
|
||||
} else {
|
||||
format!("{}", readable_path(¤t.cwd))
|
||||
format!("{}", readable_home(¤t.cwd))
|
||||
};
|
||||
|
||||
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 crate::{config::THEME, core};
|
||||
use crate::{config::THEME, core, misc::readable_path};
|
||||
|
||||
pub struct Folder<'a> {
|
||||
folder: &'a core::manager::Folder,
|
||||
|
|
@ -41,10 +41,11 @@ impl<'a> Widget for Folder<'a> {
|
|||
.map(|x| x.display.as_ref())
|
||||
.unwrap_or("");
|
||||
|
||||
let name = readable_path(&v.path, &self.folder.cwd);
|
||||
let item = ListItem::new(if v.is_selected {
|
||||
format!("> {} {}", icon, v.name)
|
||||
format!("> {} {}", icon, name)
|
||||
} else {
|
||||
format!("{} {}", icon, v.name)
|
||||
format!("{} {}", icon, name)
|
||||
});
|
||||
|
||||
let mut style = Style::default();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue