From d107621830c8120cead1b90346a2c811339155f5 Mon Sep 17 00:00:00 2001 From: sqshq Date: Sun, 2 Jun 2019 20:53:15 -0400 Subject: [PATCH] multiple cosmetic improvements --- component/runchart/grid.go | 24 ++---------------------- component/runchart/runchart.go | 2 +- data/item.go | 7 +++++-- data/sampler.go | 2 +- go.mod | 1 + go.sum | 2 ++ 6 files changed, 12 insertions(+), 26 deletions(-) diff --git a/component/runchart/grid.go b/component/runchart/grid.go index f758806..99ba77f 100644 --- a/component/runchart/grid.go +++ b/component/runchart/grid.go @@ -8,7 +8,7 @@ import ( "time" ) -const DefaultValueLength = 4 +const defaultValueLength = 4 type ChartGrid struct { timeRange TimeRange @@ -30,7 +30,7 @@ func (c *RunChart) newChartGrid() ChartGrid { valueExtrema: getLocalExtrema(c.lines, timeRange), linesCount: linesCount, maxTimeWidth: c.Inner.Max.X, - minTimeWidth: 0, + minTimeWidth: defaultValueLength, } } @@ -145,23 +145,3 @@ func getLocalExtrema(items []TimeLine, timeRange TimeRange) ValueExtrema { func (r *TimeRange) isInRange(time time.Time) bool { return time.After(r.min) && time.Before(r.max) } - -//func (c *RunChart) getMaxValueLength() int { -// -// maxValueLength := -1 -// -// for _, line := range c.lines { -// for _, point := range line.points { -// l := len(util.FormatValue(point.value, c.scale)) -// if l > maxValueLength { -// maxValueLength = l -// } -// } -// } -// -// if maxValueLength < 0 { -// return DefaultValueLength -// } -// -// return maxValueLength -//} diff --git a/component/runchart/runchart.go b/component/runchart/runchart.go index be02c36..9174015 100644 --- a/component/runchart/runchart.go +++ b/component/runchart/runchart.go @@ -137,9 +137,9 @@ func (c *RunChart) Draw(buffer *ui.Buffer) { c.Inner.Max.X, c.Inner.Max.Y-xAxisLabelsHeight-1, ) - c.renderAxes(buffer) c.renderLines(buffer, drawArea) c.renderLegend(buffer, drawArea) + c.renderAxes(buffer) component.RenderAlert(c.alert, c.Rectangle, buffer) c.mutex.Unlock() } diff --git a/data/item.go b/data/item.go index 07ab889..f9315dd 100644 --- a/data/item.go +++ b/data/item.go @@ -6,6 +6,7 @@ import ( "fmt" ui "github.com/gizak/termui/v3" "github.com/kr/pty" + "github.com/lunixbochs/vtclean" "github.com/sqshq/sampler/config" "io" "os" @@ -84,7 +85,9 @@ func (i *Item) executeCmd(variables []string, script string) (string, error) { return "", err } - return string(output), nil + result := vtclean.Clean(string(output), false) + + return result, nil } func (i *Item) initInteractiveShell(variables []string) error { @@ -151,7 +154,7 @@ await: for { select { case output := <-i.interactiveShell.Channel: - o := cleanupOutput(output) + o := vtclean.Clean(output, false) if len(o) > 0 && !strings.Contains(o, i.sampleScript) { builder.WriteString(o) builder.WriteString("\n") diff --git a/data/sampler.go b/data/sampler.go index a919d04..f0ec171 100644 --- a/data/sampler.go +++ b/data/sampler.go @@ -29,7 +29,7 @@ func NewSampler(consumer *Consumer, items []*Item, triggers []*Trigger, options go func() { for ; true; <-ticker.C { for _, item := range sampler.items { - sampler.sample(item, options) + go sampler.sample(item, options) } } }() diff --git a/go.mod b/go.mod index b087f31..7f4d186 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/hajimehoshi/oto v0.1.1 github.com/jessevdk/go-flags v1.4.0 github.com/kr/pty v1.1.4 + github.com/lunixbochs/vtclean v1.0.0 github.com/mattn/go-runewidth v0.0.4 github.com/mbndr/figlet4go v0.0.0-20190224160619-d6cef5b186ea github.com/mitchellh/go-wordwrap v1.0.0 // indirect diff --git a/go.sum b/go.sum index 221e9f1..d7336f0 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGAR github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/kr/pty v1.1.4 h1:5Myjjh3JY/NaAi4IsUbHADytDyl1VE1Y9PXDlL+P/VQ= github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/lunixbochs/vtclean v1.0.0 h1:xu2sLAri4lGiovBDQKxl5mrXyESr3gUr5m5SM5+LVb8= +github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.4 h1:2BvfKmzob6Bmd4YsL0zygOqfdFnK7GR4QL06Do4/p7Y= github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=