Compare commits

..

No commits in common. "master" and "0.1.2" have entirely different histories.

12 changed files with 116 additions and 881 deletions

328
Cargo.lock generated
View file

@ -4,178 +4,92 @@ version = 3
[[package]]
name = "aho-corasick"
version = "1.1.3"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
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.3.0"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "bumpalo"
version = "3.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
[[package]]
name = "cc"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "chrono"
version = "0.4.38"
version = "0.4.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401"
checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"libc",
"num-integer",
"num-traits",
"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.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
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",
"time",
"winapi",
]
[[package]]
name = "itoa"
version = "1.0.11"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "js-sys"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d"
dependencies = [
"wasm-bindgen",
]
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
[[package]]
name = "libc"
version = "0.2.155"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "memchr"
version = "2.7.2"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
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",
]
[[package]]
name = "num-traits"
version = "0.2.19"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "proc-macro2"
version = "1.0.85"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.10.5"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
dependencies = [
"aho-corasick",
"memchr",
@ -184,30 +98,30 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.8.4"
version = "0.6.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
[[package]]
name = "ryu"
version = "1.0.18"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
[[package]]
name = "serde"
version = "1.0.203"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094"
checksum = "1578c6245786b9d168c5447eeacfb96856573ca56c9d68fdcf394be134882a47"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.203"
version = "1.0.138"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba"
checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c"
dependencies = [
"proc-macro2",
"quote",
@ -216,9 +130,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.117"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3"
checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7"
dependencies = [
"itoa",
"ryu",
@ -227,7 +141,7 @@ dependencies = [
[[package]]
name = "swaybar_info"
version = "0.1.16"
version = "0.1.2"
dependencies = [
"chrono",
"regex",
@ -237,144 +151,56 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.66"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
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.12"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "wasm-bindgen"
version = "0.2.92"
name = "wasi"
version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"cfg-if",
"wasm-bindgen-macro",
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.92"
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da"
dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.92"
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

View file

@ -1,6 +1,6 @@
[package]
name = "swaybar_info"
version = "0.1.16"
version = "0.1.2"
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.10"
regex = "1.5"

View file

@ -2,94 +2,6 @@
## Upcoming Changes
## 0.1.16
Update dependencies (`cargo update`).
## 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.
Refactoring of handling of Option types wrapping primitive values.
Round values when determining netgraph results instead of truncating to an
integer.
## 0.1.5
Implemented `--netdev_width=<width>` which sets the minimum width of the netdev
byte/KiB/MiB text displays.
Implemented `--netgraph_max_bytes=<bytes>` which displays a graph in text using
Unicode "Block Elements" symbols. The `<bytes>` argument determines the maximum
amount of bytes that will determine which block-character is printed on the
interval. The graph is always 10 characters wide, and the right side is the
most-recent side. Note that this always checks against the maximum of either
download or upload rates. For example, if `<bytes>` is set to 1024, and 128
bytes were downloaded and 512 bytes were uploaded in an interval, the "Lower
Half Block" Unicode symbol will be emitted (exactly half).
SwaybarObject was changed to use an `Option<String>` instead of an `Option<u16>`
for `min_width`.
## 0.1.4
Implemented advanced usage of `--regex-cmd=...` such that output text and output
text color can be specified with regex captures. The first capture is the output
text and the second capture is its color.
The README.md explains how to use this feature.
## 0.1.3
Fix failing to fetch netdev info when /proc/net/dev device starts with whitespace.
## 0.1.2
Fix README.md (erroneously used `--date-format` instead of `--time-format`).

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2022-2023 Stephen Seo
Copyright (c) 2022 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

@ -1,7 +1,6 @@
# swaybar\_info
[![swaybar\_info crates.io version badge](https://img.shields.io/crates/v/swaybar_info)](https://crates.io/crates/swaybar_info)
[![swaybar\_info license badge](https://img.shields.io/github/license/Stephen-Seo/swaybar_info)](https://choosealicense.com/licenses/mit/)
[![swaybar\_info badge](https://img.shields.io/crates/v/swaybar_info)](https://crates.io/crates/swaybar_info)
[![swaybar\_info preview image](https://github.com/Stephen-Seo/swaybar_info/raw/master/pictures/swaybar_screenshot_00.png)](https://github.com/Stephen-Seo/swaybar_info/raw/master/pictures/swaybar_screenshot_00.png)
@ -16,18 +15,13 @@ 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 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:
-h | --help Prints help
--netdev=<device_name> Check network traffic on specified device
--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
@ -68,60 +62,6 @@ Put the following in your `~/.config/sway/config` (assuming the binary is at
#status_command $HOME/.config/sway/swaybar_info --time-format="%Y-%m-%d %R:%S"
}
## Advanced Usage of `--regex-cmd`
If the regex provided to `swaybar_info` has two captures, the first capture will
be used as the text to be displayed, and the second capture will be expected to
be the color string (such as FFFFFF for white, or 44FF44 for a lighter green).
For example, if the script invoked with `--regex-cmd` has output like the
following:
MPD Title | MPD Album | playingCOLORSPLIT44FF44
That sometimes becomes:
MPD is not running
Then this text can be parsed with a regex like:
status_command $HOME/.config/sway/swaybar_info \
'--regex-cmd=$HOME/scripts/mpc/mpcCommand.sh[SPLIT]simple[SPLIT]^\(.\*?\)\(?:COLORSPLIT\([A-F0-9]{6}\)\)?$'
Note that some characters like `*` or `(` had to be escaped because they are
being passed verbatim to a shell.
If only one capture is used in the regex string, then that capture will be used
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.9.1/regex/index.html#syntax).
## Net graph
The `--netgraph_max_bytes=<bytes>` arg enables a 10-character-wide text graph
showing a history of network traffic. The algorithm checks the larger of bytes
sent or received in an interval and compares it to `<bytes>`. If it is greater,
then the graph character will be a "full block" character. If it is less, then
the graph character will be something in between out of 9 possible characters (a
space, and [8 unicode block
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: 27 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

@ -19,17 +19,6 @@ pub fn get_args() -> ArgsResult {
} else if arg.starts_with("--netdev=") {
let (_, back) = arg.split_at(9);
map.insert("netdev".into(), back.into());
} else if arg.starts_with("--netdev_width=") {
let (_, back) = arg.split_at(15);
map.insert("netdevwidth".into(), back.into());
} 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());
@ -63,21 +52,6 @@ pub fn print_usage() {
stderr_handle
.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 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",
@ -95,7 +69,7 @@ pub fn print_usage() {
.ok();
stderr_handle
.write_all(
b" --time-format=<date format string>\t\t\tSet the format string for the date\n",
b" --date-format=<date format string>\t\t\tSet the format string for the date\n",
)
.ok();
}

View file

@ -127,14 +127,7 @@ impl BattInfo {
cmd_builder.arg("-b");
let output = cmd_builder.output()?;
let string = String::from_utf8(output.stdout)?;
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);
let regex_captures_result = self.regex.captures(&string);
if regex_captures_result.is_none() {
self.acpi_error = true;
return Err(Error::Generic("battinfo: regex captured nothing".into()));

View file

@ -9,11 +9,6 @@ pub enum Error {
Generic(String),
}
pub struct ExternalRegexResult {
pub matched: String,
pub color: Option<String>,
}
impl From<io::Error> for Error {
fn from(io_error: io::Error) -> Self {
Self::IO(io_error)
@ -52,11 +47,7 @@ impl std::error::Error for Error {
}
}
pub fn get_cmd_output(
cmd: &str,
args: &[&str],
regex: &Regex,
) -> Result<ExternalRegexResult, Error> {
pub fn get_cmd_output(cmd: &str, args: &[&str], regex: &Regex) -> Result<String, Error> {
let mut cmd_builder = Command::new(cmd);
for arg in args {
cmd_builder.arg(arg);
@ -64,33 +55,10 @@ pub fn get_cmd_output(
let output = cmd_builder.output()?;
let stdout_output: String = String::from_utf8(output.stdout)?;
let regex_captures = regex
.captures(stdout_output.trim())
.captures(&stdout_output)
.ok_or_else(|| Error::from("Regex returned empty matches".to_owned()))?;
let mut color: Option<String> = None;
let matched: String = if regex_captures.len() == 1 {
regex_captures
.get(0)
.ok_or_else(|| Error::from("Failed to get regex 0".to_owned()))?
.as_str()
.to_owned()
} else {
//if regex_captures.len() >= 2 {
regex_captures
.get(1)
.ok_or_else(|| Error::from("Failed to get regex 1".to_owned()))?
.as_str()
.to_owned()
};
match regex_captures.len() {
3 => color = regex_captures.get(2).map(|m| m.as_str().to_owned()),
4.. => {
return Err(Error::from(
"Too many captures in regex, up to 2 is allowed".to_owned(),
))
}
_ => (),
}
Ok(ExternalRegexResult { matched, color })
let regex_match = regex_captures
.get(0)
.ok_or_else(|| Error::from("Failed to get regex match".to_owned()))?;
Ok(regex_match.as_str().to_owned())
}

View file

@ -4,7 +4,6 @@ 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::*;
@ -45,79 +44,12 @@ fn main() {
}
let mut net_obj: Option<proc::NetInfo> = None;
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 {
net_width = Some(width);
} else {
let mut stderr_handle = io::stderr().lock();
stderr_handle
.write_all(
"WARNING: Invalid value passed to --netdev_width=..., ignoring...\n".as_bytes(),
)
.ok();
}
}
if args_result.map.contains_key("netgraph") {
if args_result.map.get("netgraph").as_ref().unwrap() == &"dynamic" {
net_graph_is_dynamic = true;
} else {
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(),
)
.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 {
@ -160,22 +92,8 @@ fn main() {
println!("[");
let mut array = SwaybarArray::new();
let set_net_error = |is_empty: bool, array: &mut SwaybarArray, graph_max_opt: &Option<f64>| {
let set_net_error = |is_empty: bool, array: &mut SwaybarArray| {
if is_empty {
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(),
));
}
let down_obj =
SwaybarObject::from_error_string("net_down".to_owned(), "Net ERROR".into());
array.push_object(down_obj);
@ -183,18 +101,6 @@ fn main() {
let up_obj = SwaybarObject::from_error_string("net_up".to_owned(), "Net ERROR".into());
array.push_object(up_obj);
} else {
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());
}
}
let down_ref_opt = array.get_by_name_mut("net_down");
if let Some(down_ref) = down_ref_opt {
down_ref.update_as_error("Net ERROR".to_owned());
@ -212,44 +118,16 @@ fn main() {
array: &mut SwaybarArray|
-> Result<(), proc::Error> {
net.update()?;
let (netinfo_string, graph_items, max_idx, history_max) =
net.get_netstring(net_graph_max)?;
let netinfo_string = net.get_netstring()?;
let netinfo_parts: Vec<&str> = netinfo_string.split_whitespace().collect();
if is_empty {
if net_graph_is_dynamic && net_graph_show_dynamic_max {
let mut graph_obj =
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());
for _ in 0..width {
string.push('0');
}
width_string = Some(string);
}
{
let mut down_object = SwaybarObject::from_string(
"net_down".to_owned(),
format!("{} {}", netinfo_parts[0], netinfo_parts[1]),
);
down_object.color = Some("#ff8888ff".into());
down_object.min_width = width_string.clone();
down_object.align = Some(String::from("right"));
array.push_object(down_object);
}
@ -259,61 +137,9 @@ fn main() {
format!("{} {}", netinfo_parts[2], netinfo_parts[3]),
);
up_object.color = Some("#88ff88ff".into());
up_object.min_width = width_string;
up_object.align = Some(String::from("right"));
array.push_object(up_object);
}
} else {
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") {
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;
}
}
if let Some(down_object) = array.get_by_name_mut("net_down") {
down_object
.update_as_net_down(format!("{} {}", netinfo_parts[0], netinfo_parts[1]));
@ -336,7 +162,7 @@ fn main() {
let mut stderr_handle = io::stderr().lock();
stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
net_obj = None;
set_net_error(is_empty, &mut array, &net_graph_max);
set_net_error(is_empty, &mut array);
}
}
@ -362,18 +188,15 @@ fn main() {
{
for (idx, (cmd, args, regex)) in cmds.iter().enumerate() {
let cmd_result = external::get_cmd_output(cmd, args, regex);
if let Ok(cmd_struct) = cmd_result {
if let Ok(cmd_string) = cmd_result {
if is_empty {
let mut cmd_obj = SwaybarObject::from_string(
format!("regex_cmd_{}", idx),
cmd_struct.matched,
);
cmd_obj.color = cmd_struct.color;
let cmd_obj =
SwaybarObject::from_string(format!("regex_cmd_{}", idx), cmd_string);
array.push_object(cmd_obj);
} else if let Some(cmd_obj) =
array.get_by_name_mut(&format!("regex_cmd_{}", idx))
{
cmd_obj.update_as_generic(cmd_struct.matched, cmd_struct.color);
cmd_obj.update_as_generic(cmd_string, None);
}
} else if let Err(e) = cmd_result {
let mut stderr_handle = io::stderr().lock();

View file

@ -1,7 +1,6 @@
use std::fmt::Write as FMTWrite;
use std::fmt::Write;
use std::fs::File;
use std::io::prelude::*;
use std::io::Write as IOWrite;
#[derive(Debug)]
pub enum Error {
@ -57,82 +56,23 @@ 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: Vec<GraphItem>,
down: u64,
prev_down: u64,
up: u64,
prev_up: u64,
first_iteration: bool,
}
impl NetInfo {
pub fn new(dev_name: String, graph_size_opt: Option<usize>) -> Self {
let mut s = Self {
pub fn new(dev_name: String) -> Self {
Self {
dev_name,
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> {
@ -143,7 +83,7 @@ impl NetInfo {
}
let mut dev_line: Option<&str> = None;
for line in netdev_string.lines().map(|line| line.trim()) {
for line in netdev_string.lines() {
if line.starts_with(&self.dev_name) {
dev_line = Some(line);
break;
@ -156,13 +96,8 @@ impl NetInfo {
return Err(format!("NetInfo::update: Failed to parse /proc/net/dev, \"{}\" device line is too short", self.dev_name).into());
}
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()?;
}
self.down = entries[1].parse()?;
self.up = entries[9].parse()?;
} else {
return Err(format!(
"NetInfo::update: Failed to parse /proc/net/dev, can't find net device \"{}\"",
@ -171,30 +106,14 @@ impl NetInfo {
.into());
}
self.first_iteration = false;
Ok(())
}
// 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
};
pub fn get_netstring(&mut self) -> Result<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;
let mut output = String::new();
if down_diff > 1024.0 * 1024.0 {
@ -213,127 +132,7 @@ impl NetInfo {
write!(&mut output, "{:.0} B", 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 {
(diff_max / graph_max * 8.0f64).round() as u8
};
self.graph.remove(0);
match graph_value {
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, history_max_idx, diff_max_string))
Ok(output)
}
}

View file

@ -38,7 +38,7 @@ pub struct SwaybarObject {
#[serde(skip_serializing_if = "Option::is_none")]
pub border_right: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub min_width: Option<String>,
pub min_width: Option<u16>,
#[serde(skip_serializing_if = "Option::is_none")]
pub align: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]