3 # - global, builtin : ALLCAPS
4 # - global, public : Camel_Snake_Man_Bear_Pig
5 # - global, private : _snake_case_prefixed_underscore
8 # - global, public : snake_case
10 # -----------------------------------------------------------------------------
12 # -----------------------------------------------------------------------------
18 $
2 ==
"khatus_sensor_datetime" {
19 # Code for bar_make_status is expected to be passed as an
20 # additional source file, using -f flag.
21 msg_out_ok
("status_bar", bar_make_status
())
25 # -----------------------------------------------------------------------------
27 # -----------------------------------------------------------------------------
29 function bar_make_status_energy
( state
, charge
, direction_of_change
) {
30 cache_get
(state
, "khatus_sensor_energy", "battery_state" , 0)
31 cache_get
(charge
, "khatus_sensor_energy", "battery_percentage", 0)
33 if (state
["value"] ==
"discharging") {
34 direction_of_change =
"<"
35 } else if (state
["value"] ==
"charging") {
36 direction_of_change =
">"
38 direction_of_change =
"="
41 return sprintf("E%s%d%%", direction_of_change
, charge
["value"])
44 function bar_make_status_mem
( total
, used
, percent
, status
) {
45 cache_get
(total
, "khatus_sensor_memory", "total", 5)
46 cache_get
(used
, "khatus_sensor_memory", "used" , 5)
47 # Checking total["value"] to avoid division by zero when data is missing
48 if (!total
["is_expired"] && \
49 !used
["is_expired"] && \
52 percent = util_round
((used
["value"] / total
["value"]) * 100)
53 status =
sprintf("%d%%", percent
)
57 return sprintf("M=%s", status
)
60 function bar_make_status_procs
() {
62 # D uninterruptible sleep (usually IO)
63 # R running or runnable (on run queue)
64 # S interruptible sleep (waiting for an event to complete)
65 # T stopped by job control signal
66 # t stopped by debugger during the tracing
67 # W paging (not valid since the 2.6.xx kernel)
68 # X dead (should never be seen)
69 # Z defunct ("zombie") process, terminated but not reaped by its parent
71 # Additionally, not documented in ps man page:
74 src =
"khatus_sensor_procs"
75 all = cache_get_fmt_def
(src
, "total_procs" , 15, "%d")
76 r = cache_get_fmt_def
(src
, "total_per_state" Kfs
"R", 15, "%d", "0")
77 d = cache_get_fmt_def
(src
, "total_per_state" Kfs
"D", 15, "%d", "0")
78 t = cache_get_fmt_def
(src
, "total_per_state" Kfs
"T", 15, "%d", "0")
79 i = cache_get_fmt_def
(src
, "total_per_state" Kfs
"I", 15, "%d", "0")
80 z = cache_get_fmt_def
(src
, "total_per_state" Kfs
"Z", 15, "%d", "0")
81 return sprintf("P=[%s %sr %sd %st %si %sz]", all
, r
, d
, t
, i
, z
)
84 function bar_make_status_cpu
( l
, t
, f
) {
85 l_src =
"khatus_sensor_loadavg"
86 t_src =
"khatus_sensor_temperature"
87 f_src =
"khatus_sensor_fan"
88 l = cache_get_fmt_def
(l_src
, "load_avg_1min", 5, "%4.2f")
89 t = cache_get_fmt_def
(t_src
, "temp_c" , 5, "%d" )
90 f = cache_get_fmt_def
(f_src
, "speed" , 5, "%4d" )
91 return sprintf("C=[%s %s°C %srpm]", l
, t
, f
)
94 function bar_make_status_disk
( u
, w
, r
, src_u
, src_io
) {
95 src_u =
"khatus_sensor_disk_space"
96 src_io =
"khatus_sensor_disk_io"
97 u = cache_get_fmt_def
(src_u
, "disk_usage_percentage", 10, "%s")
98 w = cache_get_fmt_def
(src_io
, "sectors_written" , 5, "%0.3f")
99 r = cache_get_fmt_def
(src_io
, "sectors_read" , 5, "%0.3f")
100 return sprintf("D=[%s%% %s▲ %s▼]", u
, w
, r
)
103 function bar_make_status_net
( \
104 number_of_net_interfaces_to_show
, \
105 net_interfaces_to_show
, \
119 number_of_net_interfaces_to_show = \
120 split(Opt_Net_Interfaces_To_Show
, net_interfaces_to_show
, ",")
121 io =
"khatus_sensor_net_addr_io"
122 wi =
"khatus_sensor_net_wifi_status"
125 for (i = number_of_net_interfaces_to_show
; i
> 0; i
--) {
126 interface = net_interfaces_to_show
[i
]
127 label =
substr(interface
, 1, 1)
128 if (interface ~
"^w") {
129 wifi = cache_get_fmt_def
(wi
, "status" Kfs interface
, 10, "%s")
130 label = label
":" wifi
132 addr = cache_get_fmt_def
(io
, "addr" Kfs interface
, 5, "%s", "")
133 w = cache_get_fmt_def
(io
, "bytes_written" Kfs interface
, 5, "%0.3f")
134 r = cache_get_fmt_def
(io
, "bytes_read" Kfs interface
, 5, "%0.3f")
135 io_stat = addr ?
sprintf("%s▲ %s▼", w
, r
) : "--"
136 out = out sep label
":" io_stat
139 return sprintf("N[%s]", out
)
142 function bar_make_status_bluetooth
( src
, key
) {
143 src =
"khatus_sensor_bluetooth_power"
145 return sprintf("B=%s", cache_get_fmt_def
(src
, key
, 10, "%s"))
148 function bar_make_status_screen_brightness
( src
, key
) {
149 src =
"khatus_sensor_screen_brightness"
151 return sprintf("*%s%%", cache_get_fmt_def
(src
, key
, 5, "%d"))
154 function bar_make_status_volume
( sink
, mu
, vl
, vr
, show
) {
155 sink = Opt_Pulseaudio_Sink
156 cache_get
(mu
, "khatus_sensor_volume", "mute" Kfs sink
, 5)
157 cache_get
(vl
, "khatus_sensor_volume", "vol_left" Kfs sink
, 5)
158 cache_get
(vr
, "khatus_sensor_volume", "vol_right" Kfs sink
, 5)
160 if (!mu
["is_expired"] && !vl
["is_expired"] && !vr
["is_expired"]) {
161 if (mu
["value"] ==
"yes") {show =
"X"}
162 else if (mu
["value"] ==
"no") {show = vl
["value"] " " vr
["value"]}
165 "bar_make_status_volume", \
166 "Unexpected value for 'mute' field: " mu
["value"] \
170 return sprintf("(%s)", show
)
173 function bar_make_status_mpd
( state
, status
) {
174 cache_get
(state
, "khatus_sensor_mpd", "state", 5)
175 if (!state
["is_expired"] && state
["value"]) {
176 if (state
["value"] ==
"play") {
177 status = bar_make_status_mpd_state_known
("▶")
178 } else if (state
["value"] ==
"pause") {
179 status = bar_make_status_mpd_state_known
("❚❚")
180 } else if (state
["value"] ==
"stop") {
181 status = bar_make_status_mpd_state_known
("⬛")
184 "bar_make_status_mpd", \
185 "Unexpected value for 'state' field: " state
["value"] \
193 return sprintf("[%s]", status
)
196 function bar_make_status_mpd_state_known
(symbol
, s
, song
, time
, percentage
) {
197 s =
"khatus_sensor_mpd"
198 song = cache_get_fmt_def
(s
, "song" , 5, "%s", "?")
199 time = cache_get_fmt_def
(s
, "play_time_minimal_units", 5, "%s", "?")
200 percent = cache_get_fmt_def
(s
, "play_time_percentage" , 5, "%s", "?")
201 song =
substr(song
, 1, Opt_Mpd_Song_Max_Chars
)
202 return sprintf("%s %s %s %s", symbol
, time
, percent
, song
)
205 function bar_make_status_weather
( src
, hour
, t_f
) {
206 src =
"khatus_sensor_weather"
208 t_f = cache_get_fmt_def
(src
, "temperature_f", 3 * hour
, "%d")
209 return sprintf("%s°F", t_f
)
212 function bar_make_status_datetime
( dt
) {
213 return cache_get_fmt_def
("khatus_sensor_datetime", "datetime", 5, "%s")