Skip to content

Commit eb01714

Browse files
committed
feat : list coloration + remove warnings
1 parent cad677c commit eb01714

File tree

2 files changed

+28
-37
lines changed

2 files changed

+28
-37
lines changed

src/graveyard.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use anyhow::{Context, Result};
99
use chrono::{Local, TimeZone, Utc};
1010
use fs_err as fs;
1111
use std::ffi::OsString;
12+
use yansi::{Color, Paint};
1213

1314
use crate::fs_safemove::safe_move_unique;
1415
use crate::safety::{SafetyCtx, guard_path};
@@ -43,33 +44,26 @@ fn kind_icon(k: Kind) -> &'static str {
4344
}
4445

4546
/// Durée compacte (2 unités max) ex: "1m47s", "3h12m", "2d"
46-
fn compact_age(secs: u64) -> String {
47+
fn compact_age(mut secs: u64) -> String {
4748
const MIN: u64 = 60;
4849
const H: u64 = 60 * MIN;
4950
const D: u64 = 24 * H;
5051
const W: u64 = 7 * D;
51-
let mut n = secs;
52-
if n < MIN {
53-
return format!("{n}s");
54-
}
52+
let units = [(W, "w"), (D, "d"), (H, "h"), (MIN, "m"), (1, "s")];
5553
let mut out = String::new();
5654
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-
}
55+
for (u, suf) in units {
56+
if secs >= u {
57+
let v = secs / u;
58+
secs %= u;
6559
out.push_str(&format!("{v}{suf}"));
6660
parts += 1;
6761
if parts == 2 {
6862
break;
6963
}
7064
}
7165
}
72-
out
66+
if out.is_empty() { "0s".into() } else { out }
7367
}
7468

7569
fn graveyard_dir() -> Result<PathBuf> {
@@ -376,16 +370,17 @@ pub fn list() -> anyhow::Result<()> {
376370
let rel = compact_age(now_secs.saturating_sub(e.deleted_at as u64));
377371
let k = kind_letter(e.kind);
378372
let ico = kind_icon(e.kind);
379-
println!(
380-
"{:7} {} {} ({}) {} {} ({})",
381-
id,
382-
ico,
383-
k,
384-
absolute,
385-
base,
386-
e.original_path.display(),
387-
rel
388-
);
373+
374+
// Couleurs sobres (respectées/neutralisées par yansi::enable/disable dans main.rs)
375+
let id_p = Paint::new(format!("{id:7}")).dim();
376+
let icon_p = Paint::new(ico).fg(Color::Cyan);
377+
let k_p = Paint::new(k).fg(Color::Cyan);
378+
let date_p = Paint::new(format!("({absolute})")).dim();
379+
let name_p = Paint::new(base).bold();
380+
let path_p = Paint::new(e.original_path.display()).dim();
381+
let age_p = Paint::new(format!("({rel})")).italic().dim();
382+
383+
println!("{id_p} {icon_p} {k_p} {date_p} {name_p} {path_p} {age_p}");
389384
}
390385
Ok(())
391386
}
@@ -550,7 +545,7 @@ pub fn prune(target: Option<String>, dry_run: bool, yes: bool) -> anyhow::Result
550545
};
551546
}
552547
}
553-
remaining.clear(); // au cas où
548+
remaining.resetting();
554549
}
555550

556551
idx.items = remaining;

src/ui.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,7 @@ use chrono::{Local, TimeZone};
33
use std::process::{Command, Stdio};
44

55
use crate::index::{Index, Kind};
6-
7-
fn kind_letter(k: Kind) -> char {
8-
match k {
9-
Kind::File => 'F',
10-
Kind::Dir => 'D',
11-
Kind::Symlink => 'L',
12-
Kind::Other => '?',
13-
}
14-
}
6+
use yansi::{Color, Paint};
157

168
fn human_when(ts: i64) -> String {
179
// Date locale courte (pour fzf)
@@ -45,12 +37,16 @@ fn build_fzf_lines(idx: &Index) -> Vec<String> {
4537
.and_then(|s| s.to_str())
4638
.unwrap_or("")
4739
.to_string();
40+
// Champ 0 (index) ***NON COLORÉ*** pour le parse
41+
let icon_p = Paint::new(icon).fg(Color::Cyan).to_string();
42+
let date_p = Paint::new(human_when(e.deleted_at)).dim().to_string();
43+
let base_p = Paint::new(base).bold().to_string();
4844
format!(
4945
"{}\t{}\t{}\t{}\t{}\t{}",
5046
i,
51-
icon,
52-
human_when(e.deleted_at),
53-
base,
47+
icon_p,
48+
date_p,
49+
base_p,
5450
e.original_path.display(),
5551
e.trashed_path.display()
5652
)

0 commit comments

Comments
 (0)