From 09296c0214c4cc7477fe53bc79c54805899c6d19 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Sat, 6 Apr 2019 13:28:54 -0400 Subject: [PATCH] consider collapsed dirs in visible tree size (fixes #185) --- README.md | 12 ++++++------ filetree/tree.go | 12 +++++++++++- ui/filetree_controller.go | 3 +++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ea01dfa6..51211300 100644 --- a/README.md +++ b/README.md @@ -74,14 +74,14 @@ Analyze and image and get a pass/fail result based on the image efficiency and w **Ubuntu/Debian** ```bash -wget https://github.com/wagoodman/dive/releases/download/v0.7.1/dive_0.7.1_linux_amd64.deb -sudo apt install ./dive_0.7.1_linux_amd64.deb +wget https://github.com/wagoodman/dive/releases/download/v0.7.2/dive_0.7.2_linux_amd64.deb +sudo apt install ./dive_0.7.2_linux_amd64.deb ``` **RHEL/Centos** ```bash -curl -OL https://github.com/wagoodman/dive/releases/download/v0.7.1/dive_0.7.1_linux_amd64.rpm -rpm -i dive_0.7.1_linux_amd64.rpm +curl -OL https://github.com/wagoodman/dive/releases/download/v0.7.2/dive_0.7.2_linux_amd64.rpm +rpm -i dive_0.7.2_linux_amd64.rpm ``` **Arch Linux** @@ -100,11 +100,11 @@ The above example assumes [`yay`](https://aur.archlinux.org/packages/yay/) as th brew tap wagoodman/dive brew install dive ``` -or download the latest Darwin build from the [releases page](https://github.com/wagoodman/dive/releases/download/v0.7.1/dive_0.7.1_darwin_amd64.tar.gz). +or download the latest Darwin build from the [releases page](https://github.com/wagoodman/dive/releases/download/v0.7.2/dive_0.7.2_darwin_amd64.tar.gz). **Windows** -Download the [latest release](https://github.com/wagoodman/dive/releases/download/v0.7.1/dive_0.7.1_windows_amd64.zip). +Download the [latest release](https://github.com/wagoodman/dive/releases/download/v0.7.2/dive_0.7.2_windows_amd64.zip). **Go tools** Requires Go version 1.9 or higher. diff --git a/filetree/tree.go b/filetree/tree.go index b9cc8348..46309cec 100644 --- a/filetree/tree.go +++ b/filetree/tree.go @@ -127,13 +127,23 @@ func (tree *FileTree) VisibleSize() int { return nil } visitEvaluator := func(node *FileNode) bool { - return !node.Data.ViewInfo.Collapsed && !node.Data.ViewInfo.Hidden + if node.Data.FileInfo.IsDir { + // we won't visit a collapsed dir, but we need to count it + if node.Data.ViewInfo.Collapsed { + size++ + } + return !node.Data.ViewInfo.Collapsed && !node.Data.ViewInfo.Hidden + } + return !node.Data.ViewInfo.Hidden } err := tree.VisitDepthParentFirst(visitor, visitEvaluator) if err != nil { logrus.Errorf("unable to determine visible tree size: %+v", err) } + // don't include root + size-- + return size } diff --git a/ui/filetree_controller.go b/ui/filetree_controller.go index 2ce8573e..cc53cc7d 100644 --- a/ui/filetree_controller.go +++ b/ui/filetree_controller.go @@ -287,6 +287,9 @@ func (controller *FileTreeController) toggleCollapseAll() error { if err != nil { return err } + if controller.vm.CollapseAll { + controller.resetCursor() + } controller.Update() return controller.Render() }