summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvindex10 <vindex10@gmail.com>2019-10-21 19:17:49 +0200
committerjao <jao@gnu.org>2019-10-21 18:17:49 +0100
commite9638fdc41ccd0876f17b4344461deaa109332e2 (patch)
treeff43109455014449dd984712768925f140023987
parent238905099eb7d6a0ee44dadc2ff051692d8831f6 (diff)
downloadxmobar-e9638fdc41ccd0876f17b4344461deaa109332e2.tar.gz
xmobar-e9638fdc41ccd0876f17b4344461deaa109332e2.tar.bz2
add filtering option for Net devices (#408)
* add filtering option for Net devices * relate to comments * upd readme * add few more words to readme
-rw-r--r--readme.md4
-rw-r--r--src/Xmobar/Plugins/Monitors/Net.hs22
2 files changed, 24 insertions, 2 deletions
diff --git a/readme.md b/readme.md
index 073a181..10eb91b 100644
--- a/readme.md
+++ b/readme.md
@@ -799,13 +799,15 @@ specification, such as `("clear", "<icon=weather-clear.xbm/>")`.
- Thresholds are expressed in Kb/s
- Args: default monitor arguments, plus:
- `--rx-icon-pattern`: dynamic string for reception rate in `rxipat`.
- - `--tx-icon-pattern`: dynamic string for transmission rate in `txipat`.
+ - `--tx-icon-pattern`: dynamic string for transmission rate in `txipat`
+ - `--devices`: comma-separated list of devices to show.
- Variables that can be used with the `-t`/`--template` argument:
`dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxipat`, `txbar`, `txvbar`,
`txipat`. Reception and transmission rates (`rx` and `tx`) are displayed
in Kbytes per second, and you can set the `-S` to "True" to make them
displayed with units (the string "Kb/s").
- Default template: `<dev>: <rx>KB|<tx>KB`
+- Example of usage of `--devices` option: `["--", "--devices", "wlp2s0,enp0s20f41"]`
### `Wireless Interface Args RefreshRate`
diff --git a/src/Xmobar/Plugins/Monitors/Net.hs b/src/Xmobar/Plugins/Monitors/Net.hs
index 81a5f6b..1e8fb72 100644
--- a/src/Xmobar/Plugins/Monitors/Net.hs
+++ b/src/Xmobar/Plugins/Monitors/Net.hs
@@ -31,15 +31,27 @@ import System.IO.Error (catchIOError)
import qualified Data.ByteString.Lazy.Char8 as B
+type DevList = [String]
+
+parseDevList :: String -> DevList
+parseDevList = splitOnComma
+ where splitOnComma [] = [[]]
+ splitOnComma (',':xs) = [] : splitOnComma xs
+ splitOnComma (x:xs) =
+ let rest = splitOnComma xs
+ in (x : head rest) : tail rest
+
data NetOpts = NetOpts
{ rxIconPattern :: Maybe IconPattern
, txIconPattern :: Maybe IconPattern
+ , onlyDevList :: Maybe DevList
}
defaultOpts :: NetOpts
defaultOpts = NetOpts
{ rxIconPattern = Nothing
, txIconPattern = Nothing
+ , onlyDevList = Nothing
}
options :: [OptDescr (NetOpts -> NetOpts)]
@@ -48,6 +60,8 @@ options =
o { rxIconPattern = Just $ parseIconPattern x }) "") ""
, Option "" ["tx-icon-pattern"] (ReqArg (\x o ->
o { txIconPattern = Just $ parseIconPattern x }) "") ""
+ , Option "" ["devices"] (ReqArg (\x o ->
+ o { onlyDevList = Just $ parseDevList x }) "") ""
]
parseOpts :: [String] -> IO NetOpts
@@ -187,10 +201,16 @@ parseNets = mapM $ uncurry parseNet
runNets :: [(NetDevRef, String)] -> [String] -> Monitor String
runNets refs argv = do
- dev <- io $ parseActive refs
opts <- io $ parseOpts argv
+ dev <- io $ parseActive $ filterRefs opts refs
printNet opts dev
where parseActive refs' = fmap selectActive (parseNets refs')
+ refInDevList opts' (_, refname') = case onlyDevList opts' of
+ Just theList -> refname' `elem` theList
+ Nothing -> True
+ filterRefs opts' refs' = case filter (refInDevList opts') refs' of
+ [] -> refs'
+ xs -> xs
selectActive = maximum
startNet :: String -> [String] -> Int -> (String -> IO ()) -> IO ()