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
( d
, p
) {
30 d = bar_make_status_energy_direction
()
31 p = bar_make_status_energy_percent
()
32 return sprintf("E%s%d%%", d
, p
)
35 function bar_make_status_energy_percent
( charge
) {
36 cache_get
(charge
, "khatus_sensor_energy", "battery_percentage", 0)
37 return charge
["value"]
40 function bar_make_status_energy_direction
( state
, direction_of_change
) {
41 cache_get
(state
, "khatus_sensor_energy", "battery_state", 0)
42 if (state
["value"] ==
"discharging") {
43 direction_of_change =
"<"
44 } else if (state
["value"] ==
"charging") {
45 direction_of_change =
">"
47 direction_of_change =
"="
49 return direction_of_change
52 # -----------------------------------------------------------------------------
54 # -----------------------------------------------------------------------------
56 function bar_make_status_mem
() {
57 return sprintf("M=%s%%", bar_make_status_mem_percent
())
60 function bar_make_status_mem_percent
( total
, used
, percent
, percent_str
) {
61 cache_get
(total
, "khatus_sensor_memory", "total", 5)
62 cache_get
(used
, "khatus_sensor_memory", "used" , 5)
63 # Checking total["value"] to avoid division by zero when data is missing
64 if (!total
["is_expired"] && \
65 !used
["is_expired"] && \
68 percent = util_round
((used
["value"] / total
["value"]) * 100)
69 percent_str =
sprintf("%d", percent
)
76 # -----------------------------------------------------------------------------
78 # -----------------------------------------------------------------------------
80 function bar_make_status_procs
() {
82 # D uninterruptible sleep (usually IO)
83 # R running or runnable (on run queue)
84 # S interruptible sleep (waiting for an event to complete)
85 # T stopped by job control signal
86 # t stopped by debugger during the tracing
87 # W paging (not valid since the 2.6.xx kernel)
88 # X dead (should never be seen)
89 # Z defunct ("zombie") process, terminated but not reaped by its parent
91 # Additionally, not documented in ps man page:
94 all = bar_make_status_procs_count_all
()
95 r = bar_make_status_procs_count_r
()
96 d = bar_make_status_procs_count_d
()
97 t = bar_make_status_procs_count_t
()
98 i = bar_make_status_procs_count_i
()
99 z = bar_make_status_procs_count_z
()
100 return sprintf("P=[%s %sr %sd %st %si %sz]", all
, r
, d
, t
, i
, z
)
103 function bar_make_status_procs_count_all
() {
104 return cache_get_fmt_def
("khatus_sensor_procs", "total_procs", 15, "%d")
107 function bar_make_status_procs_count_r
( src
) {
108 src =
"khatus_sensor_procs"
109 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"R", 15, "%d", "0")
112 function bar_make_status_procs_count_d
( src
) {
113 src =
"khatus_sensor_procs"
114 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"D", 15, "%d", "0")
117 function bar_make_status_procs_count_t
( src
) {
118 src =
"khatus_sensor_procs"
119 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"T", 15, "%d", "0")
122 function bar_make_status_procs_count_i
( src
) {
123 src =
"khatus_sensor_procs"
124 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"I", 15, "%d", "0")
127 function bar_make_status_procs_count_z
( src
) {
128 src =
"khatus_sensor_procs"
129 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"Z", 15, "%d", "0")
132 # -----------------------------------------------------------------------------
134 # -----------------------------------------------------------------------------
136 function bar_make_status_cpu
( l
, t
, f
) {
137 l = bar_make_status_cpu_loadavg
()
138 t = bar_make_status_cpu_temperature
()
139 f = bar_make_status_cpu_fan_speed
()
140 return sprintf("C=[%s %s°C %srpm]", l
, t
, f
)
143 function bar_make_status_cpu_loadavg
( src
) {
144 src =
"khatus_sensor_loadavg"
145 return cache_get_fmt_def
(src
, "load_avg_1min", 5, "%4.2f")
148 function bar_make_status_cpu_temperature
() {
149 return cache_get_fmt_def
("khatus_sensor_temperature", "temp_c", 5, "%d")
152 function bar_make_status_cpu_fan_speed
() {
153 return cache_get_fmt_def
("khatus_sensor_fan", "speed", 5, "%4d")
156 # -----------------------------------------------------------------------------
158 # -----------------------------------------------------------------------------
160 function bar_make_status_disk
( u
, w
, r
) {
161 u = bar_make_status_disk_space
()
162 w = bar_make_status_disk_io_w
()
163 r = bar_make_status_disk_io_r
()
164 return sprintf("D=[%s%% %s▲ %s▼]", u
, w
, r
)
167 function bar_make_status_disk_space
( src
) {
168 src =
"khatus_sensor_disk_space"
169 return cache_get_fmt_def
(src
, "disk_usage_percentage", 10, "%s")
172 function bar_make_status_disk_io_w
( src
) {
173 src =
"khatus_sensor_disk_io"
174 return cache_get_fmt_def
(src
, "sectors_written", 5, "%0.3f")
177 function bar_make_status_disk_io_r
( src
) {
178 src =
"khatus_sensor_disk_io"
179 return cache_get_fmt_def
(src
, "sectors_read", 5, "%0.3f")
182 # -----------------------------------------------------------------------------
184 # -----------------------------------------------------------------------------
186 function bar_make_status_net
( \
187 number_of_net_interfaces_to_show
, \
188 net_interfaces_to_show
, \
198 number_of_net_interfaces_to_show = \
199 split(Opt_Net_Interfaces_To_Show
, net_interfaces_to_show
, ",")
202 for (i = number_of_net_interfaces_to_show
; i
> 0; i
--) {
203 interface = net_interfaces_to_show
[i
]
204 label =
substr(interface
, 1, 1)
205 if (interface ~
"^w") {
206 label = label
":" bar_make_status_net_wifi
(interface
)
208 addr = bar_make_status_net_addr
(interface
)
209 w = bar_make_status_net_io_w
(interface
)
210 r = bar_make_status_net_io_r
(interface
)
211 out = out sep label
":" sprintf("%s▲ %s▼", w
, r
)
214 return sprintf("N[%s]", out
)
217 function bar_make_status_net_addr
(interface
, src
) {
218 src =
"khatus_sensor_net_addr_io"
219 return cache_get_fmt_def
(src
, "addr" Kfs interface
, 5, "%s", "")
222 function bar_make_status_net_io_w
(interface
, src
) {
223 src =
"khatus_sensor_net_addr_io"
224 return cache_get_fmt_def
(src
, "bytes_written" Kfs interface
, 5, "%0.3f")
227 function bar_make_status_net_io_r
(interface
, src
) {
228 src =
"khatus_sensor_net_addr_io"
229 return cache_get_fmt_def
(src
, "bytes_read" Kfs interface
, 5, "%0.3f")
232 function bar_make_status_net_wifi
(interface
, src
) {
233 src =
"khatus_sensor_net_wifi_status"
234 return cache_get_fmt_def
(src
, "status" Kfs interface
, 10, "%s")
237 # -----------------------------------------------------------------------------
239 # -----------------------------------------------------------------------------
241 function bar_make_status_bluetooth
() {
242 return sprintf("B=%s", bar_make_status_bluetooth_power
())
245 function bar_make_status_bluetooth_power
( src
) {
246 src =
"khatus_sensor_bluetooth_power"
247 return cache_get_fmt_def
(src
, "power_status", 10, "%s")
250 # -----------------------------------------------------------------------------
252 # -----------------------------------------------------------------------------
254 function bar_make_status_screen_brightness
() {
255 return sprintf("*%s%%", bar_make_status_backlight_percent
())
258 function bar_make_status_backlight_percent
( src
) {
259 src =
"khatus_sensor_screen_brightness"
260 return cache_get_fmt_def
(src
, "percentage", 5, "%d")
263 # -----------------------------------------------------------------------------
265 # -----------------------------------------------------------------------------
267 function bar_make_status_volume
() {
268 return sprintf("(%s)", bar_make_status_volume_value
())
271 # TODO: better name than "bar_make_status_volume_value" ... :)
272 function bar_make_status_volume_value
( sink
, mu
, vl
, vr
, show
) {
273 sink = Opt_Pulseaudio_Sink
274 cache_get
(mu
, "khatus_sensor_volume", "mute" Kfs sink
, 5)
275 cache_get
(vl
, "khatus_sensor_volume", "vol_left" Kfs sink
, 5)
276 cache_get
(vr
, "khatus_sensor_volume", "vol_right" Kfs sink
, 5)
278 if (!mu
["is_expired"] && !vl
["is_expired"] && !vr
["is_expired"]) {
279 if (mu
["value"] ==
"yes") {show =
"X"}
280 else if (mu
["value"] ==
"no") {show = vl
["value"] " " vr
["value"]}
283 "bar_make_status_volume", \
284 "Unexpected value for 'mute' field: " mu
["value"] \
291 # -----------------------------------------------------------------------------
293 # -----------------------------------------------------------------------------
295 function bar_make_status_mpd
() {
296 return sprintf("[%s]", bar_make_status_mpd_value
())
299 function bar_make_status_mpd_value
( state
, status
) {
300 cache_get
(state
, "khatus_sensor_mpd", "state", 5)
301 if (!state
["is_expired"] && state
["value"]) {
302 if (state
["value"] ==
"play") {
303 status = bar_make_status_mpd_state_known
("▶")
304 } else if (state
["value"] ==
"pause") {
305 status = bar_make_status_mpd_state_known
("❚❚")
306 } else if (state
["value"] ==
"stop") {
307 status = bar_make_status_mpd_state_known
("⬛")
310 "bar_make_status_mpd", \
311 "Unexpected value for 'state' field: " state
["value"] \
321 function bar_make_status_mpd_state_known
(symbol
, s
, song
, time
, percentage
) {
322 s =
"khatus_sensor_mpd"
323 song = cache_get_fmt_def
(s
, "song" , 5, "%s", "?")
324 time = cache_get_fmt_def
(s
, "play_time_minimal_units", 5, "%s", "?")
325 percent = cache_get_fmt_def
(s
, "play_time_percentage" , 5, "%s", "?")
326 song =
substr(song
, 1, Opt_Mpd_Song_Max_Chars
)
327 return sprintf("%s %s %s %s", symbol
, time
, percent
, song
)
330 # -----------------------------------------------------------------------------
332 # -----------------------------------------------------------------------------
334 function bar_make_status_weather
() {
335 return sprintf("%s°F", bar_make_status_weather_temp_f
())
338 function bar_make_status_weather_temp_f
( src
, hour
) {
339 src =
"khatus_sensor_weather"
341 return cache_get_fmt_def
(src
, "temperature_f", 3 * hour
, "%d")
344 # -----------------------------------------------------------------------------
346 # -----------------------------------------------------------------------------
348 function bar_make_status_datetime
( dt
) {
349 return cache_get_fmt_def
("khatus_sensor_datetime", "datetime", 5, "%s")