From e9638fdc41ccd0876f17b4344461deaa109332e2 Mon Sep 17 00:00:00 2001 From: vindex10 Date: Mon, 21 Oct 2019 19:17:49 +0200 Subject: add filtering option for Net devices (#408) * add filtering option for Net devices * relate to comments * upd readme * add few more words to readme --- readme.md | 4 +++- src/Xmobar/Plugins/Monitors/Net.hs | 22 +++++++++++++++++++++- 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", "")`. - 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: `: KB|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 () -- cgit v1.2.3