Skip to content

Commit 50fb7ba

Browse files
committed
chore : icon + compact display
1 parent 73dae88 commit 50fb7ba

File tree

2 files changed

+70
-11
lines changed

2 files changed

+70
-11
lines changed

src/graveyard.rs

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,45 @@ fn kind_letter(k: Kind) -> char {
3333
}
3434
}
3535

36+
fn kind_icon(k: Kind) -> &'static str {
37+
match k {
38+
Kind::File => "📄",
39+
Kind::Dir => "📁",
40+
Kind::Symlink => "🔗",
41+
Kind::Other => "❔",
42+
}
43+
}
44+
45+
/// Durée compacte (2 unités max) ex: "1m47s", "3h12m", "2d"
46+
fn compact_age(secs: u64) -> String {
47+
const MIN: u64 = 60;
48+
const H: u64 = 60 * MIN;
49+
const D: u64 = 24 * H;
50+
const W: u64 = 7 * D;
51+
let mut n = secs;
52+
if n < MIN {
53+
return format!("{n}s");
54+
}
55+
let mut out = String::new();
56+
let mut parts = 0;
57+
let units = [(W, "w"), (D, "d"), (H, "h"), (MIN, "m"), (1, "s")];
58+
for (unit, suf) in units {
59+
if n >= unit {
60+
let v = n / unit;
61+
n %= unit;
62+
if parts > 0 {
63+
out.push_str("");
64+
}
65+
out.push_str(&format!("{v}{suf}"));
66+
parts += 1;
67+
if parts == 2 {
68+
break;
69+
}
70+
}
71+
}
72+
out
73+
}
74+
3675
fn graveyard_dir() -> Result<PathBuf> {
3776
Ok(crate::paths::data_dir()?.join("graveyard"))
3877
}
@@ -329,16 +368,18 @@ pub fn list() -> anyhow::Result<()> {
329368
.single()
330369
.unwrap_or_else(|| Local.timestamp_opt(0, 0).single().unwrap());
331370
let absolute = dt.format("%Y-%m-%d %H:%M:%S").to_string();
332-
// âge relatif (ex: "3m 12s")
333-
let now = std::time::SystemTime::now()
371+
// âge relatif compact
372+
let now_secs = std::time::SystemTime::now()
334373
.duration_since(std::time::UNIX_EPOCH)
335-
.unwrap_or_default();
336-
let then = std::time::Duration::from_secs(e.deleted_at as u64);
337-
let rel = humantime::format_duration(now.saturating_sub(then)).to_string();
374+
.unwrap_or_default()
375+
.as_secs();
376+
let rel = compact_age(now_secs.saturating_sub(e.deleted_at as u64));
338377
let k = kind_letter(e.kind);
378+
let ico = kind_icon(e.kind);
339379
println!(
340-
"{:7} {} ({}) {} {} ({})",
380+
"{:7} {} {} ({}) {} {} ({})",
341381
id,
382+
ico,
342383
k,
343384
absolute,
344385
base,

src/ui.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,35 @@ fn human_when(ts: i64) -> String {
2222
dt.format("%Y-%m-%d %H:%M").to_string()
2323
}
2424

25-
/// Lignes pour fzf: "IDX \t DATE \t ORIGINAL \t -> \t TRASHED"
25+
fn kind_icon(k: Kind) -> &'static str {
26+
match k {
27+
Kind::File => "📄",
28+
Kind::Dir => "📁",
29+
Kind::Symlink => "🔗",
30+
Kind::Other => "❔",
31+
}
32+
}
33+
34+
/// Lignes pour fzf (compactes):
35+
/// IDX \t ICON \t DATE \t BASENAME \t ORIGINAL \t TRASHED(HIDDEN)
2636
fn build_fzf_lines(idx: &Index) -> Vec<String> {
2737
idx.items
2838
.iter()
2939
.enumerate()
3040
.map(|(i, e)| {
41+
let icon = kind_icon(e.kind);
42+
let base = e
43+
.original_path
44+
.file_name()
45+
.and_then(|s| s.to_str())
46+
.unwrap_or("")
47+
.to_string();
3148
format!(
32-
"{}\t{}\t{}\t{}\t->\t{}",
49+
"{}\t{}\t{}\t{}\t{}\t{}",
3350
i,
34-
kind_letter(e.kind),
51+
icon,
3552
human_when(e.deleted_at),
53+
base,
3654
e.original_path.display(),
3755
e.trashed_path.display()
3856
)
@@ -55,15 +73,15 @@ pub fn pick_entries_with_fzf(idx: &Index, preview: bool) -> Result<Vec<usize>> {
5573
.arg("--ansi")
5674
.arg("--print0") // sortie NUL-delimitée
5775
.args(["--delimiter", "\t"]) // champs = tab
58-
.args(["--with-nth", "3.."]) // masque l'IDX+KIND à l'affichage
76+
.args(["--with-nth", "3,4,5"])
5977
.stdin(Stdio::piped())
6078
.stdout(Stdio::piped());
6179

6280
if preview {
6381
// Aperçu simple: liste le chemin TRASHED (colonne après "->")
6482
cmd.args([
6583
"--preview",
66-
r#"sh -c 'printf "%s\n" "$@" | awk -F"\t" "{for (i=1;i<=NF;i++) if (\$i==\"->\") { print \$(i+1); exit }}" | xargs -r ls -ld --'"#,
84+
r#"sh -c 'printf "%s\n" "$@" | awk -F"\t" "{print \$NF}" | xargs -r ls -ld --'"#,
6785
"--preview-window=right:60%",
6886
]);
6987
}

0 commit comments

Comments
 (0)