Skip to content

Commit

Permalink
consider collapsed dirs in visible tree size (fixes #185)
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Apr 6, 2019
1 parent fa48fc1 commit 09296c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion filetree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions ui/filetree_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 09296c0

Please sign in to comment.