added alerter to all components

This commit is contained in:
sqshq 2019-03-12 23:19:19 -04:00
parent cf68e2a654
commit ff24a2d64e
3 changed files with 15 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package asciibox
import (
fl "github.com/mbndr/figlet4go"
"github.com/sqshq/sampler/asset"
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/config"
"github.com/sqshq/sampler/data"
ui "github.com/sqshq/termui"
@ -12,6 +13,7 @@ import (
type AsciiBox struct {
ui.Block
data.Consumer
*component.Alerter
text string
ascii string
style ui.Style
@ -23,6 +25,7 @@ const asciiFontExtension = ".flf"
func NewAsciiBox(c config.AsciiBoxConfig) *AsciiBox {
consumer := data.NewConsumer()
block := *ui.NewBlock()
block.Title = c.Title
@ -38,7 +41,8 @@ func NewAsciiBox(c config.AsciiBoxConfig) *AsciiBox {
box := AsciiBox{
Block: block,
Consumer: data.NewConsumer(),
Consumer: consumer,
Alerter: component.NewAlerter(consumer.AlertChannel),
style: ui.NewStyle(*c.Color),
render: render,
options: options,

View File

@ -3,6 +3,7 @@ package barchart
import (
"fmt"
rw "github.com/mattn/go-runewidth"
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
ui "github.com/sqshq/termui"
@ -18,6 +19,7 @@ const (
type BarChart struct {
ui.Block
data.Consumer
*component.Alerter
bars []Bar
scale int
maxValue float64
@ -32,11 +34,13 @@ type Bar struct {
}
func NewBarChart(title string, scale int) *BarChart {
consumer := data.NewConsumer()
block := *ui.NewBlock()
block.Title = title
chart := BarChart{
Block: block,
Consumer: data.NewConsumer(),
Consumer: consumer,
Alerter: component.NewAlerter(consumer.AlertChannel),
bars: []Bar{},
scale: scale,
maxValue: -math.MaxFloat64,

View File

@ -2,6 +2,7 @@ package gauge
import (
"fmt"
"github.com/sqshq/sampler/component"
"github.com/sqshq/sampler/console"
"github.com/sqshq/sampler/data"
ui "github.com/sqshq/termui"
@ -19,6 +20,7 @@ const (
type Gauge struct {
ui.Block
data.Consumer
*component.Alerter
minValue float64
maxValue float64
curValue float64
@ -27,13 +29,13 @@ type Gauge struct {
}
func NewGauge(title string, scale int, color ui.Color) *Gauge {
consumer := data.NewConsumer()
block := *ui.NewBlock()
block.Title = title
gauge := Gauge{
Block: block,
Consumer: data.NewConsumer(),
Consumer: consumer,
Alerter: component.NewAlerter(consumer.AlertChannel),
scale: scale,
color: color,
}