summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Net.hs
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 /src/Xmobar/Plugins/Monitors/Net.hs
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
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Net.hs')
-rw-r--r--src/Xmobar/Plugins/Monitors/Net.hs22
1 files changed, 21 insertions, 1 deletions
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 ()