MCPcopy Index your code
hub / github.com/pterm/pterm / walkOverTree

Function walkOverTree

tree_printer.go:137–161  ·  view source on GitHub ↗

walkOverTree is a recursive function, which analyzes a TreePrinter and connects the items with specific characters. Returns TreePrinter as string.

(list []TreeNode, p TreePrinter, prefix string)

Source from the content-addressed store, hash-verified

135// which analyzes a TreePrinter and connects the items with specific characters.
136// Returns TreePrinter as string.
137func walkOverTree(list []TreeNode, p TreePrinter, prefix string) string {
138 var ret string
139 for i, item := range list {
140 if len(list) > i+1 { // if not last in list
141 if len(item.Children) == 0 { // if there are no children
142 ret += prefix + p.TreeStyle.Sprint(p.TopRightDownString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent) +
143 p.TextStyle.Sprint(item.Text) + "\n"
144 } else { // if there are children
145 ret += prefix + p.TreeStyle.Sprint(p.TopRightDownString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent-1) +
146 p.TreeStyle.Sprint(p.RightDownLeftString) + p.TextStyle.Sprint(item.Text) + "\n"
147 ret += walkOverTree(item.Children, p, prefix+p.TreeStyle.Sprint(p.VerticalString)+strings.Repeat(" ", p.Indent-1))
148 }
149 } else if len(list) == i+1 { // if last in list
150 if len(item.Children) == 0 { // if there are no children
151 ret += prefix + p.TreeStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent) +
152 p.TextStyle.Sprint(item.Text) + "\n"
153 } else { // if there are children
154 ret += prefix + p.TreeStyle.Sprint(p.TopRightCornerString) + strings.Repeat(p.TreeStyle.Sprint(p.HorizontalString), p.Indent-1) +
155 p.TreeStyle.Sprint(p.RightDownLeftString) + p.TextStyle.Sprint(item.Text) + "\n"
156 ret += walkOverTree(item.Children, p, prefix+strings.Repeat(" ", p.Indent))
157 }
158 }
159 }
160 return ret
161}

Callers 1

SrenderMethod · 0.85

Calls 1

SprintMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…