-
Notifications
You must be signed in to change notification settings - Fork 3
/
transport_console_box_flags.go
58 lines (49 loc) · 1.75 KB
/
transport_console_box_flags.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
55
56
57
58
package bitflow
import (
"flag"
"fmt"
"time"
"github.com/antongulenko/golib/gotermBox"
)
const ConsoleBoxEndpoint = EndpointType("box")
var (
ConsoleBoxSettings = gotermBox.CliLogBox{
NoUtf8: false,
LogLines: 10,
MessageBuffer: 500,
}
ConsoleBoxUpdateInterval = 500 * time.Millisecond
ConsoleBoxMinUpdateInterval = 50 * time.Millisecond
// console_box_testMode is a flag used by tests to suppress initialization routines
// that are not testable. It is a hack to keep the EndpointFactory easy to use
// while making it testable.
console_box_testMode bool
)
func RegisterConsoleBoxOutput(e *EndpointFactory) {
var factory consoleBoxFactory
e.CustomDataSinks[ConsoleBoxEndpoint] = factory.createConsoleBox
e.CustomOutputFlags = append(e.CustomOutputFlags, factory.registerFlags)
}
type consoleBoxFactory struct {
ConsoleBoxNoImmediateScreenUpdate bool
}
func (factory *consoleBoxFactory) registerFlags(f *flag.FlagSet) {
f.BoolVar(&factory.ConsoleBoxNoImmediateScreenUpdate, "slow-screen-updates", false, fmt.Sprintf("For console box output, don't update the screen on every sample, but only in intervals of %v", ConsoleBoxUpdateInterval))
}
func (factory *consoleBoxFactory) createConsoleBox(target string) (SampleProcessor, error) {
if target != stdTransportTarget {
return nil, fmt.Errorf("Transport '%v' can only be defined with target '%v'", ConsoleBoxEndpoint, stdTransportTarget)
}
sink := &ConsoleBoxSink{
CliLogBoxTask: gotermBox.CliLogBoxTask{
CliLogBox: ConsoleBoxSettings,
UpdateInterval: ConsoleBoxUpdateInterval,
MinUpdateInterval: ConsoleBoxMinUpdateInterval,
},
ImmediateScreenUpdate: !factory.ConsoleBoxNoImmediateScreenUpdate,
}
if !console_box_testMode {
sink.Init()
}
return sink, nil
}