diff options
Diffstat (limited to 'src/Xmobar/Plugins/Monitors')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Net.hs | 22 |
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 () |