-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathutils.go
51 lines (41 loc) · 891 Bytes
/
utils.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
// (c) 2011-2014 Alexander Solovyov
// under terms of ISC License
package main
import (
"fmt"
"github.com/wsxiaoys/terminal/color"
)
type Printer struct {
NoColors bool
NoGroup bool
previous string
}
func (p *Printer) Printf(colorfmt, plainfmt string,
args ...interface{}) {
if p.NoColors {
fmt.Printf(plainfmt, args...)
} else {
color.Printf(colorfmt, args...)
}
}
func (p *Printer) Sprintf(colorfmt, plainfmt string,
args ...interface{}) string {
if p.NoColors {
return fmt.Sprintf(plainfmt, args...)
} else {
return color.Sprintf(colorfmt, args...)
}
}
func (p *Printer) FilePrintf(fn, colorfmt, plainfmt string,
args ...interface{}) {
if p.NoGroup {
p.Printf("@g%s:", "%s:", fn)
} else if fn != p.previous {
if p.previous != "" {
fmt.Println("")
}
p.Printf("@g%s\n", "%s\n", fn)
p.previous = fn
}
p.Printf(colorfmt, plainfmt, args...)
}