Compare commits

...

17 Commits

Author SHA1 Message Date
bee2189ae5 work: add Amsterdam time 2025-03-05 17:20:08 -08:00
3b2c74c01e Add UTC time to work clock 2025-01-23 12:30:43 -08:00
b21a06b622 Address lint 2024-08-27 11:43:46 -07:00
4fcbf23210 Show current volume level, disable London time on work 2024-08-27 11:42:24 -07:00
b124148b0b Only show power levels for battery powered things 2024-08-27 11:31:33 -07:00
b9935c991f Make network device filtering a regex.
Work and home have different naming schemes.
2023-07-31 07:53:11 -07:00
f51bbf62d9 Merge branch 'master' of https://git.z.xinu.tv/wathiede/i3xs 2023-07-30 14:06:55 -07:00
376db0eeb4 Add disk R/W stats 2023-07-30 14:06:39 -07:00
ee79a10968 Add disk R/W stats 2023-07-30 14:06:06 -07:00
2bce347cd5 Replace NetworkSpeedWidget with new AllNetworkSpeedWidget. 2023-07-30 13:34:33 -07:00
44c0c21018 Add AllNetworkSpeedWidget to show any usage on enp devices 2023-07-30 13:32:18 -07:00
fefc331dbc cargo update 2023-07-30 10:48:05 -07:00
d0f08bfa1b Add readme 2023-05-06 10:36:16 -07:00
4819128bda Cleanup lint 2023-05-06 07:46:50 -07:00
ed997b4ba6 cargo upgrade 2023-05-06 07:44:48 -07:00
292b80b17a cargo update 2023-05-06 07:43:33 -07:00
793f1f63e9 power: set color when battery power low. 2021-12-12 11:24:58 -08:00
12 changed files with 722 additions and 211 deletions

475
Cargo.lock generated
View File

@@ -4,9 +4,9 @@ version = 3
[[package]]
name = "aho-corasick"
version = "0.7.6"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
dependencies = [
"memchr",
]
@@ -33,10 +33,25 @@ dependencies = [
]
[[package]]
name = "autocfg"
version = "0.1.6"
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
@@ -46,21 +61,27 @@ checksum = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
[[package]]
name = "bitflags"
version = "1.1.0"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
name = "cc"
version = "1.0.45"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc9a35e1f4290eb9e5fc54ba6cf40671ed2a2514c3eeb2b2a908dda2ea5a1be"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cfg-if"
version = "0.1.9"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
@@ -74,42 +95,51 @@ dependencies = [
[[package]]
name = "chrono"
version = "0.4.9"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8493056968583b0193c1bb04d6f7684586f3726992d6c573261941a895dbd68"
checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
dependencies = [
"libc",
"num-integer",
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"time",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "chrono-tz"
version = "0.5.1"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0e430fad0384e4defc3dc6b1223d1b886087a8bf9b7080e5ae027f73851ea15"
checksum = "2554a3155fec064362507487171dcc4edc3df60cb10f3a1fb10ed8094822b120"
dependencies = [
"chrono 0.4.9",
"chrono 0.4.26",
"parse-zoneinfo",
]
[[package]]
name = "clap"
version = "2.33.0"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"bitflags 1.1.0",
"bitflags 1.3.2",
"textwrap",
"unicode-width",
]
[[package]]
name = "curl"
version = "0.4.24"
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d08ad3cb89d076a36b0ce5749eec2c9964f70c0c58480ab6b75a91ec4fc206d8"
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
[[package]]
name = "curl"
version = "0.4.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22"
dependencies = [
"curl-sys",
"libc",
@@ -122,9 +152,9 @@ dependencies = [
[[package]]
name = "curl-sys"
version = "0.4.21"
version = "0.4.65+curl-8.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "520594da9914c1dc77ce3be450fc1c74fde67c82966d80f8e93c6d460eb0e9ae"
checksum = "961ba061c9ef2fe34bbd12b807152d96f0badd2bebe7b90ce6c8c8b7572a0986"
dependencies = [
"cc",
"libc",
@@ -137,23 +167,29 @@ dependencies = [
[[package]]
name = "glob"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "heck"
version = "0.3.1"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b"
[[package]]
name = "i3monkit"
version = "0.1.2"
source = "git+https://github.com/38/i3monkit#d72d94d103b2621ebfc06c9950d3bba9613e4936"
source = "git+https://github.com/38/i3monkit#7fefa91faf039c4ee53106565cea5edc0b68f840"
dependencies = [
"alsa",
"chrono 0.3.0",
@@ -167,38 +203,65 @@ dependencies = [
name = "i3xs"
version = "0.1.0"
dependencies = [
"chrono 0.4.9",
"chrono 0.4.26",
"chrono-tz",
"glob",
"i3monkit",
"num_cpus",
"regex",
"structopt",
"thiserror",
]
[[package]]
name = "itoa"
version = "0.4.4"
name = "iana-time-zone"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f"
checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows",
]
[[package]]
name = "lazy_static"
version = "1.4.0"
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "itoa"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "js-sys"
version = "0.3.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.62"
version = "0.2.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
name = "libz-sys"
version = "1.0.25"
version = "1.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe"
checksum = "d97137b25e321a73eef1418d1d5d2eda4d77e12813f8e6dead84bc52c5870a7b"
dependencies = [
"cc",
"libc",
@@ -207,10 +270,16 @@ dependencies = [
]
[[package]]
name = "memchr"
version = "2.2.1"
name = "log"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
[[package]]
name = "memchr"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "num"
@@ -225,9 +294,9 @@ dependencies = [
[[package]]
name = "num-integer"
version = "0.1.41"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
@@ -235,9 +304,9 @@ dependencies = [
[[package]]
name = "num-iter"
version = "0.1.39"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76bd5272412d173d6bf9afdf98db8612bbabc9a7a830b7bfc9c188911716132e"
checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252"
dependencies = [
"autocfg",
"num-integer",
@@ -246,35 +315,41 @@ dependencies = [
[[package]]
name = "num-traits"
version = "0.2.8"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32"
checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.10.1"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "openssl-probe"
version = "0.1.2"
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "openssl-probe"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-sys"
version = "0.9.49"
version = "0.9.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4fad9e54bd23bd4cbbe48fdc08a1b8091707ac869ef8508edea2fec77dcc884"
checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6"
dependencies = [
"autocfg",
"cc",
"libc",
"pkg-config",
@@ -283,18 +358,18 @@ dependencies = [
[[package]]
name = "parse-zoneinfo"
version = "0.2.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "089a398ccdcdd77b8c38909d5a1e4b67da1bc4c9dbfe6d5b536c828eddb779e5"
checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
dependencies = [
"regex",
]
[[package]]
name = "pkg-config"
version = "0.3.16"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72d5370d90f49f70bd033c3d75e87fc529fbfff9d6f7cccef07d6170079d91ea"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
name = "proc-macro2"
@@ -302,16 +377,16 @@ version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
"unicode-xid",
]
[[package]]
name = "proc-macro2"
version = "1.0.33"
version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a"
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
dependencies = [
"unicode-xid 0.2.0",
"unicode-ident",
]
[[package]]
@@ -325,78 +400,82 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
dependencies = [
"proc-macro2 1.0.33",
"proc-macro2 1.0.66",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
name = "regex"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
checksum = "b2eae68fc220f7cf2532e4494aded17545fce192d59cd996e0fe7887f4ceb575"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex"
version = "1.3.1"
name = "regex-automata"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc220bd33bdce8f093101afe22a037b8eb0e5af33592e6a9caafff0d4cb81cbd"
checksum = "b7b6d6190b7594385f61bd3911cd1be99dfddcfc365a4160cc2ab5bff4aed294"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
"thread_local",
]
[[package]]
name = "regex-syntax"
version = "0.6.12"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716"
checksum = "e5ea92a5b6195c6ef2a0295ea818b312502c6fc94dde986c5553242e18fd4ce2"
[[package]]
name = "ryu"
version = "1.0.0"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c92464b447c0ee8c4fb3824ecc8383b81717b9f1e74ba2e72540aef7b9f82997"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "schannel"
version = "0.1.16"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f550b06b6cba9c8b8be3ee73f391990116bf527450d2556e9b9ce263b9a021"
checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88"
dependencies = [
"lazy_static",
"winapi",
"windows-sys",
]
[[package]]
name = "serde"
version = "1.0.101"
version = "1.0.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd"
checksum = "60363bdd39a7be0266a520dab25fdc9241d2f987b08a01e01f0ec6d06a981348"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.101"
version = "1.0.178"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e"
checksum = "f28482318d6641454cb273da158647922d1be6b5a2fcc6165cd89ebdd7ed576b"
dependencies = [
"proc-macro2 1.0.33",
"quote 1.0.2",
"syn 1.0.82",
"proc-macro2 1.0.66",
"quote 1.0.32",
"syn 2.0.27",
]
[[package]]
name = "serde_json"
version = "1.0.40"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051c49229f282f7c6f3813f8286cc1e3323e8051823fce42c7ea80fe13521704"
checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
dependencies = [
"itoa",
"ryu",
@@ -405,13 +484,11 @@ dependencies = [
[[package]]
name = "socket2"
version = "0.3.11"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85"
checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"winapi",
]
@@ -445,18 +522,18 @@ checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
"unicode-xid",
]
[[package]]
name = "syn"
version = "1.0.82"
version = "2.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
checksum = "b60f673f44a8255b9c8c657daf66a596d435f2da81a555b06dc644d080ba45e0"
dependencies = [
"proc-macro2 1.0.33",
"quote 1.0.2",
"unicode-xid 0.2.0",
"proc-macro2 1.0.66",
"quote 1.0.32",
"unicode-ident",
]
[[package]]
@@ -470,55 +547,52 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.30"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96"
dependencies = [
"proc-macro2 1.0.33",
"quote 1.0.2",
"syn 1.0.82",
]
[[package]]
name = "thread_local"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
dependencies = [
"lazy_static",
"proc-macro2 1.0.66",
"quote 1.0.32",
"syn 2.0.27",
]
[[package]]
name = "time"
version = "0.1.42"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a"
dependencies = [
"libc",
"redox_syscall",
"wasi",
"winapi",
]
[[package]]
name = "unicode-segmentation"
version = "1.3.0"
name = "unicode-ident"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9"
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.6"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20"
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
[[package]]
name = "unicode-xid"
@@ -527,22 +601,76 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.0"
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "vcpkg"
version = "0.2.7"
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasm-bindgen"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2 1.0.66",
"quote 1.0.32",
"syn 2.0.27",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d"
dependencies = [
"quote 1.0.32",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b"
dependencies = [
"proc-macro2 1.0.66",
"quote 1.0.32",
"syn 2.0.27",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.87"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1"
[[package]]
name = "winapi"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
@@ -559,3 +687,78 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3"
[[package]]
name = "windows_i686_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241"
[[package]]
name = "windows_i686_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"

View File

@@ -21,9 +21,10 @@ path = "src/bin/home.rs"
[dependencies]
# Use git until ColorRGB is pub in crates
i3monkit = {git = "https://github.com/38/i3monkit"} # "0.1.2"
num_cpus = "1.0"
num_cpus = "1.15"
structopt = { version = "0.2", default-features = false }
chrono = "0.4"
chrono-tz = "0.5"
glob = "0.3.0"
thiserror = "1.0.30"
glob = "0.3.1"
thiserror = "1.0.40"
regex = "1.9.1"

10
README.md Normal file
View File

@@ -0,0 +1,10 @@
# Dev instructions
```
# Run a test nested X server with dimensions tuned for i3 status bar work
$ Xephyr :1 -screen 1280x200 &
# Run i3 with a custome socket directory so you don't clash with any
# preexisting ones.
# TODO(wathiede): write stripped down i3 config and use it
$ I3SOCK=/tmp/i3 DISPLAY=:1 i3
```

View File

@@ -1,40 +1,42 @@
use chrono::NaiveTime;
use i3monkit::{ColorRGB, Header, I3Protocol, WidgetCollection};
use i3monkit::{widgets::VolumeWidget, ColorRGB, Header, I3Protocol, WidgetCollection};
use i3xs::widgets::{
cpu::CpuWidget,
datetime::{DateTimeWidget, TimeColor},
disk::AllDiskSpeedWidget,
network::AllNetworkSpeedWidget,
power::PowerSupply,
};
use structopt::StructOpt;
use i3xs::widgets::cpu::CpuWidget;
use i3xs::widgets::datetime::{DateTimeWidget, TimeColor};
use i3xs::widgets::network::NetworkSpeedWidget;
use i3xs::widgets::power::PowerSupply;
#[derive(Debug, StructOpt)]
#[structopt(name = "i3xs", about = "Custom i3 status bar program.")]
struct Opt {
#[structopt(short, long)]
nic: String,
}
struct Opt {}
fn main() {
let mut bar = WidgetCollection::new();
let opts = Opt::from_args();
let _opts = Opt::from_args();
bar.push(PowerSupply::default());
bar.push(CpuWidget::default());
// Realtime upload/download rate for a interface
bar.push(NetworkSpeedWidget::new(&opts.nic, 6));
// Realtime upload/download rate for a any active NICs
bar.push(AllNetworkSpeedWidget::new(6));
// Realtime read/write rate for a any active disks
bar.push(AllDiskSpeedWidget::new(6));
bar.push(VolumeWidget::new("default", "Master", 0));
let mut dt = DateTimeWidget::new("%m/%d %H:%M");
dt.set_colors(vec![
TimeColor {
start: NaiveTime::from_hms(19, 0, 0),
start: NaiveTime::from_hms_opt(19, 0, 0).unwrap(),
color: ColorRGB::yellow(),
},
TimeColor {
start: NaiveTime::from_hms(20, 0, 0),
start: NaiveTime::from_hms_opt(20, 0, 0).unwrap(),
color: ColorRGB::red(),
},
]);

View File

@@ -1,73 +1,78 @@
use chrono::NaiveTime;
use i3monkit::{ColorRGB, Header, I3Protocol, WidgetCollection};
use i3monkit::{widgets::VolumeWidget, ColorRGB, Header, I3Protocol, WidgetCollection};
use i3xs::widgets::{
cpu::CpuWidget,
datetime::{DateTimeWidget, TimeColor},
disk::AllDiskSpeedWidget,
network::AllNetworkSpeedWidget,
power::PowerSupply,
};
use structopt::StructOpt;
use i3xs::widgets::cpu::CpuWidget;
use i3xs::widgets::datetime::{DateTimeWidget, TimeColor};
use i3xs::widgets::network::NetworkSpeedWidget;
use i3xs::widgets::power::PowerSupply;
#[derive(Debug, StructOpt)]
#[structopt(name = "i3xs", about = "Custom i3 status bar program.")]
struct Opt {
#[structopt(short, long)]
nic: String,
}
struct Opt {}
fn main() {
let mut bar = WidgetCollection::new();
let opts = Opt::from_args();
let _opts = Opt::from_args();
bar.push(PowerSupply::default());
bar.push(CpuWidget::default());
// Realtime upload/download rate for a interface
bar.push(NetworkSpeedWidget::new(&opts.nic, 6));
bar.push(AllNetworkSpeedWidget::new(6));
let mut dt = DateTimeWidget::tz("%H:%M %Z", chrono_tz::Europe::London);
// Realtime read/write rate for a any active disks
bar.push(AllDiskSpeedWidget::new(6));
// Setup time in Amsterdam widget with end of day warnings
let mut dt = DateTimeWidget::tz("%H:%M %Z", chrono_tz::Europe::Amsterdam);
dt.set_colors(vec![
TimeColor {
start: NaiveTime::from_hms(0, 0, 0),
start: NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
color: ColorRGB::red(),
},
TimeColor {
start: NaiveTime::from_hms(8, 0, 0),
start: NaiveTime::from_hms_opt(8, 0, 0).unwrap(),
color: ColorRGB(255, 255, 255),
},
TimeColor {
start: NaiveTime::from_hms(17, 0, 0),
start: NaiveTime::from_hms_opt(17, 0, 0).unwrap(),
color: ColorRGB::yellow(),
},
TimeColor {
start: NaiveTime::from_hms(18, 0, 0),
start: NaiveTime::from_hms_opt(18, 0, 0).unwrap(),
color: ColorRGB::red(),
},
]);
bar.push(dt);
bar.push(VolumeWidget::new("default", "Master", 0));
let mut dt = DateTimeWidget::new("%m/%d %H:%M");
dt.set_colors(vec![
TimeColor {
start: NaiveTime::from_hms(0, 0, 0),
start: NaiveTime::from_hms_opt(0, 0, 0).unwrap(),
color: ColorRGB::red(),
},
TimeColor {
start: NaiveTime::from_hms(7, 0, 0),
start: NaiveTime::from_hms_opt(7, 0, 0).unwrap(),
color: ColorRGB(255, 255, 255),
},
TimeColor {
start: NaiveTime::from_hms(15, 0, 0),
start: NaiveTime::from_hms_opt(15, 0, 0).unwrap(),
color: ColorRGB::yellow(),
},
TimeColor {
start: NaiveTime::from_hms(16, 0, 0),
start: NaiveTime::from_hms_opt(16, 0, 0).unwrap(),
color: ColorRGB::red(),
},
]);
bar.push(dt);
let dt_utc = DateTimeWidget::tz("UTC %H:%M", chrono::offset::Utc);
bar.push(dt_utc);
// Then start updating the status bar
bar.update_loop(I3Protocol::new(Header::new(1), std::io::stdout()));

15
src/colors.rs Normal file
View File

@@ -0,0 +1,15 @@
use i3monkit::ColorRGB;
pub const WHITE: ColorRGB = ColorRGB(255, 255, 255);
pub fn lerp(c1: ColorRGB, c2: ColorRGB, alpha: f32) -> ColorRGB {
ColorRGB(
(c1.0 as f32 * (1. - alpha) + c2.0 as f32 * alpha) as u8,
(c1.1 as f32 * (1. - alpha) + c2.1 as f32 * alpha) as u8,
(c1.2 as f32 * (1. - alpha) + c2.2 as f32 * alpha) as u8,
)
}
pub fn to_string(c: ColorRGB) -> String {
format!("#{:02x}{:02x}{:02x}", c.0, c.1, c.2)
}

View File

@@ -1,2 +1,3 @@
pub mod colors;
pub mod spark;
pub mod widgets;

View File

@@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader, Result};
use i3monkit::{Block, ColorRGB, Widget, WidgetUpdate};
use crate::spark;
use crate::{colors, spark};
#[derive(Debug)]
struct Stat {
@@ -20,18 +20,6 @@ pub struct CpuWidget {
history: Vec<VecDeque<f32>>,
}
fn color_lerp(c1: ColorRGB, c2: ColorRGB, alpha: f32) -> ColorRGB {
ColorRGB(
(c1.0 as f32 * (1. - alpha) + c2.0 as f32 * alpha) as u8,
(c1.1 as f32 * (1. - alpha) + c2.1 as f32 * alpha) as u8,
(c1.2 as f32 * (1. - alpha) + c2.2 as f32 * alpha) as u8,
)
}
fn color_to_string(c: ColorRGB) -> String {
format!("#{:02x}{:02x}{:02x}", c.0, c.1, c.2)
}
impl CpuWidget {
fn read_status() -> Result<Vec<Stat>> {
let file = File::open("/proc/stat")?;
@@ -92,10 +80,10 @@ impl CpuWidget {
.iter()
.zip(sg.chars())
.map(|(v, g)| {
let c = color_lerp(ColorRGB::green(), ColorRGB::red(), *v);
let c = colors::lerp(ColorRGB::green(), ColorRGB::red(), *v);
format!(
r##"<span foreground="{}">{}</span>"##,
color_to_string(c),
colors::to_string(c),
g
)
})

199
src/widgets/disk.rs Normal file
View File

@@ -0,0 +1,199 @@
use std::{collections::vec_deque::VecDeque, io::Result, time::SystemTime};
use i3monkit::{Block, Widget, WidgetUpdate};
use crate::spark;
const DISK_STATS_PAT: &str = "/sys/class/block/*/*/stat";
struct TransferStat {
rx: u64,
tx: u64,
ts: SystemTime,
}
impl TransferStat {
fn read_stat(stat_path: &str) -> Result<Self> {
// File format documented at https://www.kernel.org/doc/Documentation/block/stat.txt
let s = std::fs::read_to_string(stat_path)?;
let parts: Vec<_> = s.split(" ").filter(|s| !s.is_empty()).collect();
let rx = parts[2].parse().unwrap_or(0) * 512;
let tx = parts[6].parse().unwrap_or(0) * 512;
let ts = SystemTime::now();
Ok(Self { rx, tx, ts })
}
fn duration(&self, earlier: &Self) -> f64 {
let duration = self.ts.duration_since(earlier.ts).unwrap();
duration.as_secs() as f64 + duration.subsec_nanos() as f64 / 1_000_000_000.0
}
fn rx_rate(&self, earlier: &Self) -> f64 {
let duration = self.duration(earlier);
if duration < 1e-5 {
return std::f64::NAN;
}
(self.rx - earlier.rx) as f64 / duration
}
fn tx_rate(&self, earlier: &Self) -> f64 {
let duration = self.duration(earlier);
if duration < 1e-5 {
return std::f64::NAN;
}
(self.tx - earlier.tx) as f64 / duration
}
}
/// A widget that shows the disk R/W realtimely
pub struct DiskSpeedWidget {
device: String,
last_stat: TransferStat,
rx_history: VecDeque<f32>,
tx_history: VecDeque<f32>,
}
impl DiskSpeedWidget {
/// Create the widget, for given device.
///
/// **device** The interface to monitor
pub fn new(device: &str, num_samples: usize) -> Self {
let last_stat = TransferStat::read_stat(device).unwrap();
let device = device.to_string();
let rx_history: VecDeque<f32> = (0..num_samples).map(|_| 1.).collect();
let tx_history: VecDeque<f32> = (0..num_samples).map(|_| 1.).collect();
Self {
last_stat,
device,
rx_history,
tx_history,
}
}
fn is_active(&self) -> bool {
(self.rx_history.iter().sum::<f32>() + self.tx_history.iter().sum::<f32>()) > 0.
}
fn format_rate(rate: f64) -> String {
if rate.is_nan() {
return "N/A".to_string();
}
const UNIT_NAME: [&str; 6] = [" B/s", "KB/s", "MB/s", "GB/s", "TB/s", "PB/s"];
let mut best_unit = UNIT_NAME[0];
let mut best_multiplier = 1.0;
for unit in UNIT_NAME[1..].iter() {
if best_multiplier > rate / 1024.0 {
break;
}
best_unit = unit;
best_multiplier *= 1024.0
}
format!("{:6.1}{}", rate / best_multiplier, best_unit)
}
fn get_human_readable_stat(&mut self) -> Result<(String, String)> {
let cur_stat = TransferStat::read_stat(&self.device)?;
let rx_rate = cur_stat.rx_rate(&self.last_stat);
let tx_rate = cur_stat.tx_rate(&self.last_stat);
self.rx_history.push_back(rx_rate as f32);
self.rx_history.pop_front();
self.tx_history.push_back(tx_rate as f32);
self.tx_history.pop_front();
self.last_stat = cur_stat;
Ok((Self::format_rate(rx_rate), Self::format_rate(tx_rate)))
}
fn render(&mut self) -> Option<String> {
if let Ok((rx, tx)) = self.get_human_readable_stat() {
let (rx_history, tx_history) = if self.rx_history.len() > 1 {
let g = spark::Graph {
min: None,
max: None,
};
(
g.render(&self.rx_history.iter().cloned().collect::<Vec<f32>>()),
g.render(&self.tx_history.iter().cloned().collect::<Vec<f32>>()),
)
} else {
("".to_string(), "".to_string())
};
return Some(format!(
"R:<tt>{} {}</tt> W:<tt>{} {}</tt> ",
rx, rx_history, tx, tx_history
));
}
None
}
}
impl Widget for DiskSpeedWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
if let Some(text) = self.render() {
let mut data = Block::new();
data.use_pango();
data.append_full_text(&text);
return Some(WidgetUpdate {
refresh_interval: std::time::Duration::new(1, 0),
data: Some(data),
});
}
None
}
}
pub struct AllDiskSpeedWidget {
disks: Vec<DiskSpeedWidget>,
}
impl AllDiskSpeedWidget {
pub fn new(num_samples: usize) -> Self {
let disks = glob::glob(DISK_STATS_PAT)
.expect("couldn't find glob for disks")
.map(|path| {
let p = path.unwrap().display().to_string();
DiskSpeedWidget::new(&p, num_samples)
})
.collect();
AllDiskSpeedWidget { disks }
}
}
impl Widget for AllDiskSpeedWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
let disks: Vec<_> = self
.disks
.iter_mut()
.filter_map(|dev| {
if !dev.is_active() {
return None;
}
if let Some(text) = dev.render() {
let name = dev.device.rsplit("/").skip(1).nth(0).unwrap();
Some(format!("{}: {}", name, text))
} else {
None
}
})
.collect();
let mut data = Block::new();
data.use_pango();
disks.iter().for_each(|n| {
data.append_full_text(n);
});
Some(WidgetUpdate {
refresh_interval: std::time::Duration::new(1, 0),
data: Some(data),
})
}
}

View File

@@ -1,4 +1,5 @@
pub mod cpu;
pub mod datetime;
pub mod disk;
pub mod network;
pub mod power;

View File

@@ -1,11 +1,13 @@
use i3monkit::Block;
use i3monkit::{Widget, WidgetUpdate};
use std::{
collections::vec_deque::VecDeque,
fs::File,
io::{BufRead, BufReader, Error, ErrorKind, Result},
path::PathBuf,
time::SystemTime,
};
use std::collections::vec_deque::VecDeque;
use std::fs::File;
use std::io::{BufRead, BufReader, Error, ErrorKind, Result};
use std::path::PathBuf;
use std::time::SystemTime;
use i3monkit::{Block, Widget, WidgetUpdate};
use regex::Regex;
use crate::spark;
@@ -84,8 +86,8 @@ impl NetworkSpeedWidget {
pub fn new(interface: &str, num_samples: usize) -> Self {
let last_stat = TransferStat::read_stat(interface).unwrap();
let interface = interface.to_string();
let rx_history: VecDeque<f32> = (0..num_samples).map(|_| 0.).collect();
let tx_history: VecDeque<f32> = (0..num_samples).map(|_| 0.).collect();
let rx_history: VecDeque<f32> = (0..num_samples).map(|_| 1.).collect();
let tx_history: VecDeque<f32> = (0..num_samples).map(|_| 1.).collect();
Self {
last_stat,
interface,
@@ -94,6 +96,10 @@ impl NetworkSpeedWidget {
}
}
fn is_active(&self) -> bool {
(self.rx_history.iter().sum::<f32>() + self.tx_history.iter().sum::<f32>()) > 0.
}
fn format_rate(rate: f64) -> String {
if rate.is_nan() {
return "N/A".to_string();
@@ -129,12 +135,9 @@ impl NetworkSpeedWidget {
Ok((Self::format_rate(rx_rate), Self::format_rate(tx_rate)))
}
}
impl Widget for NetworkSpeedWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
fn render(&mut self) -> Option<String> {
if let Ok((rx, tx)) = self.get_human_readable_stat() {
let mut data = Block::new();
let (rx_history, tx_history) = if self.rx_history.len() > 1 {
let g = spark::Graph {
min: None,
@@ -147,11 +150,21 @@ impl Widget for NetworkSpeedWidget {
} else {
("".to_string(), "".to_string())
};
data.use_pango();
data.append_full_text(&format!(
return Some(format!(
"Rx:<tt>{} {}</tt> Tx:<tt>{} {}</tt>",
rx, rx_history, tx, tx_history
));
}
None
}
}
impl Widget for NetworkSpeedWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
if let Some(text) = self.render() {
let mut data = Block::new();
data.use_pango();
data.append_full_text(&text);
return Some(WidgetUpdate {
refresh_interval: std::time::Duration::new(1, 0),
data: Some(data),
@@ -160,3 +173,56 @@ impl Widget for NetworkSpeedWidget {
None
}
}
pub struct AllNetworkSpeedWidget {
nics: Vec<NetworkSpeedWidget>,
}
impl AllNetworkSpeedWidget {
pub fn new(num_samples: usize) -> Self {
let dev_pat = Regex::new("(enp|eno).*").expect("bad re");
let nics = std::fs::read_dir(NETWORK_PATH_PREFIX)
.expect(&format!("couldn't list {NETWORK_PATH_PREFIX}"))
.filter_map(|dir| {
let d = dir.unwrap();
let p = d.file_name();
let p = p.to_string_lossy();
if dev_pat.is_match(&p) {
Some(NetworkSpeedWidget::new(&p, num_samples))
} else {
None
}
})
.collect();
AllNetworkSpeedWidget { nics }
}
}
impl Widget for AllNetworkSpeedWidget {
fn update(&mut self) -> Option<WidgetUpdate> {
let nics: Vec<_> = self
.nics
.iter_mut()
.filter_map(|nic| {
if !nic.is_active() {
return None;
}
if let Some(text) = nic.render() {
Some(format!("{}: {}", nic.interface, text))
} else {
None
}
})
.collect();
let mut data = Block::new();
data.use_pango();
nics.iter().for_each(|n| {
data.append_full_text(n);
});
Some(WidgetUpdate {
refresh_interval: std::time::Duration::new(1, 0),
data: Some(data),
})
}
}

View File

@@ -13,9 +13,11 @@
use std::collections::HashMap;
use glob::glob;
use i3monkit::{Block, Widget, WidgetUpdate};
use i3monkit::{Block, ColorRGB, Widget, WidgetUpdate};
use thiserror::Error;
use crate::colors;
#[derive(Debug, Default)]
pub struct PowerSupply {}
@@ -56,6 +58,14 @@ impl PowerSupply {
})
})
.collect::<Result<_, _>>()?;
// Skip things that aren't battery powered
if !values
.get("POWER_SUPPLY_TYPE")
.map(|t| t == &"Battery")
.unwrap_or(false)
{
continue;
}
let cap: u32 = values
.get("POWER_SUPPLY_CAPACITY")
.unwrap_or(&"0")
@@ -71,14 +81,24 @@ impl PowerSupply {
} else {
BATT_0
};
let color = if cap >= 50 {
colors::WHITE
} else if cap >= 25 {
ColorRGB::yellow()
} else {
ColorRGB::red()
};
res.push(format!(
"{} {}: <span face=\"pango:Font Awesome 5 Free\">{}</span>",
r##"{} {}: {}% <span color="{}" face="pango:Font Awesome 5 Free">{}</span>"##,
values
.get("POWER_SUPPLY_MANUFACTURER")
.unwrap_or(&"Unknown mfg"),
values
.get("POWER_SUPPLY_MODEL_NAME")
.unwrap_or(&"Unknown model"),
cap,
colors::to_string(color),
power,
));
}