summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins')
-rw-r--r--src/Plugins/Monitors.hs2
-rw-r--r--src/Plugins/Monitors/Batt.hs38
-rw-r--r--src/Plugins/Monitors/Bright.hs19
-rw-r--r--src/Plugins/Monitors/Cpu.hs38
-rw-r--r--src/Plugins/Monitors/Disk.hs79
-rw-r--r--src/Plugins/Monitors/MPD.hs9
-rw-r--r--src/Plugins/Monitors/Mem.hs45
-rw-r--r--src/Plugins/Monitors/MultiCpu.hs50
-rw-r--r--src/Plugins/Monitors/Net.hs55
-rw-r--r--src/Plugins/Monitors/Volume.hs13
-rw-r--r--src/Plugins/Monitors/Wireless.hs34
11 files changed, 312 insertions, 70 deletions
diff --git a/src/Plugins/Monitors.hs b/src/Plugins/Monitors.hs
index 68ec3de..bee3c06 100644
--- a/src/Plugins/Monitors.hs
+++ b/src/Plugins/Monitors.hs
@@ -156,7 +156,7 @@ instance Exec Monitors where
start (Uptime a r) = runM a uptimeConfig runUptime r
start (CatInt _ s a r) = runM a catIntConfig (runCatInt s) r
#ifdef IWLIB
- start (Wireless i a r) = runM (a ++ [i]) wirelessConfig runWireless r
+ start (Wireless i a r) = runM a wirelessConfig (runWireless i) r
#endif
#ifdef LIBMPD
start (MPD a r) = runMD a mpdConfig runMPD r mpdReady
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs
index ac8cb24..592deae 100644
--- a/src/Plugins/Monitors/Batt.hs
+++ b/src/Plugins/Monitors/Batt.hs
@@ -34,6 +34,9 @@ data BattOpts = BattOpts
, highThreshold :: Float
, onlineFile :: FilePath
, scale :: Float
+ , onDynamicString :: Maybe DynamicString
+ , offDynamicString :: Maybe DynamicString
+ , idleDynamicString :: Maybe DynamicString
}
defaultOpts :: BattOpts
@@ -49,6 +52,9 @@ defaultOpts = BattOpts
, highThreshold = -10
, onlineFile = "AC/online"
, scale = 1e6
+ , onDynamicString = Nothing
+ , offDynamicString = Nothing
+ , idleDynamicString = Nothing
}
options :: [OptDescr (BattOpts -> BattOpts)]
@@ -64,6 +70,12 @@ options =
, Option "H" ["hight"] (ReqArg (\x o -> o { highThreshold = read x }) "") ""
, Option "f" ["online"] (ReqArg (\x o -> o { onlineFile = x }) "") ""
, Option "s" ["scale"] (ReqArg (\x o -> o {scale = read x}) "") ""
+ , Option "" ["on-dynamic-string"] (ReqArg (\x o ->
+ o { onDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["off-dynamic-string"] (ReqArg (\x o ->
+ o { offDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["idle-dynamic-string"] (ReqArg (\x o ->
+ o { idleDynamicString = Just $ parseDynamicString x }) "") ""
]
parseOpts :: [String] -> IO BattOpts
@@ -72,7 +84,9 @@ parseOpts argv =
(o, _, []) -> return $ foldr id defaultOpts o
(_, _, errs) -> ioError . userError $ concat errs
-data Result = Result Float Float Float String | NA
+data Status = Charging | Discharging | Idle
+
+data Result = Result Float Float Float Status | NA
sysDir :: FilePath
sysDir = "/sys/class/power_supply"
@@ -80,7 +94,7 @@ sysDir = "/sys/class/power_supply"
battConfig :: IO MConfig
battConfig = mkMConfig
"Batt: <watts>, <left>% / <timeleft>" -- template
- ["leftbar", "leftvbar", "left", "acstatus", "timeleft", "watts"] -- replacements
+ ["leftbar", "leftvbar", "left", "acstatus", "timeleft", "watts", "leftdstr"] -- replacements
data Files = Files
{ fFull :: String
@@ -150,10 +164,10 @@ readBatteries opts bfs =
time = if idle then 0 else sum $ map time' bats
mwatts = if idle then 1 else sign * watts
time' b = (if ac then full b - now b else now b) / mwatts
- acstr | idle = idleString opts
- | ac = onString opts
- | otherwise = offString opts
- return $ if isNaN left then NA else Result left watts time acstr
+ acst | idle = Idle
+ | ac = Charging
+ | otherwise = Discharging
+ return $ if isNaN left then NA else Result left watts time acst
runBatt :: [String] -> Monitor String
runBatt = runBatt' ["BAT0","BAT1","BAT2"]
@@ -168,7 +182,8 @@ runBatt' bfs args = do
Result x w t s ->
do l <- fmtPercent x
ws <- fmtWatts w opts suffix d
- parseTemplate (l ++ [s, fmtTime $ floor t, ws])
+ si <- getDynamicString opts s x
+ parseTemplate (l ++ [fmtStatus opts s, fmtTime $ floor t, ws, si])
NA -> getConfigValue naString
where fmtPercent :: Float -> Monitor [String]
fmtPercent x = do
@@ -185,9 +200,18 @@ runBatt' bfs args = do
then minutes else '0' : minutes
where hours = show (x `div` 3600)
minutes = show ((x `mod` 3600) `div` 60)
+ fmtStatus opts Idle = idleString opts
+ fmtStatus opts Charging = onString opts
+ fmtStatus opts Discharging = offString opts
maybeColor Nothing str = str
maybeColor (Just c) str = "<fc=" ++ c ++ ">" ++ str ++ "</fc>"
color x o | x >= 0 = maybeColor (posColor o)
| -x >= highThreshold o = maybeColor (highWColor o)
| -x >= lowThreshold o = maybeColor (mediumWColor o)
| otherwise = maybeColor (lowWColor o)
+ getDynamicString opts status x = do
+ let x' = minimum [1, x]
+ case status of
+ Idle -> showDynamicString (idleDynamicString opts) x'
+ Charging -> showDynamicString (onDynamicString opts) x'
+ Discharging -> showDynamicString (offDynamicString opts) x'
diff --git a/src/Plugins/Monitors/Bright.hs b/src/Plugins/Monitors/Bright.hs
index d29c5a4..999b459 100644
--- a/src/Plugins/Monitors/Bright.hs
+++ b/src/Plugins/Monitors/Bright.hs
@@ -26,18 +26,22 @@ import Plugins.Monitors.Common
data BrightOpts = BrightOpts { subDir :: String
, currBright :: String
, maxBright :: String
+ , curBrightDynamicString :: Maybe DynamicString
}
defaultOpts :: BrightOpts
defaultOpts = BrightOpts { subDir = "acpi_video0"
, currBright = "actual_brightness"
, maxBright = "max_brightness"
+ , curBrightDynamicString = Nothing
}
options :: [OptDescr (BrightOpts -> BrightOpts)]
options = [ Option "D" ["device"] (ReqArg (\x o -> o { subDir = x }) "") ""
, Option "C" ["curr"] (ReqArg (\x o -> o { currBright = x }) "") ""
, Option "M" ["max"] (ReqArg (\x o -> o { maxBright = x }) "") ""
+ , Option "" ["brightness-dynamic-string"] (ReqArg (\x o ->
+ o { curBrightDynamicString = Just $ parseDynamicString x }) "") ""
]
-- from Batt.hs
@@ -52,7 +56,7 @@ sysDir = "/sys/class/backlight/"
brightConfig :: IO MConfig
brightConfig = mkMConfig "<percent>" -- template
- ["vbar", "percent", "bar"] -- replacements
+ ["vbar", "percent", "bar", "dstr"] -- replacements
data Files = Files { fCurr :: String
, fMax :: String
@@ -76,12 +80,13 @@ runBright args = do
c <- io $ readBright f
case f of
NoFiles -> return "hurz"
- _ -> fmtPercent c >>= parseTemplate
- where fmtPercent :: Float -> Monitor [String]
- fmtPercent c = do r <- showVerticalBar (100 * c) c
- s <- showPercentWithColors c
- t <- showPercentBar (100 * c) c
- return [r,s,t]
+ _ -> fmtPercent opts c >>= parseTemplate
+ where fmtPercent :: BrightOpts -> Float -> Monitor [String]
+ fmtPercent opts c = do r <- showVerticalBar (100 * c) c
+ s <- showPercentWithColors c
+ t <- showPercentBar (100 * c) c
+ d <- showDynamicString (curBrightDynamicString opts) c
+ return [r,s,t,d]
readBright :: Files -> IO Float
readBright NoFiles = return 0
diff --git a/src/Plugins/Monitors/Cpu.hs b/src/Plugins/Monitors/Cpu.hs
index 10d945f..5abde7e 100644
--- a/src/Plugins/Monitors/Cpu.hs
+++ b/src/Plugins/Monitors/Cpu.hs
@@ -18,11 +18,33 @@ module Plugins.Monitors.Cpu (startCpu) where
import Plugins.Monitors.Common
import qualified Data.ByteString.Lazy.Char8 as B
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
+import System.Console.GetOpt
+
+data CpuOpts = CpuOpts
+ { loadDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: CpuOpts
+defaultOpts = CpuOpts
+ { loadDynamicString = Nothing
+ }
+
+options :: [OptDescr (CpuOpts -> CpuOpts)]
+options =
+ [ Option "" ["load-dynamic-string"] (ReqArg (\x o ->
+ o { loadDynamicString = Just $ parseDynamicString x }) "") ""
+ ]
+
+parseOpts :: [String] -> IO CpuOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
cpuConfig :: IO MConfig
cpuConfig = mkMConfig
"Cpu: <total>%"
- ["bar","vbar","total","user","nice","system","idle","iowait"]
+ ["bar","vbar","dstr","total","user","nice","system","idle","iowait"]
type CpuDataRef = IORef [Int]
@@ -42,19 +64,21 @@ parseCpu cref =
percent = map ((/ tot) . fromIntegral) dif
return percent
-formatCpu :: [Float] -> Monitor [String]
-formatCpu [] = return $ replicate 8 ""
-formatCpu xs = do
+formatCpu :: CpuOpts -> [Float] -> Monitor [String]
+formatCpu _ [] = return $ replicate 8 ""
+formatCpu opts xs = do
let t = sum $ take 3 xs
b <- showPercentBar (100 * t) t
v <- showVerticalBar (100 * t) t
+ d <- showDynamicString (loadDynamicString opts) t
ps <- showPercentsWithColors (t:xs)
- return (b:v:ps)
+ return (b:v:d:ps)
runCpu :: CpuDataRef -> [String] -> Monitor String
-runCpu cref _ =
+runCpu cref argv =
do c <- io (parseCpu cref)
- l <- formatCpu c
+ opts <- io $ parseOpts argv
+ l <- formatCpu opts c
parseTemplate l
startCpu :: [String] -> Int -> (String -> IO ()) -> IO ()
diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs
index b43aede..e020c85 100644
--- a/src/Plugins/Monitors/Disk.hs
+++ b/src/Plugins/Monitors/Disk.hs
@@ -25,16 +25,67 @@ import qualified Data.ByteString.Lazy.Char8 as B
import Data.List (isPrefixOf, find)
import Data.Maybe (catMaybes)
import System.Directory (canonicalizePath, doesFileExist)
+import System.Console.GetOpt
+
+data DiskIOOpts = DiskIOOpts
+ { totalDynamicString :: Maybe DynamicString
+ , writeDynamicString :: Maybe DynamicString
+ , readDynamicString :: Maybe DynamicString
+ }
+
+parseDiskIOOpts :: [String] -> IO DiskIOOpts
+parseDiskIOOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
+ where defaultOpts = DiskIOOpts
+ { totalDynamicString = Nothing
+ , writeDynamicString = Nothing
+ , readDynamicString = Nothing
+ }
+ options =
+ [ Option "" ["total-dynamic-string"] (ReqArg (\x o ->
+ o { totalDynamicString = Just $ parseDynamicString x}) "") ""
+ , Option "" ["write-dynamic-string"] (ReqArg (\x o ->
+ o { writeDynamicString = Just $ parseDynamicString x}) "") ""
+ , Option "" ["read-dynamic-string"] (ReqArg (\x o ->
+ o { readDynamicString = Just $ parseDynamicString x}) "") ""
+ ]
diskIOConfig :: IO MConfig
diskIOConfig = mkMConfig "" ["total", "read", "write"
,"totalbar", "readbar", "writebar"
,"totalvbar", "readvbar", "writevbar"
+ ,"totaldstr", "readdstr", "writedstr"
]
+data DiskUOpts = DiskUOpts
+ { freeDynamicString :: Maybe DynamicString
+ , usedDynamicString :: Maybe DynamicString
+ }
+
+parseDiskUOpts :: [String] -> IO DiskUOpts
+parseDiskUOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
+ where defaultOpts = DiskUOpts
+ { freeDynamicString = Nothing
+ , usedDynamicString = Nothing
+ }
+ options =
+ [ Option "" ["free-dynamic-string"] (ReqArg (\x o ->
+ o { freeDynamicString = Just $ parseDynamicString x}) "") ""
+ , Option "" ["used-dynamic-string"] (ReqArg (\x o ->
+ o { usedDynamicString = Just $ parseDynamicString x}) "") ""
+ ]
+
diskUConfig :: IO MConfig
diskUConfig = mkMConfig ""
- ["size", "free", "used", "freep", "usedp", "freebar", "freevbar", "usedbar", "usedvbar"]
+ [ "size", "free", "used", "freep", "usedp"
+ , "freebar", "freevbar", "freedstr"
+ , "usedbar", "usedvbar", "useddstr"
+ ]
type DevName = String
type Path = String
@@ -127,19 +178,22 @@ devTemplates disks mounted dat =
Nothing -> [0, 0, 0]
Just (_, xs) -> xs
-runDiskIO' :: (String, [Float]) -> Monitor String
-runDiskIO' (tmp, xs) = do
+runDiskIO' :: DiskIOOpts -> (String, [Float]) -> Monitor String
+runDiskIO' opts (tmp, xs) = do
s <- mapM (showWithColors speedToStr) xs
b <- mapM (showLogBar 0.8) xs
vb <- mapM (showLogVBar 0.8) xs
+ dstr <- mapM (\(f,v) -> showLogDynamicString (f opts) 0.8 v)
+ $ zip [totalDynamicString, readDynamicString, writeDynamicString] xs
setConfigValue tmp template
- parseTemplate $ s ++ b ++ vb
+ parseTemplate $ s ++ b ++ vb ++ dstr
runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String
-runDiskIO dref disks _ = do
+runDiskIO dref disks argv = do
+ opts <- io $ parseDiskIOOpts argv
dev <- io $ mountedOrDiskDevices (map fst disks)
dat <- io $ mountedData dref (map fst dev)
- strs <- mapM runDiskIO' $ devTemplates disks dev dat
+ strs <- mapM (runDiskIO' opts) $ devTemplates disks dev dat
return $ unwords strs
startDiskIO :: [(String, String)] ->
@@ -160,8 +214,8 @@ fsStats path = do
used = fsStatBytesUsed f
in return [tot, free, used]
-runDiskU' :: String -> String -> Monitor String
-runDiskU' tmp path = do
+runDiskU' :: DiskUOpts -> String -> String -> Monitor String
+runDiskU' opts tmp path = do
setConfigValue tmp template
[total, free, diff] <- io (handle ign $ fsStats path)
let strs = map sizeToStr [free, diff]
@@ -171,14 +225,17 @@ runDiskU' tmp path = do
sp <- showPercentsWithColors [fr, 1 - fr]
fb <- showPercentBar (fromIntegral freep) fr
fvb <- showVerticalBar (fromIntegral freep) fr
+ fdstr <- showDynamicString (freeDynamicString opts) fr
ub <- showPercentBar (fromIntegral $ 100 - freep) (1 - fr)
uvb <- showVerticalBar (fromIntegral $ 100 - freep) (1 - fr)
- parseTemplate $ [sizeToStr total] ++ s ++ sp ++ [fb,fvb,ub,uvb]
+ udstr <- showDynamicString (usedDynamicString opts) (1 - fr)
+ parseTemplate $ [sizeToStr total] ++ s ++ sp ++ [fb,fvb,fdstr,ub,uvb,udstr]
where ign = const (return [0, 0, 0]) :: SomeException -> IO [Integer]
runDiskU :: [(String, String)] -> [String] -> Monitor String
-runDiskU disks _ = do
+runDiskU disks argv = do
devs <- io $ mountedDevices (map fst disks)
- strs <- mapM (\(d, p) -> runDiskU' (findTempl d p disks) p) devs
+ opts <- io $ parseDiskUOpts argv
+ strs <- mapM (\(d, p) -> runDiskU' opts (findTempl d p disks) p) devs
return $ unwords strs
diff --git a/src/Plugins/Monitors/MPD.hs b/src/Plugins/Monitors/MPD.hs
index ac976f2..3c1615e 100644
--- a/src/Plugins/Monitors/MPD.hs
+++ b/src/Plugins/Monitors/MPD.hs
@@ -22,7 +22,7 @@ import Control.Concurrent (threadDelay)
mpdConfig :: IO MConfig
mpdConfig = mkMConfig "MPD: <state>"
- [ "bar", "vbar", "state", "statei", "volume", "length"
+ [ "bar", "vbar", "dstr", "state", "statei", "volume", "length"
, "lapsed", "remaining", "plength", "ppos", "file"
, "name", "artist", "composer", "performer"
, "album", "title", "track", "genre"
@@ -32,6 +32,7 @@ data MOpts = MOpts
{ mPlaying :: String
, mStopped :: String
, mPaused :: String
+ , mLapsedDynamicString :: Maybe DynamicString
}
defaultOpts :: MOpts
@@ -39,6 +40,7 @@ defaultOpts = MOpts
{ mPlaying = ">>"
, mStopped = "><"
, mPaused = "||"
+ , mLapsedDynamicString = Nothing
}
options :: [OptDescr (MOpts -> MOpts)]
@@ -46,6 +48,8 @@ options =
[ Option "P" ["playing"] (ReqArg (\x o -> o { mPlaying = x }) "") ""
, Option "S" ["stopped"] (ReqArg (\x o -> o { mStopped = x }) "") ""
, Option "Z" ["paused"] (ReqArg (\x o -> o { mPaused = x }) "") ""
+ , Option "" ["lapsed-dynamic-string"] (ReqArg (\x o ->
+ o { mLapsedDynamicString = Just $ parseDynamicString x }) "") ""
]
runMPD :: [String] -> Monitor String
@@ -87,7 +91,8 @@ parseMPD (Right st) song opts = do
songData <- parseSong song
bar <- showPercentBar (100 * b) b
vbar <- showVerticalBar (100 * b) b
- return $ [bar, vbar, ss, si, vol, len, lap, remain, plen, ppos] ++ songData
+ dstr <- showDynamicString (mLapsedDynamicString opts) b
+ return $ [bar, vbar, dstr, ss, si, vol, len, lap, remain, plen, ppos] ++ songData
where s = M.stState st
ss = show s
si = stateGlyph s opts
diff --git a/src/Plugins/Monitors/Mem.hs b/src/Plugins/Monitors/Mem.hs
index db2e5de..7524989 100644
--- a/src/Plugins/Monitors/Mem.hs
+++ b/src/Plugins/Monitors/Mem.hs
@@ -16,12 +16,38 @@ module Plugins.Monitors.Mem (memConfig, runMem, totalMem, usedMem) where
import Plugins.Monitors.Common
import qualified Data.Map as M
+import System.Console.GetOpt
+
+data MemOpts = MemOpts
+ { usedDynamicString :: Maybe DynamicString
+ , freeDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: MemOpts
+defaultOpts = MemOpts
+ { usedDynamicString = Nothing
+ , freeDynamicString = Nothing
+ }
+
+options :: [OptDescr (MemOpts -> MemOpts)]
+options =
+ [ Option "" ["used-dynamic-string"] (ReqArg (\x o ->
+ o { usedDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["free-dynamic-string"] (ReqArg (\x o ->
+ o { freeDynamicString = Just $ parseDynamicString x }) "") ""
+ ]
+
+parseOpts :: [String] -> IO MemOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
memConfig :: IO MConfig
memConfig = mkMConfig
"Mem: <usedratio>% (<cache>M)" -- template
- ["usedbar", "usedvbar", "freebar", "freevbar", "usedratio", "freeratio", "total",
- "free", "buffer", "cache", "rest", "used"] -- available replacements
+ ["usedbar", "usedvbar", "useddstr", "freebar", "freevbar", "freedstr", "usedratio", "freeratio",
+ "total", "free", "buffer", "cache", "rest", "used"] -- available replacements
fileMEM :: IO String
fileMEM = readFile "/proc/meminfo"
@@ -44,22 +70,25 @@ totalMem = fmap ((*1024) . (!!1)) parseMEM
usedMem :: IO Float
usedMem = fmap ((*1024) . (!!6)) parseMEM
-formatMem :: [Float] -> Monitor [String]
-formatMem (r:fr:xs) =
+formatMem :: MemOpts -> [Float] -> Monitor [String]
+formatMem opts (r:fr:xs) =
do let f = showDigits 0
rr = 100 * r
ub <- showPercentBar rr r
uvb <- showVerticalBar rr r
+ udstr <- showDynamicString (usedDynamicString opts) r
fb <- showPercentBar (100 - rr) (1 - r)
fvb <- showVerticalBar (100 - rr) ( 1 - r)
+ fdstr <- showDynamicString (freeDynamicString opts) (1 - r)
rs <- showPercentWithColors r
fs <- showPercentWithColors fr
s <- mapM (showWithColors f) xs
- return (ub:uvb:fb:fvb:rs:fs:s)
-formatMem _ = replicate 10 `fmap` getConfigValue naString
+ return (ub:uvb:udstr:fb:fvb:fdstr:rs:fs:s)
+formatMem _ _ = replicate 10 `fmap` getConfigValue naString
runMem :: [String] -> Monitor String
-runMem _ =
+runMem argv =
do m <- io parseMEM
- l <- formatMem m
+ opts <- io $ parseOpts argv
+ l <- formatMem opts m
parseTemplate l
diff --git a/src/Plugins/Monitors/MultiCpu.hs b/src/Plugins/Monitors/MultiCpu.hs
index 150fb7e..9f8c191 100644
--- a/src/Plugins/Monitors/MultiCpu.hs
+++ b/src/Plugins/Monitors/MultiCpu.hs
@@ -19,9 +19,35 @@ import Control.Applicative ((<$>))
import qualified Data.ByteString.Lazy.Char8 as B
import Data.List (isPrefixOf, transpose, unfoldr)
import Data.IORef (IORef, newIORef, readIORef, writeIORef)
+import System.Console.GetOpt
+
+data MultiCpuOpts = MultiCpuOpts
+ { loadDynamicStrings :: [DynamicString]
+ , loadDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: MultiCpuOpts
+defaultOpts = MultiCpuOpts
+ { loadDynamicStrings = []
+ , loadDynamicString = Nothing
+ }
+
+options :: [OptDescr (MultiCpuOpts -> MultiCpuOpts)]
+options =
+ [ Option "" ["load-dynamic-string"] (ReqArg (\x o ->
+ o { loadDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["load-dynamic-strings"] (ReqArg (\x o ->
+ o { loadDynamicStrings = parseDynamicString x : loadDynamicStrings o }) "") ""
+ ]
+
+parseOpts :: [String] -> IO MultiCpuOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
variables :: [String]
-variables = ["bar", "vbar","total","user","nice","system","idle"]
+variables = ["bar", "vbar","dstr","total","user","nice","system","idle"]
vNum :: Int
vNum = length variables
@@ -55,18 +81,23 @@ percent b a = if tot > 0 then map (/ tot) $ take 4 dif else [0, 0, 0, 0]
where dif = zipWith (-) b a
tot = sum dif
-formatMultiCpus :: [[Float]] -> Monitor [String]
-formatMultiCpus [] = return []
-formatMultiCpus xs = concat <$> mapM formatCpu xs
+formatMultiCpus :: MultiCpuOpts -> [[Float]] -> Monitor [String]
+formatMultiCpus _ [] = return []
+formatMultiCpus opts xs = concat <$> mapM (\(i, x) -> formatCpu opts i x) (zip [0..] xs)
-formatCpu :: [Float] -> Monitor [String]
-formatCpu xs
+formatCpu :: MultiCpuOpts -> Int -> [Float] -> Monitor [String]
+formatCpu opts i xs
| length xs < 4 = showPercentsWithColors $ replicate vNum 0.0
| otherwise = let t = sum $ take 3 xs
in do b <- showPercentBar (100 * t) t
h <- showVerticalBar (100 * t) t
+ d <- showDynamicString tryString t
ps <- showPercentsWithColors (t:xs)
- return (b:h:ps)
+ return (b:h:d:ps)
+ where tryString
+ | i == 0 = loadDynamicString opts
+ | i <= length (loadDynamicStrings opts) = Just $ (loadDynamicStrings opts) !! (i - 1)
+ | otherwise = Nothing
splitEvery :: (Eq a) => Int -> [a] -> [[a]]
splitEvery n = unfoldr (\x -> if null x then Nothing else Just $ splitAt n x)
@@ -79,9 +110,10 @@ formatAutoCpus [] = return $ replicate vNum ""
formatAutoCpus xs = return $ map unwords (groupData xs)
runMultiCpu :: CpuDataRef -> [String] -> Monitor String
-runMultiCpu cref _ =
+runMultiCpu cref argv =
do c <- io $ parseCpuData cref
- l <- formatMultiCpus c
+ opts <- io $ parseOpts argv
+ l <- formatMultiCpus opts c
a <- formatAutoCpus l
parseTemplate $ a ++ l
diff --git a/src/Plugins/Monitors/Net.hs b/src/Plugins/Monitors/Net.hs
index 51c760c..137770c 100644
--- a/src/Plugins/Monitors/Net.hs
+++ b/src/Plugins/Monitors/Net.hs
@@ -25,9 +25,35 @@ import Data.Time.Clock (UTCTime, getCurrentTime, diffUTCTime)
import Control.Monad (forM, filterM, liftM)
import System.Directory (getDirectoryContents, doesFileExist)
import System.FilePath ((</>))
+import System.Console.GetOpt
import qualified Data.ByteString.Lazy.Char8 as B
+data NetOpts = NetOpts
+ { rxDynamicString :: Maybe DynamicString
+ , txDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: NetOpts
+defaultOpts = NetOpts
+ { rxDynamicString = Nothing
+ , txDynamicString = Nothing
+ }
+
+options :: [OptDescr (NetOpts -> NetOpts)]
+options =
+ [ Option "" ["rx-dynamic-string"] (ReqArg (\x o ->
+ o { rxDynamicString = Just $ parseDynamicString x }) "") ""
+ , Option "" ["tx-dynamic-string"] (ReqArg (\x o ->
+ o { txDynamicString = Just $ parseDynamicString x }) "") ""
+ ]
+
+parseOpts :: [String] -> IO NetOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
+
data UnitPerSec = Bs | KBs | MBs | GBs deriving (Eq,Enum,Ord)
data NetValue = NetValue Float UnitPerSec deriving (Eq,Show)
@@ -62,7 +88,7 @@ instance Ord NetDev where
netConfig :: IO MConfig
netConfig = mkMConfig
"<dev>: <rx>KB|<tx>KB" -- template
- ["dev", "rx", "tx", "rxbar", "rxvbar", "txbar", "txvbar"] -- available replacements
+ ["dev", "rx", "tx", "rxbar", "rxvbar", "rxdstr", "txbar", "txvbar", "txdstr"] -- available replacements
operstateDir :: String -> FilePath
operstateDir d = "/sys/class/net" </> d </> "operstate"
@@ -106,8 +132,8 @@ findNetDev dev = do
isDev (NI d) = d == dev
isDev NA = False
-formatNet :: Float -> Monitor (String, String, String)
-formatNet d = do
+formatNet :: Maybe DynamicString -> Float -> Monitor (String, String, String, String)
+formatNet mdstr d = do
s <- getConfigValue useSuffix
dd <- getConfigValue decDigits
let str True v = showDigits dd d' ++ show u
@@ -115,16 +141,17 @@ formatNet d = do
str False v = showDigits dd $ v / 1024
b <- showLogBar 0.9 d
vb <- showLogVBar 0.9 d
+ dstr <- showLogDynamicString mdstr 0.9 d
x <- showWithColors (str s) d
- return (x, b, vb)
+ return (x, b, vb, dstr)
-printNet :: NetDev -> Monitor String
-printNet nd =
+printNet :: NetOpts -> NetDev -> Monitor String
+printNet opts nd =
case nd of
ND d r t -> do
- (rx, rb, rvb) <- formatNet r
- (tx, tb, tvb) <- formatNet t
- parseTemplate [d,rx,tx,rb,rvb,tb,tvb]
+ (rx, rb, rvb, rdstr) <- formatNet (rxDynamicString opts) r
+ (tx, tb, tvb, tdstr) <- formatNet (txDynamicString opts) t
+ parseTemplate [d,rx,tx,rb,rvb,rdstr,tb,tvb,tdstr]
NI _ -> return ""
NA -> getConfigValue naString
@@ -144,13 +171,19 @@ parseNet nref nd = do
return $ diffRate n0 n1
runNet :: NetDevRef -> String -> [String] -> Monitor String
-runNet nref i _ = io (parseNet nref i) >>= printNet
+runNet nref i argv = do
+ dev <- io $ parseNet nref i
+ opts <- io $ parseOpts argv
+ printNet opts dev
parseNets :: [(NetDevRef, String)] -> IO [NetDev]
parseNets = mapM $ uncurry parseNet
runNets :: [(NetDevRef, String)] -> [String] -> Monitor String
-runNets refs _ = io (parseActive refs) >>= printNet
+runNets refs argv = do
+ dev <- io $ parseActive refs
+ opts <- io $ parseOpts argv
+ printNet opts dev
where parseActive refs' = liftM selectActive (parseNets refs')
selectActive = maximum
diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs
index 22b7f6c..2787a3c 100644
--- a/src/Plugins/Monitors/Volume.hs
+++ b/src/Plugins/Monitors/Volume.hs
@@ -24,7 +24,7 @@ import System.Console.GetOpt
volumeConfig :: IO MConfig
volumeConfig = mkMConfig "Vol: <volume>% <status>"
- ["volume", "volumebar", "volumevbar", "dB","status"]
+ ["volume", "volumebar", "volumevbar", "dB","status", "volumedstr"]
data VolumeOpts = VolumeOpts
@@ -34,6 +34,7 @@ data VolumeOpts = VolumeOpts
, offColor :: Maybe String
, highDbThresh :: Float
, lowDbThresh :: Float
+ , volumeDynamicString :: Maybe DynamicString
}
defaultOpts :: VolumeOpts
@@ -44,6 +45,7 @@ defaultOpts = VolumeOpts
, offColor = Just "red"
, highDbThresh = -5.0
, lowDbThresh = -30.0
+ , volumeDynamicString = Nothing
}
options :: [OptDescr (VolumeOpts -> VolumeOpts)]
@@ -54,6 +56,8 @@ options =
, Option "" ["highd"] (ReqArg (\x o -> o { highDbThresh = read x }) "") ""
, Option "C" ["onc"] (ReqArg (\x o -> o { onColor = Just x }) "") ""
, Option "c" ["offc"] (ReqArg (\x o -> o { offColor = Just x }) "") ""
+ , Option "" ["volume-dynamic-string"] (ReqArg (\x o ->
+ o { volumeDynamicString = Just $ parseDynamicString x }) "") ""
]
parseOpts :: [String] -> IO VolumeOpts
@@ -80,6 +84,10 @@ formatVolVBar :: Integer -> Integer -> Integer -> Monitor String
formatVolVBar lo hi v =
showVerticalBar (100 * x) x where x = percent v lo hi
+formatVolDStr :: Maybe DynamicString -> Integer -> Integer -> Integer -> Monitor String
+formatVolDStr dstr lo hi v =
+ showDynamicString dstr $ percent v lo hi
+
switchHelper :: VolumeOpts
-> (VolumeOpts -> Maybe String)
-> (VolumeOpts -> String)
@@ -126,7 +134,8 @@ runVolume mixerName controlName argv = do
v <- liftMonitor $ liftM3 formatVolVBar lo hi val
d <- getFormatDB opts db
s <- getFormatSwitch opts sw
- parseTemplate [p, b, v, d, s]
+ dstr <- liftMonitor $ liftM3 (formatVolDStr $ volumeDynamicString opts) lo hi val
+ parseTemplate [p, b, v, d, s, dstr]
where
diff --git a/src/Plugins/Monitors/Wireless.hs b/src/Plugins/Monitors/Wireless.hs
index c6e6b44..c87bec6 100644
--- a/src/Plugins/Monitors/Wireless.hs
+++ b/src/Plugins/Monitors/Wireless.hs
@@ -14,15 +14,39 @@
module Plugins.Monitors.Wireless (wirelessConfig, runWireless) where
+import System.Console.GetOpt
+
import Plugins.Monitors.Common
import IWlib
+data WirelessOpts = WirelessOpts
+ { qualityDynamicString :: Maybe DynamicString
+ }
+
+defaultOpts :: WirelessOpts
+defaultOpts = WirelessOpts
+ { qualityDynamicString = Nothing
+ }
+
+options :: [OptDescr (WirelessOpts -> WirelessOpts)]
+options =
+ [ Option "" ["quality-dynamic-string"] (ReqArg (\d opts ->
+ opts { qualityDynamicString = Just $ parseDynamicString d }) "") ""
+ ]
+
+parseOpts :: [String] -> IO WirelessOpts
+parseOpts argv =
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
+
wirelessConfig :: IO MConfig
wirelessConfig =
- mkMConfig "<essid> <quality>" ["essid", "quality", "qualitybar", "qualityvbar"]
+ mkMConfig "<essid> <quality>" ["essid", "quality", "qualitybar", "qualityvbar", "qualitydstr"]
-runWireless :: [String] -> Monitor String
-runWireless (iface:_) = do
+runWireless :: String -> [String] -> Monitor String
+runWireless iface args = do
+ opts <- io $ parseOpts args
wi <- io $ getWirelessInfo iface
na <- getConfigValue naString
let essid = wiEssid wi
@@ -34,5 +58,5 @@ runWireless (iface:_) = do
else showWithPadding ""
qb <- showPercentBar qlty (qlty / 100)
qvb <- showVerticalBar qlty (qlty / 100)
- parseTemplate [ep, q, qb, qvb]
-runWireless _ = getConfigValue naString
+ qdstr <- showDynamicString (qualityDynamicString opts) (qlty / 100)
+ parseTemplate [ep, q, qb, qvb, qdstr]