summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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 ()