From 1dc53518afea556bb5247fbf364913d818d39285 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 2 Jun 2018 04:35:12 +0000 Subject: [PATCH] gim: draw the text of the edge --- gim/line.go | 10 ++++++++++ gim/main.go | 6 ++++++ gim/view.go | 1 + 3 files changed, 17 insertions(+) diff --git a/gim/line.go b/gim/line.go index ce38938..9538688 100644 --- a/gim/line.go +++ b/gim/line.go @@ -42,6 +42,7 @@ var arrows = map[geo.XY]string{ type line struct { from, to *box fromI, toI int + body string } // given the "primary" direction the line should be headed, picks a possible @@ -68,6 +69,7 @@ func (l line) draw(term *terminal.Terminal, flowDir, secFlowDir geo.XY) { return xy[1] } + // collect the points along the line into an array var pts []geo.XY midPrim := along(mid, flowDir) endSec := along(end, dirSec) @@ -82,6 +84,7 @@ func (l line) draw(term *terminal.Terminal, flowDir, secFlowDir geo.XY) { curr = curr.Add(flowDir) } + // draw each point for i, pt := range pts { var str string switch { @@ -100,4 +103,11 @@ func (l line) draw(term *terminal.Terminal, flowDir, secFlowDir geo.XY) { term.MoveCursorTo(pt) term.Printf(str) } + + // draw the body + if l.body != "" { + bodyPos := mid.Add(geo.Left.Scale(len(l.body) / 2)) + term.MoveCursorTo(bodyPos) + term.Printf(l.body) + } } diff --git a/gim/main.go b/gim/main.go index b7be93b..345a976 100644 --- a/gim/main.go +++ b/gim/main.go @@ -63,6 +63,12 @@ func mkGraph() (*gg.Graph, gg.Value) { gg.ValueOut(b3, empty), }, gg.NewValue("jE")) g = g.AddValueIn(jE, c) + + // TODO this really fucks it up + //d := gg.NewValue("d") + //deE := gg.ValueOut(d, gg.NewValue("deE")) + //g = g.AddValueIn(deE, gg.NewValue("e")) + return g, c } diff --git a/gim/view.go b/gim/view.go index b3a95a1..2e66269 100644 --- a/gim/view.go +++ b/gim/view.go @@ -181,6 +181,7 @@ func (view *view) draw(term *terminal.Terminal) { fromI: fromI, to: b, toI: i, + body: e.Value.V.(string), }) } }