wagoodman / dive

A tool for exploring each layer in a docker image
MIT License
47.42k stars 1.79k forks source link

feat: add support for alternative ordering strategies #424

Closed iiian closed 1 year ago

iiian commented 1 year ago

Addresses https://github.com/wagoodman/dive/issues/341.

Adds a default hotkey of ctrl+o to flip between A-Z sort order and numerical sort-by-size-desc on the right-side pane.

The approach to implementing this feature was to find all of the places in code that enforce the order in which file-system nodes in the selected layer are displayed in the buffer window. Three methods were identified: FileTree.StringBetween, FileNode.VisitDepthParentFirst and FileNode.VisitDepthChildFirst. These locations were taking the FileNode's property Children map[string]*FileNode and performing sort.Strings(keys) in order to implement alphanumeric sorting.

These locations have been unified with OrderStrategy.orderKeys(map[string]*FileNode). A factory function, GetSortOrderStrategy, tees up the corresponding ordering strategy given an enum, which it then propagates down to the three mentioned methods.

Additionally, a Size int64 field has been attached to FileNode in order to cache information on directory/file size for use in the sort-by-size-desc strategy (with a simple extraction refactor of the FileNode.MetadataString method.

Happy New Year! 🥂

wagoodman commented 1 year ago

Sorry! I didn't mean to close this, I renamed the master branch to main... I should have switched the target here first.

wagoodman commented 1 year ago

@iiian if you'd like to re-open the PR against main I'd be happy to take a look

wagoodman commented 1 year ago

@iiian I recreated the master branch temporarily to get this in (I didn't think of that earlier). Just force pushed to rebase.

iiian commented 1 year ago

Rad!

Potherca commented 1 year ago

FYI: This closes #89