-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysinfo.go
101 lines (83 loc) · 2.08 KB
/
sysinfo.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
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"time"
"github.com/barista-run/barista/bar"
"github.com/barista-run/barista/base/click"
"github.com/barista-run/barista/colors"
"github.com/barista-run/barista/format"
"github.com/barista-run/barista/outputs"
"github.com/barista-run/barista/pango"
"github.com/barista-run/barista/modules/meminfo"
"github.com/barista-run/barista/modules/sysinfo"
"github.com/martinlindhe/unit"
)
func outputLoadAvg(s sysinfo.Info) bar.Output {
out := outputs.Group()
loadFirst := outputs.Pango(
pango.Icon("mdi-cpu-64-bit").Color(colors.Scheme("color10")),
spacer,
pango.Textf("%0.2f", s.Loads[0]),
).OnClick(click.Left(func() {
mainModalController.Toggle("cpu")
}))
// Load averages are unusually high for a few minutes after boot.
// so don't add colours until 10 minutes after system start.
if s.Uptime > 10*time.Minute {
threshold(loadFirst,
false,
s.Loads[0] > 128 || s.Loads[2] > 64,
s.Loads[0] > 64 || s.Loads[2] > 32,
s.Loads[0] > 32 || s.Loads[2] > 16,
false,
)
}
out.Append(loadFirst)
// Others in detail mode
out.Append(outputs.Pango(
pango.Textf("%0.2f %0.2f", s.Loads[1], s.Loads[2]).Smaller(),
))
return out
}
// Free memory
func outputFreeMem(m meminfo.Info) bar.Output {
out := outputs.Pango(
pango.Icon("mdi-memory").Color(colors.Scheme("color10")),
spacer,
format.IBytesize(m.Available()),
)
freeGigs := m.Available().Gigabytes()
threshold(out,
false,
freeGigs < 0.5,
freeGigs < 1,
freeGigs < 2,
)
out.OnClick(click.Left(func() {
mainModalController.Toggle("mem")
}))
return out
}
// Swap memory
func outputSwapMem(m meminfo.Info) bar.Output {
return outputs.Pango(
pango.Icon("mdi-swap-horizontal"),
spacer,
format.IBytesize(m["SwapTotal"]-m["SwapFree"]),
spacer,
pango.Textf("(%2.0f%%)", (1-m.FreeFrac("Swap"))*100.0).Small(),
)
}
func outputTemp(temp unit.Temperature) bar.Output {
out := outputs.Pango(
pango.Icon("mdi-fan"),
spacer,
pango.Textf("%2d℃", int(temp.Celsius())),
)
threshold(out,
false,
temp.Celsius() > 90,
temp.Celsius() > 70,
temp.Celsius() > 60,
)
return out
}