-
Notifications
You must be signed in to change notification settings - Fork 0
/
lemonbar.go
88 lines (83 loc) · 2.34 KB
/
lemonbar.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
type lemonbarFormatter struct {
before, after string
}
var bareSingleton formatter
func NewLemonbarFormatter() formatter {
f := new(lemonbarFormatter)
f.after = ""
f.before = ""
return f
}
func (f *lemonbarFormatter) wrapOuter(before, after string) formatter {
wrapped := f.clone()
wrapped.before = before + f.before
wrapped.after = f.after + after
return wrapped
}
func (f *lemonbarFormatter) wrapInner(before, after string) formatter {
wrapped := f.clone()
wrapped.before = f.before + before
wrapped.after = after + f.after
return wrapped
}
func (f *lemonbarFormatter) WrapFgColor(color string) formatter {
return f.wrapOuter("%{F"+color+"}", "%{F-}")
}
func (f *lemonbarFormatter) WrapBgColor(color string) formatter {
return f.wrapOuter("%{B"+color+"}", "%{B-}")
}
func (f *lemonbarFormatter) AlignLeft() formatter {
return f.wrapInner("%{l}", "")
}
func (f *lemonbarFormatter) AlignRight() formatter {
return f.wrapInner("%{r}", "")
}
func (f *lemonbarFormatter) AlignCenter() formatter {
return f.wrapInner("%{c}", "")
}
func (f *lemonbarFormatter) WrapUnderlineColor(color string) formatter {
return f.wrapOuter("%{U"+color+"}", "%{U-}")
}
func (f *lemonbarFormatter) WrapUnderline() formatter {
return f.wrapOuter("%{+u}", "%{-u}")
}
func (f *lemonbarFormatter) WrapOverline() formatter {
return f.wrapOuter("%{+o}", "%{-o}")
}
func (f *lemonbarFormatter) WrapBold() formatter {
return f
}
func (f *lemonbarFormatter) SetMonitor(monitor string) formatter {
return f.wrapOuter("%{S"+monitor+"}", "")
}
func (f *lemonbarFormatter) GetDefaultColor() string {
return "-"
}
func (f *lemonbarFormatter) AppendInner(text string) formatter {
return f.wrapInner("", text)
}
func (f *lemonbarFormatter) PrependInner(text string) formatter {
return f.wrapInner(text, "")
}
func (f *lemonbarFormatter) AppendOuter(text string) formatter {
return f.wrapOuter("", text)
}
func (f *lemonbarFormatter) PrependOuter(text string) formatter {
return f.wrapOuter(text, "")
}
func (f *lemonbarFormatter) clone() *lemonbarFormatter {
clone := new(lemonbarFormatter)
clone.before = f.before
clone.after = f.after
return clone
}
func (f *lemonbarFormatter) Bare() formatter {
if bareSingleton == nil {
bareSingleton = NewLemonbarFormatter()
}
return bareSingleton
}
func (f *lemonbarFormatter) Format(text string) string {
return f.before + text + f.after
}