feat: add calculate_cumulative_size command#628
Open
BoogerMan2103 wants to merge 2 commits into
Open
Conversation
Mirrors ranger's `dc` — recursively measures the size of selected entries (or the entry under the cursor) and displays the totals both inline on each directory and as a status-line message. Bound to `dc` by default. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
After `calculate_cumulative_size` measured a directory, sorting (which soft-reloads from disk) wiped the value and the UI fell back to the item count. Carry the field across reload alongside selection state, and let `size_sort` fall back to `cumulative_size` so directories with measured sizes sort against each other and against files. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
calculate_cumulative_sizecommand that mimics ranger'sdc("get cumulative size"). It recursively walks the visual / permanent
selection (falling back to the entry under the cursor when nothing is
selected), sums every regular file's bytes, stores the result on each
measured entry, and posts the total to the status line.
Bound to
d cby default — matches the ranger muscle memory.Closes the recurring ask for a
du -hs-style readout (see #229 and thediscussion under #334, where partial / lazy directory sizing was
rejected for breaking user expectations).
What's in the PR
New command
src/commands/cumulative_size.rs— recursive walker (du-style:does not follow symlinks, counts the symlink's own size; tolerates
per-entry I/O errors) and the command entry point. Iterates
selected_or_current(), sums, stores per-entry, and emits a statusmessage —
Size of foo: 1.2 Gfor one entry,Cumulative size of N items: …for many.Metadata
src/fs/metadata.rs— newcumulative_size: Option<u64>field,distinct from the existing
directory_size: Option<usize>(which isan item count). Accessor + setter, no other call-sites touched.
Command plumbing
The usual fan-out so the command is reachable from the keymap, the
command line, and the help page:
src/constants/command_name.rs—CMD_CALCULATE_CUMULATIVE_SIZE.src/types/command/mod.rs—Command::CalculateCumulativeSize.src/types/command/impl_appcommand.rs,impl_appexecute.rs,impl_from_str.rs,impl_comment.rs— name,dispatch, parsing, help text.
Display
src/ui/widgets/tui_dirlist_detailed.rs— when an entry carries acumulative_size, the detailed dirlist renders it throughfile_size_to_string(so a measured directory shows e.g.1.2 Ginstead of the item count). Entries that have never been measured
fall back to existing behavior (count for dirs, raw len for files),
so nothing changes until the user runs the command.
Sort integration (bug fix in the same PR)
Two follow-ups discovered while testing:
sorttriggers a soft reload, which rebuilt entries from disk andwiped
cumulative_size.src/history.rsnow carries the valueacross reload next to the existing selection-state preservation
loop, so measurements survive any reload or re-sort.
size_sortonly comparedmetadata.len()— directories alltied at 0 and the sort order was meaningless for them.
src/types/option/sort/sort_option.rsnow falls back tocumulative_sizewhen present, so directories with measured sizessort correctly against each other and against files.
Default keybind
config/keymap.toml—{ keys = ["d", "c"], commands = ["calculate_cumulative_size"] }. Thed, _chord is already usedfor
cut_files(d d) anddelete_files(d D), so this slots innaturally and matches ranger.
Behavior
d con a single directory1.2 G-style.d cwith N entries selectedCumulative size of N items: ….d con a files safterd cTradeoffs / known limitations
for the small/medium trees this is usually pointed at; for huge
trees the natural follow-up is to push the walk onto the existing
worker thread infrastructure (see
src/types/io/) and update theentry asynchronously. Kept synchronous in v1 to keep the diff
reviewable; happy to do the async pass in a follow-up PR if
preferred.
d con the same directory re-walks it.A path-keyed cache + invalidation on
mtimechange would be anatural next step.
a huge tree. Falls out of the async refactor above.