-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbattery.go
More file actions
71 lines (62 loc) · 1.63 KB
/
Copy pathbattery.go
File metadata and controls
71 lines (62 loc) · 1.63 KB
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
package main
import (
"fmt"
"github.com/barista-run/barista/bar"
"github.com/barista-run/barista/base/click"
"github.com/barista-run/barista/colors"
"github.com/barista-run/barista/outputs"
"github.com/barista-run/barista/pango"
"github.com/barista-run/barista/modules/battery"
)
func outputBattery(i battery.Info) bar.Output {
if i.Status == battery.Disconnected || i.Status == battery.Unknown {
return nil
}
iconName := "battery"
if i.Status == battery.Charging {
iconName += "-charging"
}
tenth := i.RemainingPct() / 10
switch {
case tenth == 0:
iconName += "-outline"
case tenth < 10:
iconName += fmt.Sprintf("-%d0", tenth)
}
rem := i.RemainingTime()
out := outputs.Group()
// First segment will be used in summary mode.
batFirst := outputs.Pango(
pango.Icon("mdi-"+iconName).Color(colors.Scheme("color10")),
spacer,
pango.Textf("%d:%02d", int(rem.Hours()), int(rem.Minutes())%60),
).OnClick(click.Left(func() {
mainModalController.Toggle("battery")
}))
threshold(batFirst,
false,
i.RemainingPct() <= 10,
i.RemainingPct() <= 15,
i.RemainingPct() <= 25,
)
out.Append(batFirst)
// Others in detail mode.
out.Append(outputs.Pango(
pango.Icon("mdi-"+iconName),
spacer,
pango.Textf("%d%%", i.RemainingPct()),
spacer,
pango.Textf("(%d:%02d)", int(rem.Hours()), int(rem.Minutes())%60),
).OnClick(click.Left(func() {
mainModalController.Toggle("battery")
})))
out.Append(outputs.Pango(
pango.Textf("%4.1f/%4.1f", i.EnergyNow, i.EnergyFull),
pango.Text("Wh").Smaller(),
))
out.Append(outputs.Pango(
pango.Textf("% +6.2f", i.SignedPower()),
pango.Text("W").Smaller(),
))
return out
}