diff options
-rw-r--r-- | Plugins/Monitors/Batt.hs | 7 | ||||
-rw-r--r-- | Plugins/Monitors/Common.hs | 34 | ||||
-rw-r--r-- | Plugins/Monitors/Cpu.hs | 8 | ||||
-rw-r--r-- | Plugins/Monitors/Disk.hs | 7 | ||||
-rw-r--r-- | Plugins/Monitors/Mem.hs | 23 | ||||
-rw-r--r-- | Plugins/Monitors/MultiCpu.hs | 15 | ||||
-rw-r--r-- | Plugins/Monitors/Net.hs | 22 | ||||
-rw-r--r-- | Plugins/Monitors/Wireless.hs | 7 | ||||
-rw-r--r-- | README | 27 |
9 files changed, 96 insertions, 54 deletions
diff --git a/Plugins/Monitors/Batt.hs b/Plugins/Monitors/Batt.hs index 6ea62a9..16af6da 100644 --- a/Plugins/Monitors/Batt.hs +++ b/Plugins/Monitors/Batt.hs @@ -24,7 +24,7 @@ data Batt = Batt Float String battConfig :: IO MConfig battConfig = mkMConfig "Batt: <left>" -- template - ["left","status"] -- available replacements + ["leftbar", "left", "status"] -- available replacements type File = (String, String) @@ -61,7 +61,10 @@ parseBATT bfs = return $ if isNaN left then NA else Batt left c0 formatBatt :: Float -> Monitor [String] -formatBatt x = showPercentsWithColors [x] +formatBatt x = do + p <- showPercentsWithColors [x] + b <- showPercentBar (100 * x) x + return (b:p) runBatt :: [String] -> Monitor String runBatt = runBatt' ["BAT0","BAT1","BAT2"] diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 101907b..535329e 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -40,6 +40,7 @@ module Plugins.Monitors.Common ( , showWithColors , showWithColors' , showPercentsWithColors + , showPercentBar , showWithUnits , takeDigits , showDigits @@ -348,16 +349,18 @@ showWithPadding s = pr <- getConfigValue padRight return $ padString mn mx p pr s +colorizeString :: (Num a, Ord a) => a -> String -> Monitor String +colorizeString x s = do + h <- getConfigValue high + l <- getConfigValue low + let col = setColor s + [ll,hh] = map fromIntegral $ sort [l, h] -- consider high < low + head $ [col highColor | x > hh ] ++ + [col normalColor | x > ll ] ++ + [col lowColor | True] + showWithColors :: (Num a, Ord a) => (a -> String) -> a -> Monitor String -showWithColors f x = - do h <- getConfigValue high - l <- getConfigValue low - s <- showWithPadding $ f x - let col = setColor s - [ll,hh] = map fromIntegral $ sort [l, h] -- consider high < low - head $ [col highColor | x > hh ] ++ - [col normalColor | x > ll ] ++ - [col lowColor | True] +showWithColors f x = showWithPadding (f x) >>= colorizeString x showWithColors' :: (Num a, Ord a) => String -> a -> Monitor String showWithColors' str v = showWithColors (const str) v @@ -367,6 +370,19 @@ showPercentsWithColors fs = do fstrs <- mapM floatToPercent fs zipWithM (showWithColors . const) fstrs (map (*100) fs) +barBackground :: Char +barBackground = ':' +barForeground :: Char +barForeground = '#' +barLength :: Int +barLength = 10 + +showPercentBar :: Float -> Float -> Monitor String +showPercentBar v x = do + let len = min barLength $ round (fromIntegral barLength * x) + s <- colorizeString v (replicate len barForeground) + return $ s ++ replicate (barLength - len) barBackground + -- $threads doActionTwiceWithDelay :: Int -> IO [a] -> IO ([a], [a]) diff --git a/Plugins/Monitors/Cpu.hs b/Plugins/Monitors/Cpu.hs index e813713..d94bd0f 100644 --- a/Plugins/Monitors/Cpu.hs +++ b/Plugins/Monitors/Cpu.hs @@ -20,7 +20,7 @@ import qualified Data.ByteString.Lazy.Char8 as B cpuConfig :: IO MConfig cpuConfig = mkMConfig "Cpu: <total>" -- template - ["total","user","nice","system","idle"] -- available replacements + ["bar","total","user","nice","system","idle"] -- available replacements cpuData :: IO [Float] cpuData = do s <- B.readFile "/proc/stat" @@ -40,7 +40,11 @@ parseCPU = formatCpu :: [Float] -> Monitor [String] formatCpu [] = return [""] -formatCpu xs = showPercentsWithColors $ (foldr (+) 0 $ take 3 xs) : xs +formatCpu xs = do + let t = foldr (+) 0 $ take 3 xs + b <- showPercentBar (100 * t) t + ps <- showPercentsWithColors (t:xs) + return (b:ps) runCpu :: [String] -> Monitor String runCpu _ = diff --git a/Plugins/Monitors/Disk.hs b/Plugins/Monitors/Disk.hs index c0d8de7..f3c66a1 100644 --- a/Plugins/Monitors/Disk.hs +++ b/Plugins/Monitors/Disk.hs @@ -27,7 +27,8 @@ diskIOConfig :: IO MConfig diskIOConfig = mkMConfig "" ["total", "read", "write"] diskUConfig :: IO MConfig -diskUConfig = mkMConfig "" ["size", "free", "used", "freep", "usedp"] +diskUConfig = mkMConfig "" + ["size", "free", "used", "freep", "usedp", "freebar", "usedbar"] type DevName = String type Path = String @@ -123,7 +124,9 @@ runDiskU' tmp path = do fr = fromIntegral freep / 100 s <- zipWithM showWithColors' strs [100, freep, 100 - freep] sp <- showPercentsWithColors [fr, 1 - fr] - parseTemplate $ s ++ sp + fb <- showPercentBar (fromIntegral freep) fr + ub <- showPercentBar (fromIntegral $ 100 - freep) (1 - fr) + parseTemplate $ s ++ sp ++ [fb, ub] runDiskU :: [(String, String)] -> [String] -> Monitor String runDiskU disks _ = do diff --git a/Plugins/Monitors/Mem.hs b/Plugins/Monitors/Mem.hs index 16fc3a4..c6c4dc4 100644 --- a/Plugins/Monitors/Mem.hs +++ b/Plugins/Monitors/Mem.hs @@ -3,7 +3,7 @@ -- Module : Plugins.Monitors.Mem -- Copyright : (c) Andrea Rossato -- License : BSD-style (see LICENSE) --- +-- -- Maintainer : Andrea Rossato <andrea.rossato@unibz.it> -- Stability : unstable -- Portability : unportable @@ -19,29 +19,34 @@ import Plugins.Monitors.Common memConfig :: IO MConfig memConfig = mkMConfig "Mem: <usedratio>% (<cache>M)" -- template - ["total", "free", "buffer", -- available replacements - "cache", "rest", "used", "usedratio"] + ["usedbar", "freebar", "usedratio", "total", -- available replacements + "free", "buffer", "cache", "rest", "used"] fileMEM :: IO String fileMEM = readFile "/proc/meminfo" parseMEM :: IO [Float] parseMEM = - do file <- fileMEM + do file <- fileMEM let content = map words $ take 4 $ lines file [total, free, buffer, cache] = map (\line -> (read $ line !! 1 :: Float) / 1024) content rest = free + buffer + cache used = total - rest - usedratio = used * 100 / total - return [total, free, buffer, cache, rest, used, usedratio] + usedratio = used / total + return [usedratio, total, free, buffer, cache, rest, used] formatMem :: [Float] -> Monitor [String] -formatMem x = +formatMem (r:xs) = do let f n = showDigits 0 n - mapM (showWithColors f) x + rr = 100 * r + ub <- showPercentBar rr r + fb <- showPercentBar (100 - rr) (1 - r) + s <- mapM (showWithColors f) (rr:xs) + return (ub:fb:s) +formatMem _ = return $ replicate 8 "N/A" runMem :: [String] -> Monitor String runMem _ = do m <- io $ parseMEM l <- formatMem m - parseTemplate l + parseTemplate l diff --git a/Plugins/Monitors/MultiCpu.hs b/Plugins/Monitors/MultiCpu.hs index 360671b..223ff24 100644 --- a/Plugins/Monitors/MultiCpu.hs +++ b/Plugins/Monitors/MultiCpu.hs @@ -19,10 +19,10 @@ import qualified Data.ByteString.Lazy.Char8 as B import Data.List (isPrefixOf) multiCpuConfig :: IO MConfig -multiCpuConfig = mkMConfig - "Cpu: <total>" - [ k ++ n | n <- "" : map show [0 :: Int ..] - , k <- ["total","user","nice","system","idle"]] +multiCpuConfig = + mkMConfig "Cpu: <total>" + [ k ++ n | n <- "" : map show [0 :: Int ..] + , k <- ["bar","total","user","nice","system","idle"]] cpuData :: IO [[Float]] @@ -53,8 +53,11 @@ formatMultiCpus xs = fmap concat $ mapM formatCpu xs formatCpu :: [Float] -> Monitor [String] formatCpu xs - | length xs < 4 = showPercentsWithColors $ replicate 5 0.0 - | otherwise = showPercentsWithColors $ (foldr (+) 0 $ take 3 xs) : xs + | length xs < 4 = showPercentsWithColors $ replicate 6 0.0 + | otherwise = let t = foldr (+) 0 $ take 3 xs + in do b <- showPercentBar (100 * t) t + ps <- showPercentsWithColors (t:xs) + return (b:ps) runMultiCpu :: [String] -> Monitor String runMultiCpu _ = 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] diff --git a/Plugins/Monitors/Wireless.hs b/Plugins/Monitors/Wireless.hs index eb07afe..4ac0c10 100644 --- a/Plugins/Monitors/Wireless.hs +++ b/Plugins/Monitors/Wireless.hs @@ -18,14 +18,17 @@ import Plugins.Monitors.Common import IWlib wirelessConfig :: IO MConfig -wirelessConfig = mkMConfig "<essid> <quality>" ["essid", "quality"] +wirelessConfig = + mkMConfig "<essid> <quality>" ["essid", "quality", "qualitybar"] runWireless :: [String] -> Monitor String runWireless (iface:_) = do wi <- io $ getWirelessInfo iface let essid = wiEssid wi qlty = wiQuality wi + fqlty = fromIntegral qlty e = if essid == "" then "N/A" else essid q <- if qlty >= 0 then showWithColors show qlty else showWithPadding "" - parseTemplate [e, q] + qb <- showPercentBar fqlty (fqlty / 100) + parseTemplate [e, q, qb] runWireless _ = return ""
\ No newline at end of file @@ -297,7 +297,7 @@ Monitors have default aliases. - aliases to the interface name: so `Network "eth0" []` can be used as `%eth0%` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `dev`, `rx`, `tx` + `dev`, `rx`, `tx`, `rxbar`, `txbar` - Default template: `<dev>: <rx>|<tx>` `Wireless Interface Args RefreshRate` @@ -306,7 +306,7 @@ Monitors have default aliases. "wlan0" []` can be used as `%wlan0wi%` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `essid`, `quality` + `essid`, `quality`, `qualitybar` - Default template: `<essid> <quality>` - Requires the C library libiw (part of the wireless tools suite) installed in your system. In addition, to activate this plugin you @@ -318,7 +318,8 @@ Monitors have default aliases. - aliases to `memory` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `total`, `free`, `buffer`, `cache`, `rest`, `used`, `usedratio` + `total`, `free`, `buffer`, `cache`, `rest`, `used`, + `usedratio`, `usedbar`, `freebar` - Default template: `Mem: <usedratio>% (<cache>M)` `Swap Args RefreshRate` @@ -334,7 +335,7 @@ Monitors have default aliases. - aliases to `cpu` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `total`, `user`, `nice`, `system`, `idle` + `total`, `bar`, `user`, `nice`, `system`, `idle` - Default template: `Cpu: <total>` `MultiCpu Args RefreshRate` @@ -342,8 +343,8 @@ Monitors have default aliases. - aliases to `multicpu` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `total`, `user`, `nice`, `system`, `idle`, - `total0`, `user0`, `nice0`, `system0`, `idle0`, ... + `total`, `bar`, `user`, `nice`, `system`, `idle`, + `total0`, `bar0`, `user0`, `nice0`, `system0`, `idle0`, ... - Default template: `Cpu: <total>` `Battery Args RefreshRate` @@ -351,7 +352,7 @@ Monitors have default aliases. - aliases to `battery` - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `left` + `left`, `leftbar`, `status` - Default template: `Batt: <left>` `BatteryP Dirs Args RefreshRate` @@ -363,7 +364,7 @@ Monitors have default aliases. searched. - Args: the argument list (see below) - Variables that can be used with the `-t`/`--template` argument: - `left` + `left`, `leftbar`, `status` - Default template: `Batt: <left>` `TopCpu Args RefreshRate` @@ -393,10 +394,10 @@ Monitors have default aliases. - aliases to `disku` - Disks: list of pairs of the form (device or mount point, template), where the template can contain <size>, <free>, <used>, <freep> or - <usedp> for total, free, used, free percentage and used percentage - of the given file system capacity. Example: - `[("/", "<used>/<size>"), ("sdb1", "<usedp>")]` -- Args: the argument list (see below). `-t`/`--template` is ignored. + <usedp>, <freebar> or <usedbar> for total, free, used, free + percentage and used percentage of the given file system capacity. Example: + `[("/", "<used>/<size>"), ("sdb1", "<usedbar>")]` +- Args: the argument list (see above). `-t`/`--template` is ignored. - Default template: none (you must specify a template for each file system). `DiskIO Disks Args RefreshRate` @@ -406,7 +407,7 @@ Monitors have default aliases. where the template can contain <total>, <read>, <write> for total, read and write speed, respectively. Example: `[("/", "<read> <write>"), ("sdb1", "<total>")]` -- Args: the argument list (see below). `-t`/`--template` is ignored. +- Args: the argument list (see above). `-t`/`--template` is ignored. - Default template: none (you must specify a template for each file system). `Thermal Zone Args RefreshRate` |