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 msg
["type"] ==
"data" {
19 cache_update
(msg
["node"], msg
["module"], msg
["key"], msg
["val"])
22 msg
["node"] == Node
&& \
23 msg
["module"] ==
"khatus_sensor_datetime" && \
24 msg
["type"] ==
"data" {
25 # Code for bar_make_status is expected to be passed as an
26 # additional source file, using -f flag.
27 msg_out_status_bar
(bar_make_status
())
30 # -----------------------------------------------------------------------------
32 # -----------------------------------------------------------------------------
34 function bar_make_status_energy_percent
() {
35 return cache_get_fmt_def
("khatus_sensor_energy", "battery_percentage", 0, "%d")
38 function bar_make_status_energy_direction
( state
, direction_of_change
) {
39 cache_get
(state
, "khatus_sensor_energy", "battery_state", 0)
40 if (state
["value"] ==
"discharging") {
41 direction_of_change =
"<"
42 } else if (state
["value"] ==
"charging") {
43 direction_of_change =
">"
45 direction_of_change =
"="
47 return direction_of_change
50 # -----------------------------------------------------------------------------
52 # -----------------------------------------------------------------------------
54 function bar_make_status_mem_percent
( total
, used
, percent
, percent_str
) {
55 cache_get
(total
, "khatus_sensor_memory", "total", 5)
56 cache_get
(used
, "khatus_sensor_memory", "used" , 5)
57 # Checking total["value"] to avoid division by zero when data is missing
58 if (!total
["is_expired"] && \
59 !used
["is_expired"] && \
62 percent = num_round
((used
["value"] / total
["value"]) * 100)
63 percent_str =
sprintf("%d", percent
)
70 # -----------------------------------------------------------------------------
72 # -----------------------------------------------------------------------------
74 # D uninterruptible sleep (usually IO)
75 # R running or runnable (on run queue)
76 # S interruptible sleep (waiting for an event to complete)
77 # T stopped by job control signal
78 # t stopped by debugger during the tracing
79 # W paging (not valid since the 2.6.xx kernel)
80 # X dead (should never be seen)
81 # Z defunct ("zombie") process, terminated but not reaped by its parent
83 # Additionally, not documented in ps man page:
86 function bar_make_status_procs_count_all
() {
87 return cache_get_fmt_def
("khatus_sensor_procs", "total_procs", 15, "%d")
90 function bar_make_status_procs_count_r
( src
) {
91 src =
"khatus_sensor_procs"
92 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"R", 15, "%d", "0")
95 function bar_make_status_procs_count_d
( src
) {
96 src =
"khatus_sensor_procs"
97 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"D", 15, "%d", "0")
100 function bar_make_status_procs_count_t
( src
) {
101 src =
"khatus_sensor_procs"
102 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"T", 15, "%d", "0")
105 function bar_make_status_procs_count_i
( src
) {
106 src =
"khatus_sensor_procs"
107 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"I", 15, "%d", "0")
110 function bar_make_status_procs_count_z
( src
) {
111 src =
"khatus_sensor_procs"
112 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"Z", 15, "%d", "0")
115 # -----------------------------------------------------------------------------
117 # -----------------------------------------------------------------------------
119 function bar_make_status_cpu_loadavg
( src
) {
120 src =
"khatus_sensor_loadavg"
121 return cache_get_fmt_def
(src
, "load_avg_1min", 5, "%4.2f")
124 function bar_make_status_cpu_temperature
() {
125 return cache_get_fmt_def
("khatus_sensor_temperature", "temp_c", 5, "%d")
128 function bar_make_status_cpu_fan_speed
() {
129 return cache_get_fmt_def
("khatus_sensor_fan", "speed", 5, "%4d")
132 # -----------------------------------------------------------------------------
134 # -----------------------------------------------------------------------------
136 function bar_make_status_disk_space
( src
) {
137 src =
"khatus_sensor_disk_space"
138 return cache_get_fmt_def
(src
, "disk_usage_percentage", 10, "%s")
141 function bar_make_status_disk_io_w
( src
) {
142 src =
"khatus_sensor_disk_io"
143 return cache_get_fmt_def
(src
, "sectors_written", 5, "%0.3f")
146 function bar_make_status_disk_io_r
( src
) {
147 src =
"khatus_sensor_disk_io"
148 return cache_get_fmt_def
(src
, "sectors_read", 5, "%0.3f")
151 # -----------------------------------------------------------------------------
153 # -----------------------------------------------------------------------------
155 function bar_make_status_net_addr
(interface
, src
) {
156 src =
"khatus_sensor_net_addr_io"
157 return cache_get_fmt_def
(src
, "addr" Kfs interface
, 5, "%s", "")
160 function bar_make_status_net_io_w
(interface
, src
) {
161 src =
"khatus_sensor_net_addr_io"
162 return cache_get_fmt_def
(src
, "bytes_written" Kfs interface
, 5, "%0.3f")
165 function bar_make_status_net_io_r
(interface
, src
) {
166 src =
"khatus_sensor_net_addr_io"
167 return cache_get_fmt_def
(src
, "bytes_read" Kfs interface
, 5, "%0.3f")
170 function bar_make_status_net_wifi
(interface
, src
) {
171 src =
"khatus_sensor_net_wifi_status"
172 return cache_get_fmt_def
(src
, "status" Kfs interface
, 10, "%s")
175 # -----------------------------------------------------------------------------
177 # -----------------------------------------------------------------------------
179 function bar_make_status_bluetooth_power
( src
) {
180 src =
"khatus_sensor_bluetooth_power"
181 return cache_get_fmt_def
(src
, "power_status", 10, "%s")
184 # -----------------------------------------------------------------------------
185 # Backlight (screen brightness)
186 # -----------------------------------------------------------------------------
188 function bar_make_status_backlight_percent
( src
) {
189 src =
"khatus_sensor_screen_brightness"
190 return cache_get_fmt_def
(src
, "percentage", 5, "%d")
193 # -----------------------------------------------------------------------------
195 # -----------------------------------------------------------------------------
197 function bar_make_status_volume_alsa_device
(device
, mu
, vl
, vr
, show
) {
198 cache_get
(mu
, "khatus_sensor_volume", "mute" Kfs device
, 5)
199 cache_get
(vl
, "khatus_sensor_volume", "vol_left" Kfs device
, 5)
200 cache_get
(vr
, "khatus_sensor_volume", "vol_right" Kfs device
, 5)
202 if (!mu
["is_expired"] && !vl
["is_expired"] && !vr
["is_expired"]) {
203 if (mu
["value"] ==
"yes") {show =
"X"}
204 else if (mu
["value"] ==
"no") {show = vl
["value"] " " vr
["value"]}
207 "bar_make_status_volume_alsa_device: " device
". ", \
208 "Unexpected value for 'mute' field: " mu
["value"] \
215 # -----------------------------------------------------------------------------
217 # -----------------------------------------------------------------------------
219 function bar_make_status_mpd
( state
, status
) {
220 cache_get
(state
, "khatus_sensor_mpd", "state", 5)
221 if (!state
["is_expired"] && state
["value"]) {
222 if (state
["value"] ==
"play") {
223 status = bar_make_status_mpd_state_known
("▶")
224 } else if (state
["value"] ==
"pause") {
225 status = bar_make_status_mpd_state_known
("❚❚")
226 } else if (state
["value"] ==
"stop") {
227 status = bar_make_status_mpd_state_known
("⬛")
230 "bar_make_status_mpd", \
231 "Unexpected value for 'state' field: " state
["value"] \
241 function bar_make_status_mpd_state_known
(symbol
, s
, song
, time
, percentage
) {
242 s =
"khatus_sensor_mpd"
243 song = cache_get_fmt_def
(s
, "song" , 5, "%s", "?")
244 time = cache_get_fmt_def
(s
, "play_time_minimal_units", 5, "%s", "?")
245 percent = cache_get_fmt_def
(s
, "play_time_percentage" , 5, "%s", "?")
246 song =
substr(song
, 1, Opt_Mpd_Song_Max_Chars
)
247 return sprintf("%s %s %s %s", symbol
, time
, percent
, song
)
250 # -----------------------------------------------------------------------------
252 # -----------------------------------------------------------------------------
254 function bar_make_status_weather_temp_f
( src
, hour
) {
255 src =
"khatus_sensor_weather"
257 return cache_get_fmt_def
(src
, "temperature_f", 3 * hour
, "%d")
260 # -----------------------------------------------------------------------------
262 # -----------------------------------------------------------------------------
264 function bar_make_status_datetime
( dt
) {
265 return cache_get_fmt_def
("khatus_sensor_datetime", "datetime", 5, "%s")