-
Notifications
You must be signed in to change notification settings - Fork 23
/
irtt_print.go
56 lines (45 loc) · 838 Bytes
/
irtt_print.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
package irtt
import (
"bufio"
"fmt"
"io"
"os"
"text/tabwriter"
)
var printTo io.Writer = os.Stdout
type flusher interface {
Flush() error
}
func printf(format string, args ...interface{}) {
fmt.Fprintf(printTo, fmt.Sprintf("%s\n", format), args...)
}
func println(s string) {
fmt.Fprintln(printTo, s)
}
func setTabWriter(flags uint) {
printTo = tabwriter.NewWriter(printTo, 0, 0, 2, ' ', flags)
}
func setBufio() {
printTo = bufio.NewWriter(printTo)
}
func flush() {
if f, ok := printTo.(flusher); ok {
f.Flush()
}
}
func exitOnError(err error, code int) {
if err != nil {
printTo = os.Stderr
if _, ok := err.(*Error); ok {
printf("%s", err)
} else {
printf("Error: %s", err)
}
os.Exit(code)
}
}
type consoleHandler struct {
}
func (h *consoleHandler) OnEvent(e *Event) {
println(e.String())
}