summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors/Net.hs
diff options
context:
space:
mode:
authorJose A Ortega Ruiz <jao@gnu.org>2010-03-19 21:33:24 +0100
committerJose A Ortega Ruiz <jao@gnu.org>2010-03-19 21:33:24 +0100
commitdc171e4a07e597f9f5d7839c231b8b9c3ae19437 (patch)
treecae45f74db3ffd894b7fb593288ebc46538aede3 /Plugins/Monitors/Net.hs
parent4f8ba03c51570925fb59e90e65747da37a2a4b65 (diff)
downloadxmobar-dc171e4a07e597f9f5d7839c231b8b9c3ae19437.tar.gz
xmobar-dc171e4a07e597f9f5d7839c231b8b9c3ae19437.tar.bz2
Usage bars
Ignore-this: 63fd21a117029674e33a9c4419dbc4de ASCII art bars for a bunch of monitors. darcs-hash:20100319203324-748be-2f927aa0e16d8874e10a04f0245427d32e0e53ce.gz
Diffstat (limited to 'Plugins/Monitors/Net.hs')
-rw-r--r--Plugins/Monitors/Net.hs22
1 files changed, 13 insertions, 9 deletions
diff --git a/Plugins/Monitors/Net.hs b/Plugins/Monitors/Net.hs
index e948bc0..7fed311 100644
--- a/Plugins/Monitors/Net.hs
+++ b/Plugins/Monitors/Net.hs
@@ -29,14 +29,14 @@ interval = 500000
netConfig :: IO MConfig
netConfig = mkMConfig
"<dev>: <rx>|<tx>" -- template
- ["dev", "rx", "tx"] -- available replacements
+ ["dev", "rx", "tx", "rxbar", "txbar"] -- available replacements
-- Given a list of indexes, take the indexed elements from a list.
getNElements :: [Int] -> [a] -> [a]
getNElements ns as = map (as!!) ns
-- Split into words, with word boundaries indicated by the given predicate.
--- Drops delimiters. Duplicates 'Data.List.Split.wordsBy'.
+-- Drops delimiters. Duplicates 'Data.List.Split.wordsBy'.
--
-- > map (wordsBy (`elem` " :")) ["lo:31174097 31174097", "eth0: 43598 88888"]
--
@@ -62,17 +62,21 @@ netParser :: B.ByteString -> [NetDev]
netParser =
map (readNetDev . getNElements [0,1,9] . wordsBy (`elem` " :") . B.unpack) . drop 2 . B.lines
-formatNet :: Float -> Monitor String
-formatNet d =
- showWithColors f d
- where f s = showDigits 1 s ++ "Kb"
+formatNet :: Float -> Monitor (String, String)
+formatNet d = do
+ h <- getConfigValue high
+ let dx = 8 + logBase 10 (d / fromIntegral h)
+ b <- showPercentBar d $ max (dx / 10) 0
+ x <- showWithColors f d
+ return (x, b)
+ where f s = showDigits 1 s ++ "Kb"
printNet :: NetDev -> Monitor String
printNet nd =
case nd of
- ND d r t -> do rx <- formatNet r
- tx <- formatNet t
- parseTemplate [d,rx,tx]
+ ND d r t -> do (rx, rb) <- formatNet r
+ (tx, tb) <- formatNet t
+ parseTemplate [d,rx,tx,rb,tb]
NA -> return "N/A"
parseNET :: String -> IO [NetDev]