pipes draws the "| | |" pipes prefix. path is a slice of indexes leading to the current node. For example, the path [1, 3, 2] says that the current node is the 2nd child of the 3rd child of the 1st child of the root. last is the last "|" component in this grouping; it'll normally be "| " or "+- "
(path []int, last string)
| 233 | // Note that for cases where path[1] == 0, |
| 234 | // we don't draw a pipe if len(path) > 2. |
| 235 | func (p *treeWriter) pipes(path []int, last string) { |
| 236 | for depth, idx := range path { |
| 237 | if depth == len(path)-1 { |
| 238 | p.writeString(last) |
| 239 | } else if idx == 0 { |
| 240 | // First child of the parent at this layer. |
| 241 | // Nothing to connect to above us. |
| 242 | p.writeString(" ") |
| 243 | } else { |
| 244 | p.writeString("| ") |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | func (p *treeWriter) writeString(s string) { |
| 250 | _, err := io.WriteString(p.W, s) |