Compare commits

...

28 commits

Author SHA1 Message Date
Stephen Seo c659f056da Actually set version 0.1.15 2023-12-06 18:15:48 +09:00
Stephen Seo 08976fc7ab Update dependencies, version 0.1.15 2023-12-06 18:10:40 +09:00
Stephen Seo 2652bd6785 Update README.md about regex syntax link 2023-07-13 15:49:08 +09:00
Stephen Seo eb0ac2df5d Bump version in Cargo.toml 2023-07-13 15:27:10 +09:00
Stephen Seo 2bef53b948 Update Changelog.md 2023-07-13 15:19:57 +09:00
Stephen Seo aae3344e03 Bump dependency "regex" to 1.9 2023-07-13 15:19:11 +09:00
Stephen Seo 5dd426a3de Update LICENSE year 2023-06-07 18:39:10 +09:00
Stephen Seo e8ff22d88c Version 0.1.13 2023-06-05 15:48:10 +09:00
Stephen Seo 3568bebb22 Fix when acpi line has "unavailable" with 0% 2023-06-05 15:45:25 +09:00
Stephen Seo c60629864d Update swaybar example screenshot 2023-05-31 13:29:08 +09:00
Stephen Seo 7db4b850b4 Version 0.1.12, refactorings 2023-05-21 15:08:19 +09:00
Stephen Seo c12dafab07 Version 0.1.11, cleanup colorizing net graph 2023-05-21 14:53:04 +09:00
Stephen Seo 5b2c495982 Version 0.1.10, fix clippy warnings 2023-05-21 14:30:38 +09:00
Stephen Seo 4584dd018d Colorize net graph 2023-05-21 14:23:35 +09:00
Stephen Seo 31458ca38d Update README.md 2022-12-13 20:11:43 +09:00
Stephen Seo 88a0ab12a3 Version 0.1.9 2022-12-13 20:05:35 +09:00
Stephen Seo d5d9ec98dd Update README.md, Changelog.md 2022-12-13 20:05:09 +09:00
Stephen Seo fb4d32e257 Impl setting the history-graph size 2022-12-13 20:03:01 +09:00
Stephen Seo 6bc6c1b38f
Update README.md 2022-12-12 13:33:52 +09:00
Stephen Seo ea718ea833
Update README.md 2022-12-12 13:33:05 +09:00
Stephen Seo bf8bac9311 Version 0.1.8 2022-12-12 13:26:51 +09:00
Stephen Seo b35626c9fb Impl. showing the maximum value in a dyn. netgraph 2022-12-12 13:24:22 +09:00
Stephen Seo 276ae6b94a Version 0.1.7 2022-12-11 22:08:08 +09:00
Stephen Seo b8c5e39d8a Update Changelog.md 2022-12-11 22:07:43 +09:00
Stephen Seo cd91641bf5 Increase netdev traffic minimum text width to 11 2022-12-11 22:02:05 +09:00
Stephen Seo 9096a890be Fix clippy warnings 2022-12-11 21:59:58 +09:00
Stephen Seo d34e597360 Update help text and README.md 2022-12-11 21:55:27 +09:00
Stephen Seo 3889eb6dcc Impl dynamic netgraph display
The netgraph can now dynamically "resize" to always have the maximum
bytes transferred in an interval be the max value.
2022-12-11 21:49:51 +09:00
10 changed files with 667 additions and 139 deletions

322
Cargo.lock generated
View file

@ -4,13 +4,28 @@ version = 3
[[package]]
name = "aho-corasick"
version = "0.7.18"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
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"
@ -18,78 +33,152 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "chrono"
version = "0.4.19"
name = "bumpalo"
version = "3.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec"
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
"num-integer",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"time",
"winapi",
"wasm-bindgen",
"windows-targets",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "iana-time-zone"
version = "0.1.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "itoa"
version = "1.0.2"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
[[package]]
name = "js-sys"
version = "0.3.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca"
dependencies = [
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.126"
version = "0.2.150"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c"
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.5.0"
version = "2.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "num-integer"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
]
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "num-traits"
version = "0.2.15"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c"
dependencies = [
"autocfg",
]
[[package]]
name = "proc-macro2"
version = "1.0.40"
name = "once_cell"
version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
[[package]]
name = "proc-macro2"
version = "1.0.70"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.20"
version = "1.0.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.6.0"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
@ -98,30 +187,30 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.27"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "ryu"
version = "1.0.10"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
[[package]]
name = "serde"
version = "1.0.138"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47"
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.138"
version = "1.0.193"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c"
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
@ -130,9 +219,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.82"
version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7"
checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@ -141,7 +230,7 @@ dependencies = [
[[package]]
name = "swaybar_info"
version = "0.1.6"
version = "0.1.15"
dependencies = [
"chrono",
"regex",
@ -151,56 +240,137 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.98"
version = "2.0.39"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "time"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
dependencies = [
"libc",
"wasi",
"winapi",
]
[[package]]
name = "unicode-ident"
version = "1.0.1"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
name = "wasm-bindgen"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
"cfg-if",
"wasm-bindgen-macro",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
name = "wasm-bindgen-backend"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
name = "wasm-bindgen-macro"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f"
[[package]]
name = "windows-core"
version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
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.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"

View file

@ -1,6 +1,6 @@
[package]
name = "swaybar_info"
version = "0.1.6"
version = "0.1.15"
edition = "2021"
description = "Provides swaybar with info to be displayed"
license = "MIT"
@ -12,4 +12,4 @@ repository = "https://github.com/Stephen-Seo/swaybar_info"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
chrono = "0.4"
regex = "1.6"
regex = "1.10"

View file

@ -2,6 +2,52 @@
## Upcoming Changes
## 0.1.15
Update dependencies (`cargo update` and bump `regex` version).
## 0.1.14
Bumped dependency `regex` to version `1.9`.
## 0.1.13
Fix to workaround when `acpi` output contains a `0%` line with "unavailable".
When such a line is encountered, it is ignored.
## 0.1.12
Some refactoring of the code related to colorizing the netgraph.
## 0.1.11
Use pango markup to colorize the netgraph, making it look cleaner.
## 0.1.10
Colorize the netgraph based on if download or upload is greater.
Download is red, upload is green, and same amount is yellow.
## 0.1.9
Impl. changing the size of the net-graph (default 10).
## 0.1.8
Impl. showing the maximum value in a dynamic netgraph.
## 0.1.7
When swaybar\_info starts, it no longer displays the traffic amount leading up
to the start of the program (it now starts at 0).
Increase netdev traffic minimum text width to 11 (was 10).
Updated README.md and help text based on new dynamic-netgraph-display feature.
Impl. dynamic netgraph display (the netgraph will scale the graph based on the
maximum traffic in an interval dynamically).
## 0.1.6
Minor refactoring of how the netgraph string is handled.

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022 Stephen Seo
Copyright (c) 2022-2023 Stephen Seo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -16,15 +16,18 @@ tiling Wayland compositor](https://swaywm.org).
## Help Text
Usage:
-h | --help Prints help
--netdev=<device_name> Check network traffic on specified device
--netdev_width=<width> Sets the min-width of the netdev output (default 10)
--netgraph_max_bytes=<bytes> Enable "graph" output when polling network traffic
--interval-sec=<seconds> Output at intervals of <seconds> (default 5)
--acpi-builtin Use "acpi -b" built-in fetching (battery info, with color)
--regex-cmd=<cmd>[SPLIT]<args...>[SPLIT]<regex> Use an output of a command as a metric
--time-format=<date format string> Set the format string for the date
Usage:
-h | --help Prints help
--netdev=<device_name> Check network traffic on specified device
--netdev_width=<width> Sets the min-width of the netdev output (default 11)
--netgraph_max_bytes=<bytes> Enable "graph" output when polling network traffic
(Set to "dynamic" instead of a byte count for dynamic sizing)
--netgraph_size=<size> Set the number of characters displayed in the net-graph (size of graph; default 10)
--netgraph_dyn_display Enable showing the current maximum value in the graph
--interval-sec=<seconds> Output at intervals of <seconds> (default 5)
--acpi-builtin Use "acpi -b" built-in fetching (battery info, with color)
--regex-cmd=<cmd>[SPLIT]<args...>[SPLIT]<regex> Use an output of a command as a metric
--time-format=<date format string> Set the format string for the date
## Usage
@ -93,7 +96,7 @@ for the output text, and the color will be left unspecified (usually defaulting
to white).
For a reference of what kind of regex is supported,
[see this page](https://docs.rs/regex/1.6.0/regex/index.html#syntax).
[see this page](https://docs.rs/regex/1.9.1/regex/index.html#syntax).
## Net graph
@ -107,6 +110,18 @@ characters](https://en.wikipedia.org/wiki/Block_Elements)). Thus, this outputs
a history graph of network traffic. A sane value for `<bytes>` can be 1048576,
which is 1 MiB.
Specify "dynamic" instead of a bytecount (such as
`--netgraph_max_bytes=dynamic`) to have the graph dynamically resize based on
the maximum amount of bytes transferred in an interval.
When dynamic netgraph is used, swaybar\_info can display the maximum value in
the netgraph. Use the `--netgraph_dyn_display` option to enable this. (This
only works when dynamic netgraph is enabled with
`--netgraph_max_bytes=dynamic`.)
The size of the netgraph is 10 characters by default, but this can be changed by
using `--netgraph_size=<size>`.
## Dependencies
Uses [`serde_json`](https://crates.io/crates/serde_json),

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View file

@ -25,6 +25,11 @@ pub fn get_args() -> ArgsResult {
} else if arg.starts_with("--netgraph_max_bytes=") {
let (_, back) = arg.split_at(21);
map.insert("netgraph".into(), back.into());
} else if arg.starts_with("--netgraph_dyn_display") {
map.insert("netgraph-dyndisplay".into(), String::new());
} else if arg.starts_with("--netgraph_size=") {
let (_, back) = arg.split_at(16);
map.insert("netgraph-size".into(), back.into());
} else if arg.starts_with("--interval-sec=") {
let (_, back) = arg.split_at(15);
map.insert("interval-sec".into(), back.into());
@ -59,11 +64,20 @@ pub fn print_usage() {
.write_all(b" --netdev=<device_name>\t\t\t\tCheck network traffic on specified device\n")
.ok();
stderr_handle
.write_all(b" --netdev_width=<width>\t\t\t\tSets the min-width of the netdev output (default 10)\n")
.write_all(b" --netdev_width=<width>\t\t\t\tSets the min-width of the netdev output (default 11)\n")
.ok();
stderr_handle
.write_all(b" --netgraph_max_bytes=<bytes>\t\t\t\tEnable \"graph\" output when polling network traffic\n")
.ok();
stderr_handle
.write_all(b" \t\t\t\t (Set to \"dynamic\" instead of a byte count for dynamic sizing)\n")
.ok();
stderr_handle
.write_all(b" --netgraph_size=<size>\t\t\t\tSet the number of characters displayed in the net-graph (size of graph; default 10)\n")
.ok();
stderr_handle
.write_all(b" --netgraph_dyn_display\t\t\t\tEnable showing the current maximum value in the graph\n")
.ok();
stderr_handle
.write_all(
b" --interval-sec=<seconds>\t\t\t\tOutput at intervals of <seconds> (default 5)\n",

View file

@ -127,7 +127,14 @@ impl BattInfo {
cmd_builder.arg("-b");
let output = cmd_builder.output()?;
let string = String::from_utf8(output.stdout)?;
let regex_captures_result = self.regex.captures(&string);
let mut last_line = "unknown".to_owned();
for line in string.lines() {
if !line.contains("unavailable") {
last_line = line.to_owned();
break;
}
}
let regex_captures_result = self.regex.captures(&last_line);
if regex_captures_result.is_none() {
self.acpi_error = true;
return Err(Error::Generic("battinfo: regex captured nothing".into()));

View file

@ -4,6 +4,7 @@ mod external;
mod proc;
mod swaybar_object;
use std::fmt::Write as FMTWrite;
use std::io::{self, Write};
use std::time::Duration;
use swaybar_object::*;
@ -44,14 +45,45 @@ fn main() {
}
let mut net_obj: Option<proc::NetInfo> = None;
let mut net_width: Option<u16> = Some(10);
let mut net_width: Option<u16> = Some(11);
let mut net_graph_max: Option<f64> = None;
let mut net_graph_is_dynamic: bool = false;
let mut net_graph_show_dynamic_max: bool = false;
let mut interval: Duration = Duration::from_secs(5);
let mut net_graph_size: Option<usize> = None;
if args_result.map.contains_key("netdev") {
if let Some(size_str) = args_result.map.get("netgraph-size") {
if let Ok(size) = size_str.parse::<usize>() {
if size > 0 {
net_graph_size = Some(size);
} else {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
"WARNING: Invalid value passed to --netgraph_size=..., ignoring...\n"
.as_bytes(),
)
.ok();
}
} else {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
"WARNING: Invalid value passed to --netgraph_size=..., ignoring...\n"
.as_bytes(),
)
.ok();
}
}
net_obj = Some(proc::NetInfo::new(
args_result.map.get("netdev").unwrap().to_owned(),
net_graph_size,
));
}
if net_graph_size.is_none() {
net_graph_size = Some(10);
}
if args_result.map.contains_key("netdevwidth") {
let width_result: Result<u16, _> = args_result.map.get("netdevwidth").unwrap().parse();
if let Ok(width) = width_result {
@ -60,28 +92,32 @@ fn main() {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
format!("WARNING: Invalid value passed to --netdev_width=..., ignoring...\n")
.as_bytes(),
"WARNING: Invalid value passed to --netdev_width=..., ignoring...\n".as_bytes(),
)
.ok();
}
}
if args_result.map.contains_key("netgraph") {
let graph_max_result: Result<f64, _> = args_result.map.get("netgraph").unwrap().parse();
if let Ok(graph_max) = graph_max_result {
net_graph_max = Some(graph_max);
if args_result.map.get("netgraph").as_ref().unwrap() == &"dynamic" {
net_graph_is_dynamic = true;
} else {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
format!(
let graph_max_result: Result<f64, _> = args_result.map.get("netgraph").unwrap().parse();
if let Ok(graph_max) = graph_max_result {
net_graph_max = Some(graph_max);
} else {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
"WARNING: Invalid value passed to --netgraph_max_bytes=..., ignoring...\n"
.as_bytes(),
)
.as_bytes(),
)
.ok();
.ok();
}
}
}
if args_result.map.contains_key("netgraph-dyndisplay") {
net_graph_show_dynamic_max = true;
}
if args_result.map.contains_key("interval-sec") {
let seconds: Result<i64, _> = args_result.map.get("interval-sec").unwrap().parse();
if let Ok(seconds_value) = seconds {
@ -126,7 +162,14 @@ fn main() {
let mut array = SwaybarArray::new();
let set_net_error = |is_empty: bool, array: &mut SwaybarArray, graph_max_opt: &Option<f64>| {
if is_empty {
if graph_max_opt.is_some() {
if net_graph_is_dynamic && net_graph_show_dynamic_max {
array.push_object(SwaybarObject::from_error_string(
"net_graph_dyn_max".to_owned(),
"net ERROR".into(),
));
}
if graph_max_opt.is_some() || net_graph_is_dynamic {
array.push_object(SwaybarObject::from_error_string(
"net_graph".to_owned(),
"net ERROR".into(),
@ -140,7 +183,13 @@ fn main() {
let up_obj = SwaybarObject::from_error_string("net_up".to_owned(), "Net ERROR".into());
array.push_object(up_obj);
} else {
if graph_max_opt.is_some() {
if net_graph_is_dynamic && net_graph_show_dynamic_max {
if let Some(dyn_max) = array.get_by_name_mut("net_graph_dyn_max") {
dyn_max.update_as_error("Net ERROR".to_owned());
}
}
if graph_max_opt.is_some() || net_graph_is_dynamic {
if let Some(graph_ref) = array.get_by_name_mut("net_graph") {
graph_ref.update_as_error("Net ERROR".to_owned());
}
@ -163,17 +212,27 @@ fn main() {
array: &mut SwaybarArray|
-> Result<(), proc::Error> {
net.update()?;
let (netinfo_string, graph_string) = net.get_netstring(net_graph_max)?;
let (netinfo_string, graph_items, max_idx, history_max) =
net.get_netstring(net_graph_max)?;
let netinfo_parts: Vec<&str> = netinfo_string.split_whitespace().collect();
if is_empty {
if net_graph_max.is_some() {
if net_graph_is_dynamic && net_graph_show_dynamic_max {
let mut graph_obj =
SwaybarObject::from_string("net_graph".to_owned(), graph_string);
SwaybarObject::from_string("net_graph_dyn_max".to_owned(), history_max);
graph_obj.color = Some("#ffff88".into());
array.push_object(graph_obj);
}
if net_graph_max.is_some() || net_graph_is_dynamic {
let mut graph_obj = SwaybarObject::from_string(
"net_graph".to_owned(),
" ".to_owned().repeat(net_graph_size.unwrap()),
);
graph_obj.markup = Some("pango".to_owned());
array.push_object(graph_obj);
}
let mut width_string: Option<String> = None;
if let Some(width) = net_width {
let mut string = String::with_capacity(width.into());
@ -205,9 +264,53 @@ fn main() {
array.push_object(up_object);
}
} else {
if net_graph_max.is_some() {
if net_graph_is_dynamic && net_graph_show_dynamic_max {
if let Some(graph_obj) = array.get_by_name_mut("net_graph_dyn_max") {
graph_obj.full_text = history_max;
if (net_graph_max.is_some() || net_graph_is_dynamic) && !graph_items.is_empty()
{
match graph_items[max_idx].get_value_type() {
proc::GraphItemType::Download => {
graph_obj.color = Some("#ff8888ff".into())
}
proc::GraphItemType::Upload => {
graph_obj.color = Some("#88ff88ff".into())
}
proc::GraphItemType::Both => graph_obj.color = Some("#ffff88ff".into()),
}
}
}
}
if net_graph_max.is_some() || net_graph_is_dynamic {
if let Some(graph_obj) = array.get_by_name_mut("net_graph") {
graph_obj.full_text = graph_string;
let mut text = String::new();
for item in graph_items.iter() {
match item.get_value_type() {
proc::GraphItemType::Download => {
write!(
&mut text,
"<span color=\"#ff8888ff\">{}</span>",
item.get_value()
)?;
}
proc::GraphItemType::Upload => {
write!(
&mut text,
"<span color=\"#88ff88ff\">{}</span>",
item.get_value()
)?;
}
proc::GraphItemType::Both => {
write!(
&mut text,
"<span color=\"#ffff88ff\">{}</span>",
item.get_value()
)?;
}
}
}
graph_obj.full_text = text;
}
}

View file

@ -1,6 +1,7 @@
use std::fmt::Write;
use std::fmt::Write as FMTWrite;
use std::fs::File;
use std::io::prelude::*;
use std::io::Write as IOWrite;
#[derive(Debug)]
pub enum Error {
@ -56,25 +57,82 @@ impl std::error::Error for Error {
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum GraphItemType {
Download,
Upload,
Both,
}
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct GraphItem {
value: char,
num_value: f64,
value_type: GraphItemType,
}
impl GraphItem {
pub fn get_value(&self) -> char {
self.value
}
pub fn set_value(&mut self, c: char) {
self.value = c;
}
pub fn get_num_value(&self) -> f64 {
self.num_value
}
pub fn get_value_type(&self) -> GraphItemType {
self.value_type
}
}
pub struct NetInfo {
dev_name: String,
graph: String,
graph: Vec<GraphItem>,
down: u64,
prev_down: u64,
up: u64,
prev_up: u64,
first_iteration: bool,
}
impl NetInfo {
pub fn new(dev_name: String) -> Self {
Self {
pub fn new(dev_name: String, graph_size_opt: Option<usize>) -> Self {
let mut s = Self {
dev_name,
graph: String::from(" "),
graph: vec![GraphItem {
value: ' ',
num_value: 0.0,
value_type: GraphItemType::Both,
}],
down: 0,
prev_down: 0,
up: 0,
prev_up: 0,
first_iteration: true,
};
if let Some(graph_size) = graph_size_opt {
if graph_size > 0 {
s.graph = s.graph.repeat(graph_size);
} else {
let mut stderr_handle = std::io::stderr().lock();
stderr_handle
.write_all(
"WARNING: Invalid graph_size value passed to NetInfo, ignoring...\n"
.as_bytes(),
)
.ok();
s.graph = s.graph.repeat(10);
}
} else {
s.graph = s.graph.repeat(10);
}
s
}
pub fn update(&mut self) -> Result<(), Error> {
@ -98,8 +156,13 @@ impl NetInfo {
return Err(format!("NetInfo::update: Failed to parse /proc/net/dev, \"{}\" device line is too short", self.dev_name).into());
}
self.down = entries[1].parse()?;
self.up = entries[9].parse()?;
if !self.first_iteration {
self.down = entries[1].parse()?;
self.up = entries[9].parse()?;
} else {
self.prev_down = entries[1].parse()?;
self.prev_up = entries[9].parse()?;
}
} else {
return Err(format!(
"NetInfo::update: Failed to parse /proc/net/dev, can't find net device \"{}\"",
@ -108,14 +171,30 @@ impl NetInfo {
.into());
}
self.first_iteration = false;
Ok(())
}
pub fn get_netstring(&mut self, graph_max: Option<f64>) -> Result<(String, String), Error> {
let down_diff: f64 = (self.down - self.prev_down) as f64;
self.prev_down = self.down;
let up_diff: f64 = (self.up - self.prev_up) as f64;
self.prev_up = self.up;
// Returns netinfo down/up, graph, max idx, and history_max (if dynamic is enabled)
pub fn get_netstring(
&mut self,
graph_max_opt: Option<f64>,
) -> Result<(String, &Vec<GraphItem>, usize, String), Error> {
let down_diff: f64 = if self.down > self.prev_down {
let value = (self.down - self.prev_down) as f64;
self.prev_down = self.down;
value
} else {
0.0
};
let up_diff: f64 = if self.up > self.prev_up {
let value = (self.up - self.prev_up) as f64;
self.prev_up = self.up;
value
} else {
0.0
};
let mut output = String::new();
if down_diff > 1024.0 * 1024.0 {
@ -134,12 +213,21 @@ impl NetInfo {
write!(&mut output, "{:.0} B", up_diff)?;
}
if let Some(graph_max) = graph_max {
let diff_max = if down_diff > up_diff {
down_diff
} else {
up_diff
};
let mut graph_type = GraphItemType::Both;
let diff_max = if down_diff > up_diff {
graph_type = GraphItemType::Download;
down_diff
} else {
if down_diff < up_diff {
graph_type = GraphItemType::Upload;
}
up_diff
};
let mut diff_max_string = String::new();
let mut history_max_idx = 0;
if let Some(graph_max) = graph_max_opt {
let graph_value: u8 = if diff_max > graph_max {
8
} else {
@ -148,19 +236,104 @@ impl NetInfo {
self.graph.remove(0);
match graph_value {
0 => self.graph.push(' '),
1 => self.graph.push('▁'),
2 => self.graph.push('▂'),
3 => self.graph.push('▃'),
4 => self.graph.push('▄'),
5 => self.graph.push('▅'),
6 => self.graph.push('▆'),
7 => self.graph.push('▇'),
_ => self.graph.push('█'),
0 => self.graph.push(GraphItem {
value: ' ',
num_value: 0.0,
value_type: graph_type,
}),
1 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
2 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
3 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
4 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
5 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
6 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
7 => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
_ => self.graph.push(GraphItem {
value: '',
num_value: 0.0,
value_type: graph_type,
}),
}
} else {
self.graph.rotate_left(1);
{
let end_idx = self.graph.len() - 1;
self.graph[end_idx] = GraphItem {
value: ' ',
num_value: diff_max,
value_type: graph_type,
};
}
let mut history_max: f64 = 0.0;
for (idx, value) in self
.graph
.iter()
.map(|item| item.get_num_value())
.enumerate()
{
if history_max < value {
history_max = value;
history_max_idx = idx;
}
}
if history_max > 1024.0 * 1024.0 {
write!(
&mut diff_max_string,
"{:.2} MiB",
history_max / (1024.0 * 1024.0)
)?;
} else if history_max > 1024.0 {
write!(&mut diff_max_string, "{:.2} KiB", history_max / 1024.0)?;
} else {
write!(&mut diff_max_string, "{:.0} B", history_max)?;
}
for item in self.graph.iter_mut() {
match (8.0 * item.get_num_value() / history_max).round() as u8 {
0 => item.set_value(' '),
1 => item.set_value('▁'),
2 => item.set_value('▂'),
3 => item.set_value('▃'),
4 => item.set_value('▄'),
5 => item.set_value('▅'),
6 => item.set_value('▆'),
7 => item.set_value('▇'),
_ => item.set_value('█'),
}
}
}
Ok((output, self.graph.clone()))
Ok((output, &self.graph, history_max_idx, diff_max_string))
}
}