renderStringTreeBetween returns a string representing the given tree between the given rows. Since each node is rendered on its own line, the returned string shows the visible nodes not affected by a collapsed parent.
(startRow, stopRow int, showAttributes bool)
| 56 | // renderStringTreeBetween returns a string representing the given tree between the given rows. Since each node |
| 57 | // is rendered on its own line, the returned string shows the visible nodes not affected by a collapsed parent. |
| 58 | func (tree *FileTree) renderStringTreeBetween(startRow, stopRow int, showAttributes bool) string { |
| 59 | // generate a list of nodes to render |
| 60 | var params = make([]renderParams, 0) |
| 61 | var result string |
| 62 | |
| 63 | // visit from the front of the list |
| 64 | var paramsToVisit = []renderParams{{node: tree.Root, spaces: []bool{}, showCollapsed: false, isLast: false}} |
| 65 | for currentRow := 0; len(paramsToVisit) > 0 && currentRow <= stopRow; currentRow++ { |
| 66 | // pop the first node |
| 67 | var currentParams renderParams |
| 68 | currentParams, paramsToVisit = paramsToVisit[0], paramsToVisit[1:] |
| 69 | |
| 70 | // take note of the next nodes to visit later |
| 71 | sorter := GetSortOrderStrategy(tree.SortOrder) |
| 72 | keys := sorter.orderKeys(currentParams.node.Children) |
| 73 | |
| 74 | var childParams = make([]renderParams, 0) |
| 75 | for idx, name := range keys { |
| 76 | child := currentParams.node.Children[name] |
| 77 | // don't visit this node... |
| 78 | if child.Data.ViewInfo.Hidden || currentParams.node.Data.ViewInfo.Collapsed { |
| 79 | continue |
| 80 | } |
| 81 | |
| 82 | // visit this node... |
| 83 | isLast := idx == (len(currentParams.node.Children) - 1) |
| 84 | showCollapsed := child.Data.ViewInfo.Collapsed && len(child.Children) > 0 |
| 85 | |
| 86 | // completely copy the reference slice |
| 87 | childSpaces := make([]bool, len(currentParams.childSpaces)) |
| 88 | copy(childSpaces, currentParams.childSpaces) |
| 89 | |
| 90 | if len(child.Children) > 0 && !child.Data.ViewInfo.Collapsed { |
| 91 | childSpaces = append(childSpaces, isLast) |
| 92 | } |
| 93 | |
| 94 | childParams = append(childParams, renderParams{ |
| 95 | node: child, |
| 96 | spaces: currentParams.childSpaces, |
| 97 | childSpaces: childSpaces, |
| 98 | showCollapsed: showCollapsed, |
| 99 | isLast: isLast, |
| 100 | }) |
| 101 | } |
| 102 | // keep the child nodes to visit later |
| 103 | paramsToVisit = append(childParams, paramsToVisit...) |
| 104 | |
| 105 | // never process the root node |
| 106 | if currentParams.node == tree.Root { |
| 107 | currentRow-- |
| 108 | continue |
| 109 | } |
| 110 | |
| 111 | // process the current node |
| 112 | if currentRow >= startRow && currentRow <= stopRow { |
| 113 | params = append(params, currentParams) |
| 114 | } |
| 115 | } |
no test coverage detected