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 # -----------------------------------------------------------------------------
16 cache_update
(msg
["node"], msg
["module"], msg
["key"], msg
["val"])
20 $
2 ==
"khatus_sensor_datetime" && \
22 # Code for bar_make_status is expected to be passed as an
23 # additional source file, using -f flag.
24 msg_out_status_bar
(bar_make_status
())
27 # -----------------------------------------------------------------------------
29 # -----------------------------------------------------------------------------
31 function bar_make_status_energy_percent
() {
32 return cache_get_fmt_def
("khatus_sensor_energy", "battery_percentage", 0, "%d")
35 function bar_make_status_energy_direction
( state
, direction_of_change
) {
36 cache_get
(state
, "khatus_sensor_energy", "battery_state", 0)
37 if (state
["value"] ==
"discharging") {
38 direction_of_change =
"<"
39 } else if (state
["value"] ==
"charging") {
40 direction_of_change =
">"
42 direction_of_change =
"="
44 return direction_of_change
47 # -----------------------------------------------------------------------------
49 # -----------------------------------------------------------------------------
51 function bar_make_status_mem_percent
( total
, used
, percent
, percent_str
) {
52 cache_get
(total
, "khatus_sensor_memory", "total", 5)
53 cache_get
(used
, "khatus_sensor_memory", "used" , 5)
54 # Checking total["value"] to avoid division by zero when data is missing
55 if (!total
["is_expired"] && \
56 !used
["is_expired"] && \
59 percent = num_round
((used
["value"] / total
["value"]) * 100)
60 percent_str =
sprintf("%d", percent
)
67 # -----------------------------------------------------------------------------
69 # -----------------------------------------------------------------------------
71 # D uninterruptible sleep (usually IO)
72 # R running or runnable (on run queue)
73 # S interruptible sleep (waiting for an event to complete)
74 # T stopped by job control signal
75 # t stopped by debugger during the tracing
76 # W paging (not valid since the 2.6.xx kernel)
77 # X dead (should never be seen)
78 # Z defunct ("zombie") process, terminated but not reaped by its parent
80 # Additionally, not documented in ps man page:
83 function bar_make_status_procs_count_all
() {
84 return cache_get_fmt_def
("khatus_sensor_procs", "total_procs", 15, "%d")
87 function bar_make_status_procs_count_r
( src
) {
88 src =
"khatus_sensor_procs"
89 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"R", 15, "%d", "0")
92 function bar_make_status_procs_count_d
( src
) {
93 src =
"khatus_sensor_procs"
94 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"D", 15, "%d", "0")
97 function bar_make_status_procs_count_t
( src
) {
98 src =
"khatus_sensor_procs"
99 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"T", 15, "%d", "0")
102 function bar_make_status_procs_count_i
( src
) {
103 src =
"khatus_sensor_procs"
104 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"I", 15, "%d", "0")
107 function bar_make_status_procs_count_z
( src
) {
108 src =
"khatus_sensor_procs"
109 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"Z", 15, "%d", "0")
112 # -----------------------------------------------------------------------------
114 # -----------------------------------------------------------------------------
116 function bar_make_status_cpu_loadavg
( src
) {
117 src =
"khatus_sensor_loadavg"
118 return cache_get_fmt_def
(src
, "load_avg_1min", 5, "%4.2f")
121 function bar_make_status_cpu_temperature
() {
122 return cache_get_fmt_def
("khatus_sensor_temperature", "temp_c", 5, "%d")
125 function bar_make_status_cpu_fan_speed
() {
126 return cache_get_fmt_def
("khatus_sensor_fan", "speed", 5, "%4d")
129 # -----------------------------------------------------------------------------
131 # -----------------------------------------------------------------------------
133 function bar_make_status_disk_space
( src
) {
134 src =
"khatus_sensor_disk_space"
135 return cache_get_fmt_def
(src
, "disk_usage_percentage", 10, "%s")
138 function bar_make_status_disk_io_w
( src
) {
139 src =
"khatus_sensor_disk_io"
140 return cache_get_fmt_def
(src
, "sectors_written", 5, "%0.3f")
143 function bar_make_status_disk_io_r
( src
) {
144 src =
"khatus_sensor_disk_io"
145 return cache_get_fmt_def
(src
, "sectors_read", 5, "%0.3f")
148 # -----------------------------------------------------------------------------
150 # -----------------------------------------------------------------------------
152 function bar_make_status_net_addr
(interface
, src
) {
153 src =
"khatus_sensor_net_addr_io"
154 return cache_get_fmt_def
(src
, "addr" Kfs interface
, 5, "%s", "")
157 function bar_make_status_net_io_w
(interface
, src
) {
158 src =
"khatus_sensor_net_addr_io"
159 return cache_get_fmt_def
(src
, "bytes_written" Kfs interface
, 5, "%0.3f")
162 function bar_make_status_net_io_r
(interface
, src
) {
163 src =
"khatus_sensor_net_addr_io"
164 return cache_get_fmt_def
(src
, "bytes_read" Kfs interface
, 5, "%0.3f")
167 function bar_make_status_net_wifi
(interface
, src
) {
168 src =
"khatus_sensor_net_wifi_status"
169 return cache_get_fmt_def
(src
, "status" Kfs interface
, 10, "%s")
172 # -----------------------------------------------------------------------------
174 # -----------------------------------------------------------------------------
176 function bar_make_status_bluetooth_power
( src
) {
177 src =
"khatus_sensor_bluetooth_power"
178 return cache_get_fmt_def
(src
, "power_status", 10, "%s")
181 # -----------------------------------------------------------------------------
182 # Backlight (screen brightness)
183 # -----------------------------------------------------------------------------
185 function bar_make_status_backlight_percent
( src
) {
186 src =
"khatus_sensor_screen_brightness"
187 return cache_get_fmt_def
(src
, "percentage", 5, "%d")
190 # -----------------------------------------------------------------------------
192 # -----------------------------------------------------------------------------
194 function bar_make_status_volume_pulseaudio_sink
(sink
, mu
, vl
, vr
, show
) {
195 cache_get
(mu
, "khatus_sensor_volume", "mute" Kfs sink
, 5)
196 cache_get
(vl
, "khatus_sensor_volume", "vol_left" Kfs sink
, 5)
197 cache_get
(vr
, "khatus_sensor_volume", "vol_right" Kfs sink
, 5)
199 if (!mu
["is_expired"] && !vl
["is_expired"] && !vr
["is_expired"]) {
200 if (mu
["value"] ==
"yes") {show =
"X"}
201 else if (mu
["value"] ==
"no") {show = vl
["value"] " " vr
["value"]}
204 "bar_make_status_volume_pulseaudio_sink: " sink
". ", \
205 "Unexpected value for 'mute' field: " mu
["value"] \
212 # -----------------------------------------------------------------------------
214 # -----------------------------------------------------------------------------
216 function bar_make_status_mpd
( state
, status
) {
217 cache_get
(state
, "khatus_sensor_mpd", "state", 5)
218 if (!state
["is_expired"] && state
["value"]) {
219 if (state
["value"] ==
"play") {
220 status = bar_make_status_mpd_state_known
("▶")
221 } else if (state
["value"] ==
"pause") {
222 status = bar_make_status_mpd_state_known
("❚❚")
223 } else if (state
["value"] ==
"stop") {
224 status = bar_make_status_mpd_state_known
("⬛")
227 "bar_make_status_mpd", \
228 "Unexpected value for 'state' field: " state
["value"] \
238 function bar_make_status_mpd_state_known
(symbol
, s
, song
, time
, percentage
) {
239 s =
"khatus_sensor_mpd"
240 song = cache_get_fmt_def
(s
, "song" , 5, "%s", "?")
241 time = cache_get_fmt_def
(s
, "play_time_minimal_units", 5, "%s", "?")
242 percent = cache_get_fmt_def
(s
, "play_time_percentage" , 5, "%s", "?")
243 song =
substr(song
, 1, Opt_Mpd_Song_Max_Chars
)
244 return sprintf("%s %s %s %s", symbol
, time
, percent
, song
)
247 # -----------------------------------------------------------------------------
249 # -----------------------------------------------------------------------------
251 function bar_make_status_weather_temp_f
( src
, hour
) {
252 src =
"khatus_sensor_weather"
254 return cache_get_fmt_def
(src
, "temperature_f", 3 * hour
, "%d")
257 # -----------------------------------------------------------------------------
259 # -----------------------------------------------------------------------------
261 function bar_make_status_datetime
( dt
) {
262 return cache_get_fmt_def
("khatus_sensor_datetime", "datetime", 5, "%s")