Compare commits

..

No commits in common. "617a05fbcdbe1a601ed563e56ea288677fd38122" and "edb7545a4d390765865dd6209b4a884b1c574110" have entirely different histories.

6 changed files with 36 additions and 133 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "zfsdu"
version = "0.2.2"
version = "0.2.0"
edition = "2021"
description = "ncdu-like disk usage viewer for ZFS with snapshot management"
authors = ["Florian Schermer"]

View File

@ -91,11 +91,11 @@ zfsdu
| **Tree** | |
| e | Expand all |
| c | Collapse all |
| **Selection (current scope)** | |
| **Selection** | |
| Space | Mark/unmark snapshot |
| + | Select all in scope |
| - | Unselect all in scope |
| * | Invert selection in scope |
| + | Select all visible snapshots |
| - | Unselect all visible snapshots |
| * | Invert selection |
| **Search & Filter** | |
| / | Search (n=next, N=prev) |
| f | Filter visible items |
@ -141,11 +141,6 @@ search_match = "lightred"
- Terminal with UTF-8 support
- Root privileges (for snapshot deletion)
## Author
**Florian Schermer**
[DATAZONE GmbH](https://datazone.de)
## License
CDDL (Common Development and Distribution License) - same as OpenZFS.

Binary file not shown.

View File

@ -190,13 +190,14 @@ impl App {
);
items.extend(child_items);
// Add snapshots (rendered after children, so last snapshot is always last item)
// Add snapshots
let snap_len = entry.snapshots.len();
let children_empty = entry.children.is_empty();
for (j, snap) in entry.snapshots.iter().enumerate() {
items.push(TreeItem {
item: ListItem::Snapshot(snap.clone()),
depth: depth + 1,
is_last: j == snap_len - 1,
is_last: j == snap_len - 1 && children_empty,
parent_is_last: child_parent_is_last.clone(),
visible: true,
parent_path: entry.full_name.clone(),
@ -211,7 +212,6 @@ impl App {
pub fn rebuild_tree(&mut self) {
self.tree_items = Self::build_tree_view(&self.root_entries, 0, &[], &self.expanded, "");
self.apply_filter();
self.refresh_search_matches();
self.ensure_valid_selection();
}
@ -350,27 +350,17 @@ impl App {
}
pub fn is_marked(&self, name: &str) -> bool {
self.marked.iter().any(|x| x == name)
}
// Reset confirm_delete state — call on any action that isn't 'd'
pub fn reset_confirm(&mut self) {
if self.confirm_delete {
self.confirm_delete = false;
self.message = Some("Delete cancelled".to_string());
}
self.marked.contains(&name.to_string())
}
pub fn delete_marked(&mut self) -> Result<()> {
if self.marked.is_empty() {
self.confirm_delete = false;
self.message = Some("No snapshots marked".to_string());
return Ok(());
}
// In dry-run mode, just show what would happen
if self.dry_run_mode {
self.confirm_delete = false;
self.show_dry_run_preview();
return Ok(());
}
@ -447,9 +437,8 @@ impl App {
}
pub fn cancel_input(&mut self) {
let was_search = self.input_mode == InputMode::Search;
self.input_mode = InputMode::Normal;
if was_search {
if self.input_mode == InputMode::Search {
self.search_query.clear();
self.search_matches.clear();
}
@ -572,60 +561,15 @@ impl App {
self.search_matches.contains(&real_index)
}
fn refresh_search_matches(&mut self) {
if self.search_query.is_empty() {
return;
}
self.search_matches.clear();
let query = self.search_query.to_lowercase();
for (i, tree_item) in self.tree_items.iter().enumerate() {
if tree_item.visible {
let name = tree_item.item.full_name().to_lowercase();
if name.contains(&query) {
self.search_matches.push(i);
}
}
}
if !self.search_matches.is_empty() {
if self.current_match >= self.search_matches.len() {
self.current_match = self.search_matches.len() - 1;
}
} else {
self.current_match = 0;
}
}
// Get the scope parent: if cursor is on a dataset, use its full_name;
// if on a snapshot, use its parent_path (the owning dataset)
fn current_scope_parent(&self) -> Option<String> {
if let Some(real_idx) = self.nth_visible(self.selected) {
self.tree_items.get(real_idx).map(|ti| match &ti.item {
ListItem::Dataset(d) => d.full_name.clone(),
ListItem::Snapshot(_) => ti.parent_path.clone(),
})
} else {
None
}
}
// Select/Unselect Group (like MC) - works in current scope
// Select/Unselect Group (like MC)
pub fn select_group(&mut self) {
let current_parent = self.current_scope_parent();
let mut count = 0;
for ti in &self.tree_items {
if ti.visible && ti.item.is_snapshot() {
let in_scope = match &current_parent {
Some(parent) => &ti.parent_path == parent,
None => true,
};
if in_scope {
let name = ti.item.full_name().to_string();
if !self.marked.contains(&name) {
self.marked.push(name);
count += 1;
}
let name = ti.item.full_name().to_string();
if !self.marked.contains(&name) {
self.marked.push(name);
count += 1;
}
}
}
@ -633,19 +577,9 @@ impl App {
}
pub fn unselect_group(&mut self) {
let current_parent = self.current_scope_parent();
let visible_names: Vec<String> = self.tree_items
.iter()
.filter(|ti| {
if !ti.visible || !ti.item.is_snapshot() {
return false;
}
match &current_parent {
Some(parent) => &ti.parent_path == parent,
None => true,
}
})
.filter(|ti| ti.visible && ti.item.is_snapshot())
.map(|ti| ti.item.full_name().to_string())
.collect();
@ -656,47 +590,32 @@ impl App {
}
pub fn invert_selection(&mut self) {
let current_parent = self.current_scope_parent();
let mut count = 0;
for ti in &self.tree_items {
// Only invert in current scope (same parent)
if ti.visible && ti.item.is_snapshot() {
let in_scope = match &current_parent {
Some(parent) => &ti.parent_path == parent,
None => true, // If no parent, work on all visible
};
if in_scope {
let name = ti.item.full_name().to_string();
if let Some(pos) = self.marked.iter().position(|x| x == &name) {
self.marked.remove(pos);
} else {
self.marked.push(name);
count += 1;
}
let name = ti.item.full_name().to_string();
if let Some(pos) = self.marked.iter().position(|x| x == &name) {
self.marked.remove(pos);
} else {
self.marked.push(name);
}
}
}
self.message = Some(format!("Inverted {} in scope", count));
self.message = Some(format!("{} snapshot(s) marked", self.marked.len()));
}
// Expand all datasets (recursively from root_entries, not just visible tree)
// Expand all datasets
pub fn expand_all(&mut self) {
Self::collect_expandable(&self.root_entries, &mut self.expanded);
for ti in &self.tree_items {
if let ListItem::Dataset(d) = &ti.item {
if d.has_children() {
self.expanded.insert(d.full_name.clone());
}
}
}
self.rebuild_tree();
self.message = Some("Expanded all".to_string());
}
fn collect_expandable(entries: &[ZfsEntry], expanded: &mut HashSet<String>) {
for entry in entries {
if entry.has_children() {
expanded.insert(entry.full_name.clone());
}
Self::collect_expandable(&entry.children, expanded);
}
}
// Collapse all datasets
pub fn collapse_all(&mut self) {
self.expanded.clear();
@ -763,7 +682,7 @@ impl App {
pub fn toggle_auto_refresh(&mut self) {
self.auto_refresh = !self.auto_refresh;
if self.auto_refresh {
self.message = Some(format!("Auto-refresh ON ({}s)", self.auto_refresh_interval));
self.message = Some("Auto-refresh ON (30s)".to_string());
} else {
self.message = Some("Auto-refresh OFF".to_string());
}

View File

@ -75,7 +75,7 @@ fn print_help() {
println!(" ↑/k, ↓/j Navigate up/down");
println!(" Enter/l Expand/collapse dataset");
println!(" Space Mark/unmark snapshot");
println!(" +/-/* Select/unselect/invert (in scope)");
println!(" +/-/* Select/unselect/invert");
println!(" s Toggle sort (Size/Date/Name)");
println!(" / Search");
println!(" f Filter");
@ -88,9 +88,6 @@ fn print_help() {
println!();
println!("CONFIG:");
println!(" ~/.config/zfsdu/config.toml");
println!();
println!("(c) Florian Schermer - DATAZONE GmbH");
println!("https://datazone.de");
}
fn run_app<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, app: &mut App) -> Result<()> {
@ -133,11 +130,6 @@ fn run_app<B: ratatui::backend::Backend>(terminal: &mut Terminal<B>, app: &mut A
return Ok(());
}
// Reset delete confirmation on any key except 'd'/F8
if key.code != KeyCode::Char('d') && key.code != KeyCode::F(8) {
app.reset_confirm();
}
match key.code {
// Navigation
KeyCode::Up | KeyCode::Char('k') => app.previous(),

View File

@ -407,11 +407,11 @@ fn draw_help(f: &mut Frame, app: &App) {
" e Expand all",
" c Collapse all",
"",
" Selection (current scope):",
" Selection:",
" Space Mark/unmark snapshot",
" + Select all in scope",
" - Unselect all in scope",
" * Invert selection in scope",
" + Select all visible snapshots",
" - Unselect all visible snapshots",
" * Invert selection",
"",
" Search & Filter:",
" / Search (n=next, N=prev)",
@ -431,9 +431,6 @@ fn draw_help(f: &mut Frame, app: &App) {
"",
" Config: ~/.config/zfsdu/config.toml",
"",
" (c) Florian Schermer - DATAZONE GmbH",
" https://datazone.de",
"",
" Press any key to close",
];