Apply rustfmt to the crate

This commit is contained in:
Andy Dixon
2026-10-08 20:05:25 +01:00
parent b1fdb48c4b
commit a16c00671b
43 changed files with 3300 additions and 652 deletions
+95 -22
View File
@@ -32,7 +32,8 @@ use std::time::{Duration, Instant};
/// Begins a scan (or returns a loaded tree with no scanner). Called again
/// on rescan.
pub type StartFn = Arc<dyn Fn(Cancel) -> Result<(Option<Scanner>, Arc<RwLock<Tree>>), crate::Error> + Send + Sync>;
pub type StartFn =
Arc<dyn Fn(Cancel) -> Result<(Option<Scanner>, Arc<RwLock<Tree>>), crate::Error> + Send + Sync>;
/// Configures the interactive session.
pub struct Options {
@@ -75,7 +76,11 @@ impl Key {
_ if s.chars().count() == 1 => s.to_string(),
_ => String::new(),
};
Key { name: s.to_string(), text, ctrl_alt: s.starts_with("ctrl+") || s.starts_with("alt+") }
Key {
name: s.to_string(),
text,
ctrl_alt: s.starts_with("ctrl+") || s.starts_with("alt+"),
}
}
}
@@ -91,15 +96,40 @@ pub(crate) enum Msg {
Size(i32, i32),
Tick,
ScanDone(Arc<RwLock<Tree>>), // identifies the scan by its tree
Filter { gen: u64, res: Option<FilterResult> },
Filter {
gen: u64,
res: Option<FilterResult>,
},
FilterDebounce(u64),
DupDone { finder: Arc<duplicate::Finder>, groups: Option<Vec<duplicate::Group>> },
TrashDone { tree: Arc<RwLock<Tree>>, id: NodeId, err: Option<String>, done: String },
SaveDone { path: String, err: Option<String> },
DupDone {
finder: Arc<duplicate::Finder>,
groups: Option<Vec<duplicate::Group>>,
},
TrashDone {
tree: Arc<RwLock<Tree>>,
id: NodeId,
err: Option<String>,
done: String,
},
SaveDone {
path: String,
err: Option<String>,
},
Key(Key),
Click { x: i32, y: i32, button: Button },
Wheel { x: i32, y: i32, up: bool },
Motion { x: i32, y: i32 },
Click {
x: i32,
y: i32,
button: Button,
},
Wheel {
x: i32,
y: i32,
up: bool,
},
Motion {
x: i32,
y: i32,
},
Quit, // SIGTERM
}
@@ -239,8 +269,13 @@ impl Model {
{
theme.ascii = true;
}
let mut views = vec![View::Map, View::List(Default::default()), View::Ext(Default::default()),
View::Top(Default::default()), View::Info(Default::default())];
let mut views = vec![
View::Map,
View::List(Default::default()),
View::Ext(Default::default()),
View::Top(Default::default()),
View::Info(Default::default()),
];
if opts.diff.is_some() {
views.push(View::Changes(Default::default()));
}
@@ -298,7 +333,9 @@ impl Model {
}
fn wait_scan(&self) -> Cmd {
let Some(s) = &self.scanner else { return Cmd::None };
let Some(s) = &self.scanner else {
return Cmd::None;
};
let (rx, tree) = (s.done().clone(), s.tree.clone());
Cmd::run(move || {
let _ = rx.recv();
@@ -307,7 +344,11 @@ impl Model {
}
pub fn refresh_interval(&self) -> Duration {
let hz = if self.opts.settings.refresh_hz <= 0 { 10 } else { self.opts.settings.refresh_hz };
let hz = if self.opts.settings.refresh_hz <= 0 {
10
} else {
self.opts.settings.refresh_hz
};
Duration::from_secs(1) / hz as u32
}
@@ -321,7 +362,9 @@ impl Model {
}
fn needs_ticks(&self) -> bool {
self.scanning || Instant::now() < self.toast_until || self.dups.as_ref().is_some_and(|d| d.running)
self.scanning
|| Instant::now() < self.toast_until
|| self.dups.as_ref().is_some_and(|d| d.running)
}
/// Shows a transient status message.
@@ -366,7 +409,10 @@ impl Model {
self.ticking = false;
if self.scanning {
self.dirty = true;
if self.last_data.is_none_or(|t| t.elapsed() >= Duration::from_millis(400)) {
if self
.last_data
.is_none_or(|t| t.elapsed() >= Duration::from_millis(400))
{
self.invalidate();
self.last_data = Some(Instant::now());
}
@@ -379,7 +425,10 @@ impl Model {
let mut cmds = Vec::new();
if self.scanning
&& self.search.query.is_some()
&& self.search.applied_at.is_none_or(|t| t.elapsed() > Duration::from_secs(1))
&& self
.search
.applied_at
.is_none_or(|t| t.elapsed() > Duration::from_secs(1))
{
cmds.push(self.apply_filter());
}
@@ -405,7 +454,12 @@ impl Model {
Cmd::None
}
Msg::DupDone { finder, groups } => self.dup_done(finder, groups),
Msg::TrashDone { tree, id, err, done } => self.trash_done(tree, id, err, done),
Msg::TrashDone {
tree,
id,
err,
done,
} => self.trash_done(tree, id, err, done),
Msg::SaveDone { path, err } => match err {
Some(e) => self.warn(format!("Snapshot save failed: {}", textutil::sanitize(&e))),
None => self.info(format!("Saved snapshot {}", textutil::sanitize(&path))),
@@ -454,13 +508,24 @@ impl Model {
let (total, files, dirs, errs, el, cancelled) = {
let t = self.tree.read().unwrap();
let st = &t.stats;
(t.node(0).total(self.size_mode), st.files + st.symlinks + st.others, st.dirs, st.total_errors(), st.elapsed(), st.cancelled)
(
t.node(0).total(self.size_mode),
st.files + st.symlinks + st.others,
st.dirs,
st.total_errors(),
st.elapsed(),
st.cancelled,
)
};
let mut cmds = Vec::new();
let rate = (files + dirs) as f64 / el.as_secs_f64().max(0.001);
let mut msg = format!(
"✓ Scan complete {} · {} files · {} dirs · {} · {}/s",
textutil::duration(el), textutil::count(files), textutil::count(dirs), textutil::size(total), textutil::count(rate as i64)
textutil::duration(el),
textutil::count(files),
textutil::count(dirs),
textutil::size(total),
textutil::count(rate as i64)
);
if cancelled {
msg = "✗ Scan cancelled — totals are incomplete".into();
@@ -507,7 +572,10 @@ impl Model {
Ok(v) => v,
Err(e) => {
cancel.cancel();
return self.warn(format!("Rescan failed: {}", textutil::sanitize(&e.to_string())));
return self.warn(format!(
"Rescan failed: {}",
textutil::sanitize(&e.to_string())
));
}
};
self.scanning = s.is_some();
@@ -536,13 +604,18 @@ impl Model {
/// Re-zooms into the remembered directory once the new scan has
/// discovered it. Takes the read lock itself.
pub fn resolve_pending_zoom(&mut self) {
let Some(pz) = self.pending_zoom.clone() else { return };
let Some(pz) = self.pending_zoom.clone() else {
return;
};
let arc = self.tree.clone();
let t = arc.read().unwrap();
let root = t.path_bytes(0);
let rel: &[u8] = if pz == root {
b""
} else if let Some(r) = pz.strip_prefix(root.as_slice()).filter(|r| root.ends_with(b"/") || r.starts_with(b"/")) {
} else if let Some(r) = pz
.strip_prefix(root.as_slice())
.filter(|r| root.ends_with(b"/") || r.starts_with(b"/"))
{
r
} else {
self.pending_zoom = None;