-
Notifications
You must be signed in to change notification settings - Fork 1
/
doric.go
54 lines (48 loc) · 1.33 KB
/
doric.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package doric
import (
"github.com/i582/cfmt/cmd/cfmt"
"github.com/pandich/couture/model"
"github.com/pandich/couture/sink"
"github.com/pandich/couture/sink/doric/column"
"github.com/pandich/couture/source"
)
const sinkName = "doric"
// doricSink provides render output.
type doricSink struct {
terminalWidth uint
table *column.Table
config sink.Config
out chan string
}
// New provides a configured doricSink sink.
func New(config sink.Config) sink.Sink {
return &doricSink{
terminalWidth: config.EffectiveTerminalWidth(),
table: column.NewTable(config),
config: config,
out: sink.NewOut(sinkName, config.Out),
}
}
// Init ...
func (snk doricSink) Init(sources []*source.Source) {
switch {
case snk.config.Color != nil && !*snk.config.Color:
cfmt.DisableColors()
case snk.config.EffectiveIsTTY():
cfmt.EnableColors()
default:
cfmt.DisableColors()
}
var sourceColors = map[model.SourceURL]string{}
for _, src := range sources {
consistentColors := *snk.config.ConsistentColors
style := snk.config.Theme.AsHexPair(consistentColors, *src)
sourceColors[(*src).URL()] = style.Bg
column.RegisterSourceStyle(style, snk.config.Layout.Source, *src)
}
}
// Accept ...
func (snk doricSink) Accept(event model.SinkEvent) error {
snk.out <- snk.table.Render(event)
return nil
}