From 8c5ba869dc68126abd70f64a29ddd3e3538cb4f0 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Fri, 9 Jul 2021 15:14:09 -0400 Subject: [PATCH] Initial commit --- main.go | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..72718b5 --- /dev/null +++ b/main.go @@ -0,0 +1,77 @@ +package cp437tree + +import ( + "fmt" + "io" +) + +const ( + VerticalRight = "├" + DownLeft = "┐" + UpRight = "└" + DownRight = "┌" + Horizontal ="─" + Vertical = "│" +) + +/* +┌┐ // HeaderTop +├┐ // HeaderMid +│├ // ItemMid +│└ // ItemBottom +└┐ // HeaderBottom + └── //ItemEndBottom +*/ + +type Node struct { + Text string + Children *[]Node +} + + +func (o *Request) ToTreeGroup(w io.Writer, position rune) { + middle := "├──┐" // default middle branch + midRow := "│ ├── " + botRow := "│ └── " + topBranch := "┌──┐" + endBranch := "└──┐" + veryBottomRow := " └── " + + rowChars := "" + if position == 't' { + branch = topBranch + } + if position == 'b' { + branch = endBranch + } + + // platform name header + rowChars = midRow + // preparing the children variable so this whole thing can be extracted later. + children := o.Versions + childCount := len(children) - 1 + for idx, v := range children { + if idx == childCount { + rowChars = botRow + if position == 'b' { + rowChars = veryBottomRow + } + } + _, _ = fmt.Fprintf(w, "\n%s%s", rowChars, v) + } + + // new line to end the row + _, _ = fmt.Fprintf(w, "\n") +} + +func idToPosition(id, count int) rune { + // Returns 't' for top, 'b' for bottom, and 'm', for middle by comparing the idx to the count of rows. + // Does not account for if count = 1 + if id == 0 { + return 't' + } + if id == count-1 { + return 'b' + } + return 'm' +} \ No newline at end of file