From e8e4415b7eba49d2d6ddb18ab13b3151c9a787bd Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Thu, 4 Sep 2014 22:53:06 +0400 Subject: Add DynamicString as an alternative to vbars. * DynamicString is an Int -> String which takes a value from 0..8 and produces a string with this value embedded. Usefull for replacing vbars with icons: an icon per one of 9 states. * API is similar to that of vbar. * Default parser of DynamicString produces a function of `i` to a string that replaces all occurences of "%%" with `show i` --- src/Plugins/Monitors/Common.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index 971de16..ed91c73 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -40,6 +40,8 @@ module Plugins.Monitors.Common ( , parseTemplate' -- ** String Manipulation -- $strings + , DynamicString + , parseDynamicString , padString , showWithPadding , showWithColors @@ -48,8 +50,10 @@ module Plugins.Monitors.Common ( , showPercentsWithColors , showPercentBar , showVerticalBar + , showDynamicString , showLogBar , showLogVBar + , showLogDynamicString , showWithUnits , takeDigits , showDigits @@ -348,6 +352,18 @@ combine m ((s,ts,ss):xs) = -- $strings +type DynamicString = Int -> String + +parseDynamicString :: String -> DynamicString +parseDynamicString path = + let spl = splitOnPercent path + in \i -> concat $ intersperse (show i) spl + where splitOnPercent [] = [[]] + splitOnPercent ('%':'%':xs) = [] : splitOnPercent xs + splitOnPercent (x:xs) = + let rest = splitOnPercent xs + in (x : head rest) : tail rest + type Pos = (Int, Int) takeDigits :: Int -> Float -> Float @@ -453,6 +469,15 @@ showPercentBar v x = do s <- colorizeString v (take len $ cycle bf) return $ s ++ take (bw - len) (cycle bb) +showDynamicString :: Maybe DynamicString -> Float -> Monitor String +showDynamicString Nothing _ = return "" +showDynamicString (Just str) x = return $ str $ convert $ 100 * x + where convert val + | t <= 0 = 0 + | t > 8 = 8 + | otherwise = t + where t = round val `div` 12 + showVerticalBar :: Float -> Float -> Monitor String showVerticalBar v x = colorizeString v [convert $ 100 * x] where convert :: Float -> Char @@ -485,3 +510,14 @@ showLogVBar f v = do | x <= ll = 1 / bw | otherwise = f + logBase 2 (x / hh) / bw showVerticalBar v $ choose v + +showLogDynamicString :: Maybe DynamicString -> Float -> Float -> Monitor String +showLogDynamicString str f v = do + h <- fromIntegral `fmap` getConfigValue high + l <- fromIntegral `fmap` getConfigValue low + bw <- fromIntegral `fmap` getConfigValue barWidth + let [ll, hh] = sort [l, h] + choose x | x == 0.0 = 0 + | x <= ll = 1 / bw + | otherwise = f + logBase 2 (x / hh) / bw + showDynamicString str $ choose v -- cgit v1.2.3 From e590f14593728b8afc2b77e8be356e5c06428107 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Sun, 7 Sep 2014 22:24:00 +0400 Subject: Implement DynamicString for Monitors supporting vbar. * Batt * Bright * Cpu * Disk * MPD * Mem * MultiCpu * Net * Volume * Wireless --- src/Plugins/Monitors.hs | 2 +- src/Plugins/Monitors/Batt.hs | 38 +++++++++++++++---- src/Plugins/Monitors/Bright.hs | 19 ++++++---- src/Plugins/Monitors/Cpu.hs | 38 +++++++++++++++---- src/Plugins/Monitors/Disk.hs | 79 ++++++++++++++++++++++++++++++++++------ src/Plugins/Monitors/MPD.hs | 9 ++++- src/Plugins/Monitors/Mem.hs | 45 +++++++++++++++++++---- src/Plugins/Monitors/MultiCpu.hs | 50 ++++++++++++++++++++----- src/Plugins/Monitors/Net.hs | 55 ++++++++++++++++++++++------ src/Plugins/Monitors/Volume.hs | 13 ++++++- src/Plugins/Monitors/Wireless.hs | 34 ++++++++++++++--- 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: , % / " -- 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 = "" ++ str ++ "" 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 "" -- 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: %" - ["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: " - [ "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: % (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 ": KB|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", "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", "qualitybar", "qualityvbar"] + mkMConfig " " ["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] -- cgit v1.2.3 From e26731b1fc292a16230f6517aa292dd3973929ae Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Tue, 9 Sep 2014 00:18:13 +0400 Subject: Add documentation for DynamicStrings. --- readme.md | 109 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 32 deletions(-) diff --git a/readme.md b/readme.md index 2ddfb41..cb3b9cc 100644 --- a/readme.md +++ b/readme.md @@ -542,6 +542,23 @@ Monitors have default aliases. The sections below describe every monitor in turn, but before we provide a list of the configuration options (or *monitor arguments*) they all share. +### Dynamic Strings + +Some monitors allow usage of strings that depend on some integer value +from 0 to 8 by replacing all occurences of `"%%"` with it +(i.e. `""` will be interpreted +as `""` when the value is `3`, also `"%"` is interpreted +as `"%"`, `"%%"` as `"3"`, `"%%%"` as `"3%"`, `"%%%%"` as `"33"` and so on). Essentially +it allows to replace vertical bars with custom icons. For example, + + Run Brightness + [ "-t", "" + , "--" + , "--brightness-dynamic-string", "" + ] 30 + +Will display `bright_0.xpm` to `bright_8.xpm` depending on current brightness +value. ### Default Monitor Arguments @@ -693,33 +710,38 @@ something like: - Aliases to the interface name: so `Network "eth0" []` can be used as `%eth0%` -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--rx-dynamic-string`: dynamic string for reception rate in `rxdstr`. + - `--tx-dynamic-string`: dynamic string for transmission rate in `txdstr`. - Variables that can be used with the `-t`/`--template` argument: - `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `txbar`, `txvbar`. Reception - and transmission rates (`rx` and `tx`) are displayed by default as - Kb/s, without any suffixes, but you can set the `-S` to "True" to - make them displayed with adaptive units (Kb/s, Mb/s, etc.). + `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxdstr`, `txbar`, `txvbar`, + `txdstr`. Reception and transmission rates (`rx` and `tx`) are displayed + by default as Kb/s, without any suffixes, but you can set the `-S` to + "True" to make them displayed with adaptive units (Kb/s, Mb/s, etc.). - Default template: `: KB|KB` ### `DynNetwork Args RefreshRate` - Active interface is detected automatically - Aliases to "dynnetwork" -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--rx-dynamic-string`: dynamic string for reception rate in `rxdstr`. + - `--tx-dynamic-string`: dynamic string for transmission rate in `txdstr`. - Variables that can be used with the `-t`/`--template` argument: - `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `txbar`, `txvbar`. 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"). + `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxdstr`, `txbar`, `txvbar`, + `txdstr`. 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: `: KB|KB` ### `Wireless Interface Args RefreshRate` - Aliases to the interface name with the suffix "wi": thus, `Wireless "wlan0" []` can be used as `%wlan0wi%` -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--quality-dynamic-string`: dynamic string for connection quality in `qualitydstr`. - Variables that can be used with the `-t`/`--template` argument: - `essid`, `quality`, `qualitybar`, `qualityvbar` + `essid`, `quality`, `qualitybar`, `qualityvbar`, `qualitydstr` - Default template: ` ` - Requires the C library [iwlib] (part of the wireless tools suite) installed in your system. In addition, to activate this plugin you @@ -728,10 +750,13 @@ something like: ### `Memory Args RefreshRate` - Aliases to `memory` -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--used-dynamic-string`: dynamic string for used memory ratio in `useddstr`. + - `--free-dynamic-string`: dynamic string for free memory ratio in `freedstr`. - Variables that can be used with the `-t`/`--template` argument: `total`, `free`, `buffer`, `cache`, `rest`, `used`, - `usedratio`, `usedbar`, `usedvbar`, `freeratio`, `freebar`, `freevbar` + `usedratio`, `usedbar`, `usedvbar`, `useddstr`, + `freeratio`, `freebar`, `freevbar`, `freedstr` - Default template: `Mem: % (M)` ### `Swap Args RefreshRate` @@ -745,19 +770,24 @@ something like: ### `Cpu Args RefreshRate` - Aliases to `cpu` -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--load-dynamic-string`: dynamic string for cpu load in `dstr`. - Variables that can be used with the `-t`/`--template` argument: - `total`, `bar`, `vbar`, `user`, `nice`, `system`, `idle`, `iowait` + `total`, `bar`, `vbar`, `dstr`, `user`, `nice`, `system`, `idle`, `iowait` - Default template: `Cpu: %` ### `MultiCpu Args RefreshRate` - Aliases to `multicpu` -- Args: default monitor arguments +- Args: default monitor arguments, plus: + - `--load-dynamic-string`: dynamic string for overall cpu load in `dstr`. + - `--load-dynamic-strings`: dynamic string for each cpu load in `autodstr`, `dstr{i}`. + This option can be specified several times. nth option + corresponds to nth cpu. - Variables that can be used with the `-t`/`--template` argument: - `autototal`, `autobar`, `autovbar`, `autouser`, `autonice`, - `autosystem`, `autoidle`, `total`, `bar`, `vbar`, `user`, `nice`, - `system`, `idle`, `total0`, `bar0`, `vbar0`, `user0`, `nice0`, + `autototal`, `autobar`, `autovbar`, `autodstr`, `autouser`, `autonice`, + `autosystem`, `autoidle`, `total`, `bar`, `vbar`, `dstr`, `user`, `nice`, + `system`, `idle`, `total0`, `bar0`, `vbar0`, `dstr0`, `user0`, `nice0`, `system0`, `idle0`, ... The auto* variables automatically detect the number of CPUs on the system and display one entry for each. @@ -788,9 +818,15 @@ something like: - `-p`: color to display positive power (battery charging) - `-f`: file in `/sys/class/power_supply` with AC info (default: "AC/online") + - `--on-dynamic-string`: dynamic string for current battery charge + when AC is "on" in `leftdstr`. + - `--off-dynamic-string`: dynamic string for current battery charge + when AC is "off" in `leftdstr`. + - `--idle-dynamic-string`: dynamic string for current battery charge + when AC is "idle" in `leftdstr`. - Variables that can be used with the `-t`/`--template` argument: - `left`, `leftbar`, `leftvbar`, `timeleft`, `watts`, `acstatus` + `left`, `leftbar`, `leftvbar`, `leftdstr`, `timeleft`, `watts`, `acstatus` - Default template: `Batt: , % / ` - Example (note that you need "--" to separate regular monitor options from Battery's specific ones): @@ -863,10 +899,12 @@ more than one battery. - Aliases to `disku` - Disks: list of pairs of the form (device or mount point, template), where the template can contain ``, ``, ``, `` or - ``, ``, ``, `` or `` for total, - free, used, free percentage and used percentage of the given file system - capacity. -- Args: default monitor arguments. `-t`/`--template` is ignored. + ``, ``, ``, ``, ``, + `` or `` for total, free, used, free percentage and + used percentage of the given file system capacity. +- Args: default monitor arguments. `-t`/`--template` is ignored. Plus + - `--free-dynamic-string`: dynamic string for free disk space in `freedstr`. + - `--used-dynamic-string`: dynamic string for used disk space in `useddstr`. - Default template: none (you must specify a template for each file system). - Example: @@ -880,9 +918,13 @@ more than one battery. - Disks: list of pairs of the form (device or mount point, template), where the template can contain ``, ``, `` for total, read and write speed, respectively. There are also bar versions of each: - ``, ``, ``, ``, ``, and - ``. -- Args: default monitor arguments. `-t`/`--template` is ignored. + ``, ``, ``, + ``, ``, ``, + ``, ``, and ``. +- Args: default monitor arguments. `-t`/`--template` is ignored. Plus + - `--total-dynamic-string`: dynamic string for total disk I/O in ``. + - `--write-dynamic-string`: dynamic string for write disk I/O in ``. + - `--read-dynamic-string`: dynamic string for read disk I/O in ``. - Default template: none (you must specify a template for each file system). - Example: @@ -970,8 +1012,9 @@ more than one battery. - Long option: `--offc` - `--highd` _number_ High threshold for dB. Defaults to -5.0. - `--lowd` _number_ Low threshold for dB. Defaults to -30.0. + - `--volume-dynamic-string` _string_ dynamic string for current volume in `volumedstr`. - Variables that can be used with the `-t`/`--template` argument: - `volume`, `volumebar`, `volumevbar`, `dB`, `status` + `volume`, `volumebar`, `volumevbar`, `volumedstr`, `dB`, `status` - Note that `dB` might only return 0 on your system. This is known to happen on systems with a pulseaudio backend. - Default template: `Vol: % ` @@ -988,9 +1031,10 @@ more than one battery. `-P`, `-S` and `-Z`, with an string argument, to represent the playing, stopped and paused states in the `statei` template field. The environment variables `MPD_HOST` and `MPD_PORT` are used to configure the - mpd server to communicate with. + mpd server to communicate with. Also available: + - `lapsed-dynamic-string`: dynamic string for current track position in `dstr`. - Variables that can be used with the `-t`/`--template` argument: - `bar`, `vbar`, `state`, `statei`, `volume`, `length`, + `bar`, `vbar`, `dstr`, `state`, `statei`, `volume`, `length`, `lapsed`, `remaining`, `plength` (playlist length), `ppos` (playlist position), `name`, `artist`, `composer`, `performer`, @@ -1110,8 +1154,9 @@ more than one battery. actual_brightness) - `-M`: file with the maximum brightness (default: max_brightness) + - `--brightness-dynamic-string`: dynamic string for current brightness in `dstr`. - Variables that can be used with the `-t`/`--template` argument: - `vbar`, `percent`, `bar` + `vbar`, `percent`, `bar`, `dstr` - Default template: `` - Example: -- cgit v1.2.3 From f8b7b22253d72b7b6ecf83bac87a8cda41040f49 Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Wed, 24 Sep 2014 12:31:54 +0400 Subject: Rename dynamic string to icon pattern --- readme.md | 94 ++++++++++++++++++++-------------------- src/Plugins/Monitors/Batt.hs | 36 +++++++-------- src/Plugins/Monitors/Bright.hs | 12 ++--- src/Plugins/Monitors/Common.hs | 26 +++++------ src/Plugins/Monitors/Cpu.hs | 12 ++--- src/Plugins/Monitors/Disk.hs | 58 ++++++++++++------------- src/Plugins/Monitors/MPD.hs | 14 +++--- src/Plugins/Monitors/Mem.hs | 24 +++++----- src/Plugins/Monitors/MultiCpu.hs | 24 +++++----- src/Plugins/Monitors/Net.hs | 32 +++++++------- src/Plugins/Monitors/Volume.hs | 20 ++++----- src/Plugins/Monitors/Wireless.hs | 14 +++--- 12 files changed, 183 insertions(+), 183 deletions(-) diff --git a/readme.md b/readme.md index cb3b9cc..003ee2a 100644 --- a/readme.md +++ b/readme.md @@ -542,7 +542,7 @@ Monitors have default aliases. The sections below describe every monitor in turn, but before we provide a list of the configuration options (or *monitor arguments*) they all share. -### Dynamic Strings +### Icon patterns Some monitors allow usage of strings that depend on some integer value from 0 to 8 by replacing all occurences of `"%%"` with it @@ -552,9 +552,9 @@ as `"%"`, `"%%"` as `"3"`, `"%%%"` as `"3%"`, `"%%%%"` as `"33"` and so on). Ess it allows to replace vertical bars with custom icons. For example, Run Brightness - [ "-t", "" + [ "-t", "" , "--" - , "--brightness-dynamic-string", "" + , "--brightness-icon-pattern", "" ] 30 Will display `bright_0.xpm` to `bright_8.xpm` depending on current brightness @@ -711,11 +711,11 @@ something like: - Aliases to the interface name: so `Network "eth0" []` can be used as `%eth0%` - Args: default monitor arguments, plus: - - `--rx-dynamic-string`: dynamic string for reception rate in `rxdstr`. - - `--tx-dynamic-string`: dynamic string for transmission rate in `txdstr`. + - `--rx-icon-pattern`: dynamic string for reception rate in `rxipat`. + - `--tx-icon-pattern`: dynamic string for transmission rate in `txipat`. - Variables that can be used with the `-t`/`--template` argument: - `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxdstr`, `txbar`, `txvbar`, - `txdstr`. Reception and transmission rates (`rx` and `tx`) are displayed + `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxipat`, `txbar`, `txvbar`, + `txipat`. Reception and transmission rates (`rx` and `tx`) are displayed by default as Kb/s, without any suffixes, but you can set the `-S` to "True" to make them displayed with adaptive units (Kb/s, Mb/s, etc.). - Default template: `: KB|KB` @@ -725,11 +725,11 @@ something like: - Active interface is detected automatically - Aliases to "dynnetwork" - Args: default monitor arguments, plus: - - `--rx-dynamic-string`: dynamic string for reception rate in `rxdstr`. - - `--tx-dynamic-string`: dynamic string for transmission rate in `txdstr`. + - `--rx-icon-pattern`: dynamic string for reception rate in `rxipat`. + - `--tx-icon-pattern`: dynamic string for transmission rate in `txipat`. - Variables that can be used with the `-t`/`--template` argument: - `dev`, `rx`, `tx`, `rxbar`, `rxvbar`, `rxdstr`, `txbar`, `txvbar`, - `txdstr`. Reception and transmission rates (`rx` and `tx`) are displayed + `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: `: KB|KB` @@ -739,9 +739,9 @@ something like: - Aliases to the interface name with the suffix "wi": thus, `Wireless "wlan0" []` can be used as `%wlan0wi%` - Args: default monitor arguments, plus: - - `--quality-dynamic-string`: dynamic string for connection quality in `qualitydstr`. + - `--quality-icon-pattern`: dynamic string for connection quality in `qualityipat`. - Variables that can be used with the `-t`/`--template` argument: - `essid`, `quality`, `qualitybar`, `qualityvbar`, `qualitydstr` + `essid`, `quality`, `qualitybar`, `qualityvbar`, `qualityipat` - Default template: ` ` - Requires the C library [iwlib] (part of the wireless tools suite) installed in your system. In addition, to activate this plugin you @@ -751,12 +751,12 @@ something like: - Aliases to `memory` - Args: default monitor arguments, plus: - - `--used-dynamic-string`: dynamic string for used memory ratio in `useddstr`. - - `--free-dynamic-string`: dynamic string for free memory ratio in `freedstr`. + - `--used-icon-pattern`: dynamic string for used memory ratio in `usedipat`. + - `--free-icon-pattern`: dynamic string for free memory ratio in `freeipat`. - Variables that can be used with the `-t`/`--template` argument: `total`, `free`, `buffer`, `cache`, `rest`, `used`, - `usedratio`, `usedbar`, `usedvbar`, `useddstr`, - `freeratio`, `freebar`, `freevbar`, `freedstr` + `usedratio`, `usedbar`, `usedvbar`, `usedipat`, + `freeratio`, `freebar`, `freevbar`, `freeipat` - Default template: `Mem: % (M)` ### `Swap Args RefreshRate` @@ -771,23 +771,23 @@ something like: - Aliases to `cpu` - Args: default monitor arguments, plus: - - `--load-dynamic-string`: dynamic string for cpu load in `dstr`. + - `--load-icon-pattern`: dynamic string for cpu load in `ipat`. - Variables that can be used with the `-t`/`--template` argument: - `total`, `bar`, `vbar`, `dstr`, `user`, `nice`, `system`, `idle`, `iowait` + `total`, `bar`, `vbar`, `ipat`, `user`, `nice`, `system`, `idle`, `iowait` - Default template: `Cpu: %` ### `MultiCpu Args RefreshRate` - Aliases to `multicpu` - Args: default monitor arguments, plus: - - `--load-dynamic-string`: dynamic string for overall cpu load in `dstr`. - - `--load-dynamic-strings`: dynamic string for each cpu load in `autodstr`, `dstr{i}`. + - `--load-icon-pattern`: dynamic string for overall cpu load in `ipat`. + - `--load-icon-patterns`: dynamic string for each cpu load in `autoipat`, `ipat{i}`. This option can be specified several times. nth option corresponds to nth cpu. - Variables that can be used with the `-t`/`--template` argument: - `autototal`, `autobar`, `autovbar`, `autodstr`, `autouser`, `autonice`, - `autosystem`, `autoidle`, `total`, `bar`, `vbar`, `dstr`, `user`, `nice`, - `system`, `idle`, `total0`, `bar0`, `vbar0`, `dstr0`, `user0`, `nice0`, + `autototal`, `autobar`, `autovbar`, `autoipat`, `autouser`, `autonice`, + `autosystem`, `autoidle`, `total`, `bar`, `vbar`, `ipat`, `user`, `nice`, + `system`, `idle`, `total0`, `bar0`, `vbar0`, `ipat0`, `user0`, `nice0`, `system0`, `idle0`, ... The auto* variables automatically detect the number of CPUs on the system and display one entry for each. @@ -818,15 +818,15 @@ something like: - `-p`: color to display positive power (battery charging) - `-f`: file in `/sys/class/power_supply` with AC info (default: "AC/online") - - `--on-dynamic-string`: dynamic string for current battery charge - when AC is "on" in `leftdstr`. - - `--off-dynamic-string`: dynamic string for current battery charge - when AC is "off" in `leftdstr`. - - `--idle-dynamic-string`: dynamic string for current battery charge - when AC is "idle" in `leftdstr`. + - `--on-icon-pattern`: dynamic string for current battery charge + when AC is "on" in `leftipat`. + - `--off-icon-pattern`: dynamic string for current battery charge + when AC is "off" in `leftipat`. + - `--idle-icon-pattern`: dynamic string for current battery charge + when AC is "idle" in `leftipat`. - Variables that can be used with the `-t`/`--template` argument: - `left`, `leftbar`, `leftvbar`, `leftdstr`, `timeleft`, `watts`, `acstatus` + `left`, `leftbar`, `leftvbar`, `leftipat`, `timeleft`, `watts`, `acstatus` - Default template: `Batt: , % / ` - Example (note that you need "--" to separate regular monitor options from Battery's specific ones): @@ -899,12 +899,12 @@ more than one battery. - Aliases to `disku` - Disks: list of pairs of the form (device or mount point, template), where the template can contain ``, ``, ``, `` or - ``, ``, ``, ``, ``, - `` or `` for total, free, used, free percentage and + ``, ``, ``, ``, ``, + `` or `` for total, free, used, free percentage and used percentage of the given file system capacity. - Args: default monitor arguments. `-t`/`--template` is ignored. Plus - - `--free-dynamic-string`: dynamic string for free disk space in `freedstr`. - - `--used-dynamic-string`: dynamic string for used disk space in `useddstr`. + - `--free-icon-pattern`: dynamic string for free disk space in `freeipat`. + - `--used-icon-pattern`: dynamic string for used disk space in `usedipat`. - Default template: none (you must specify a template for each file system). - Example: @@ -918,13 +918,13 @@ more than one battery. - Disks: list of pairs of the form (device or mount point, template), where the template can contain ``, ``, `` for total, read and write speed, respectively. There are also bar versions of each: - ``, ``, ``, - ``, ``, ``, - ``, ``, and ``. + ``, ``, ``, + ``, ``, ``, + ``, ``, and ``. - Args: default monitor arguments. `-t`/`--template` is ignored. Plus - - `--total-dynamic-string`: dynamic string for total disk I/O in ``. - - `--write-dynamic-string`: dynamic string for write disk I/O in ``. - - `--read-dynamic-string`: dynamic string for read disk I/O in ``. + - `--total-icon-pattern`: dynamic string for total disk I/O in ``. + - `--write-icon-pattern`: dynamic string for write disk I/O in ``. + - `--read-icon-pattern`: dynamic string for read disk I/O in ``. - Default template: none (you must specify a template for each file system). - Example: @@ -1012,9 +1012,9 @@ more than one battery. - Long option: `--offc` - `--highd` _number_ High threshold for dB. Defaults to -5.0. - `--lowd` _number_ Low threshold for dB. Defaults to -30.0. - - `--volume-dynamic-string` _string_ dynamic string for current volume in `volumedstr`. + - `--volume-icon-pattern` _string_ dynamic string for current volume in `volumeipat`. - Variables that can be used with the `-t`/`--template` argument: - `volume`, `volumebar`, `volumevbar`, `volumedstr`, `dB`, `status` + `volume`, `volumebar`, `volumevbar`, `volumeipat`, `dB`, `status` - Note that `dB` might only return 0 on your system. This is known to happen on systems with a pulseaudio backend. - Default template: `Vol: % ` @@ -1032,9 +1032,9 @@ more than one battery. playing, stopped and paused states in the `statei` template field. The environment variables `MPD_HOST` and `MPD_PORT` are used to configure the mpd server to communicate with. Also available: - - `lapsed-dynamic-string`: dynamic string for current track position in `dstr`. + - `lapsed-icon-pattern`: dynamic string for current track position in `ipat`. - Variables that can be used with the `-t`/`--template` argument: - `bar`, `vbar`, `dstr`, `state`, `statei`, `volume`, `length`, + `bar`, `vbar`, `ipat`, `state`, `statei`, `volume`, `length`, `lapsed`, `remaining`, `plength` (playlist length), `ppos` (playlist position), `name`, `artist`, `composer`, `performer`, @@ -1154,9 +1154,9 @@ more than one battery. actual_brightness) - `-M`: file with the maximum brightness (default: max_brightness) - - `--brightness-dynamic-string`: dynamic string for current brightness in `dstr`. + - `--brightness-icon-pattern`: dynamic string for current brightness in `ipat`. - Variables that can be used with the `-t`/`--template` argument: - `vbar`, `percent`, `bar`, `dstr` + `vbar`, `percent`, `bar`, `ipat` - Default template: `` - Example: diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index 592deae..f7b31e4 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -34,9 +34,9 @@ data BattOpts = BattOpts , highThreshold :: Float , onlineFile :: FilePath , scale :: Float - , onDynamicString :: Maybe DynamicString - , offDynamicString :: Maybe DynamicString - , idleDynamicString :: Maybe DynamicString + , onIconPattern :: Maybe IconPattern + , offIconPattern :: Maybe IconPattern + , idleIconPattern :: Maybe IconPattern } defaultOpts :: BattOpts @@ -52,9 +52,9 @@ defaultOpts = BattOpts , highThreshold = -10 , onlineFile = "AC/online" , scale = 1e6 - , onDynamicString = Nothing - , offDynamicString = Nothing - , idleDynamicString = Nothing + , onIconPattern = Nothing + , offIconPattern = Nothing + , idleIconPattern = Nothing } options :: [OptDescr (BattOpts -> BattOpts)] @@ -70,12 +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 }) "") "" + , Option "" ["on-icon-pattern"] (ReqArg (\x o -> + o { onIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["off-icon-pattern"] (ReqArg (\x o -> + o { offIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["idle-icon-pattern"] (ReqArg (\x o -> + o { idleIconPattern = Just $ parseIconPattern x }) "") "" ] parseOpts :: [String] -> IO BattOpts @@ -94,7 +94,7 @@ sysDir = "/sys/class/power_supply" battConfig :: IO MConfig battConfig = mkMConfig "Batt: , % / " -- template - ["leftbar", "leftvbar", "left", "acstatus", "timeleft", "watts", "leftdstr"] -- replacements + ["leftbar", "leftvbar", "left", "acstatus", "timeleft", "watts", "leftipat"] -- replacements data Files = Files { fFull :: String @@ -182,7 +182,7 @@ runBatt' bfs args = do Result x w t s -> do l <- fmtPercent x ws <- fmtWatts w opts suffix d - si <- getDynamicString opts s x + si <- getIconPattern opts s x parseTemplate (l ++ [fmtStatus opts s, fmtTime $ floor t, ws, si]) NA -> getConfigValue naString where fmtPercent :: Float -> Monitor [String] @@ -209,9 +209,9 @@ runBatt' bfs args = do | -x >= highThreshold o = maybeColor (highWColor o) | -x >= lowThreshold o = maybeColor (mediumWColor o) | otherwise = maybeColor (lowWColor o) - getDynamicString opts status x = do + getIconPattern 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' + Idle -> showIconPattern (idleIconPattern opts) x' + Charging -> showIconPattern (onIconPattern opts) x' + Discharging -> showIconPattern (offIconPattern opts) x' diff --git a/src/Plugins/Monitors/Bright.hs b/src/Plugins/Monitors/Bright.hs index 999b459..cb510f6 100644 --- a/src/Plugins/Monitors/Bright.hs +++ b/src/Plugins/Monitors/Bright.hs @@ -26,22 +26,22 @@ import Plugins.Monitors.Common data BrightOpts = BrightOpts { subDir :: String , currBright :: String , maxBright :: String - , curBrightDynamicString :: Maybe DynamicString + , curBrightIconPattern :: Maybe IconPattern } defaultOpts :: BrightOpts defaultOpts = BrightOpts { subDir = "acpi_video0" , currBright = "actual_brightness" , maxBright = "max_brightness" - , curBrightDynamicString = Nothing + , curBrightIconPattern = 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 }) "") "" + , Option "" ["brightness-icon-pattern"] (ReqArg (\x o -> + o { curBrightIconPattern = Just $ parseIconPattern x }) "") "" ] -- from Batt.hs @@ -56,7 +56,7 @@ sysDir = "/sys/class/backlight/" brightConfig :: IO MConfig brightConfig = mkMConfig "" -- template - ["vbar", "percent", "bar", "dstr"] -- replacements + ["vbar", "percent", "bar", "ipat"] -- replacements data Files = Files { fCurr :: String , fMax :: String @@ -85,7 +85,7 @@ runBright args = do fmtPercent opts c = do r <- showVerticalBar (100 * c) c s <- showPercentWithColors c t <- showPercentBar (100 * c) c - d <- showDynamicString (curBrightDynamicString opts) c + d <- showIconPattern (curBrightIconPattern opts) c return [r,s,t,d] readBright :: Files -> IO Float diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index ed91c73..7d11258 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -40,8 +40,8 @@ module Plugins.Monitors.Common ( , parseTemplate' -- ** String Manipulation -- $strings - , DynamicString - , parseDynamicString + , IconPattern + , parseIconPattern , padString , showWithPadding , showWithColors @@ -50,10 +50,10 @@ module Plugins.Monitors.Common ( , showPercentsWithColors , showPercentBar , showVerticalBar - , showDynamicString + , showIconPattern , showLogBar , showLogVBar - , showLogDynamicString + , showLogIconPattern , showWithUnits , takeDigits , showDigits @@ -352,10 +352,10 @@ combine m ((s,ts,ss):xs) = -- $strings -type DynamicString = Int -> String +type IconPattern = Int -> String -parseDynamicString :: String -> DynamicString -parseDynamicString path = +parseIconPattern :: String -> IconPattern +parseIconPattern path = let spl = splitOnPercent path in \i -> concat $ intersperse (show i) spl where splitOnPercent [] = [[]] @@ -469,9 +469,9 @@ showPercentBar v x = do s <- colorizeString v (take len $ cycle bf) return $ s ++ take (bw - len) (cycle bb) -showDynamicString :: Maybe DynamicString -> Float -> Monitor String -showDynamicString Nothing _ = return "" -showDynamicString (Just str) x = return $ str $ convert $ 100 * x +showIconPattern :: Maybe IconPattern -> Float -> Monitor String +showIconPattern Nothing _ = return "" +showIconPattern (Just str) x = return $ str $ convert $ 100 * x where convert val | t <= 0 = 0 | t > 8 = 8 @@ -511,8 +511,8 @@ showLogVBar f v = do | otherwise = f + logBase 2 (x / hh) / bw showVerticalBar v $ choose v -showLogDynamicString :: Maybe DynamicString -> Float -> Float -> Monitor String -showLogDynamicString str f v = do +showLogIconPattern :: Maybe IconPattern -> Float -> Float -> Monitor String +showLogIconPattern str f v = do h <- fromIntegral `fmap` getConfigValue high l <- fromIntegral `fmap` getConfigValue low bw <- fromIntegral `fmap` getConfigValue barWidth @@ -520,4 +520,4 @@ showLogDynamicString str f v = do choose x | x == 0.0 = 0 | x <= ll = 1 / bw | otherwise = f + logBase 2 (x / hh) / bw - showDynamicString str $ choose v + showIconPattern str $ choose v diff --git a/src/Plugins/Monitors/Cpu.hs b/src/Plugins/Monitors/Cpu.hs index 5abde7e..7fed989 100644 --- a/src/Plugins/Monitors/Cpu.hs +++ b/src/Plugins/Monitors/Cpu.hs @@ -21,18 +21,18 @@ import Data.IORef (IORef, newIORef, readIORef, writeIORef) import System.Console.GetOpt data CpuOpts = CpuOpts - { loadDynamicString :: Maybe DynamicString + { loadIconPattern :: Maybe IconPattern } defaultOpts :: CpuOpts defaultOpts = CpuOpts - { loadDynamicString = Nothing + { loadIconPattern = Nothing } options :: [OptDescr (CpuOpts -> CpuOpts)] options = - [ Option "" ["load-dynamic-string"] (ReqArg (\x o -> - o { loadDynamicString = Just $ parseDynamicString x }) "") "" + [ Option "" ["load-icon-pattern"] (ReqArg (\x o -> + o { loadIconPattern = Just $ parseIconPattern x }) "") "" ] parseOpts :: [String] -> IO CpuOpts @@ -44,7 +44,7 @@ parseOpts argv = cpuConfig :: IO MConfig cpuConfig = mkMConfig "Cpu: %" - ["bar","vbar","dstr","total","user","nice","system","idle","iowait"] + ["bar","vbar","ipat","total","user","nice","system","idle","iowait"] type CpuDataRef = IORef [Int] @@ -70,7 +70,7 @@ 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 + d <- showIconPattern (loadIconPattern opts) t ps <- showPercentsWithColors (t:xs) return (b:v:d:ps) diff --git a/src/Plugins/Monitors/Disk.hs b/src/Plugins/Monitors/Disk.hs index e020c85..0019c1a 100644 --- a/src/Plugins/Monitors/Disk.hs +++ b/src/Plugins/Monitors/Disk.hs @@ -28,9 +28,9 @@ import System.Directory (canonicalizePath, doesFileExist) import System.Console.GetOpt data DiskIOOpts = DiskIOOpts - { totalDynamicString :: Maybe DynamicString - , writeDynamicString :: Maybe DynamicString - , readDynamicString :: Maybe DynamicString + { totalIconPattern :: Maybe IconPattern + , writeIconPattern :: Maybe IconPattern + , readIconPattern :: Maybe IconPattern } parseDiskIOOpts :: [String] -> IO DiskIOOpts @@ -39,29 +39,29 @@ parseDiskIOOpts argv = (o, _, []) -> return $ foldr id defaultOpts o (_, _, errs) -> ioError . userError $ concat errs where defaultOpts = DiskIOOpts - { totalDynamicString = Nothing - , writeDynamicString = Nothing - , readDynamicString = Nothing + { totalIconPattern = Nothing + , writeIconPattern = Nothing + , readIconPattern = 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}) "") "" + [ Option "" ["total-icon-pattern"] (ReqArg (\x o -> + o { totalIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["write-icon-pattern"] (ReqArg (\x o -> + o { writeIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["read-icon-pattern"] (ReqArg (\x o -> + o { readIconPattern = Just $ parseIconPattern x}) "") "" ] diskIOConfig :: IO MConfig diskIOConfig = mkMConfig "" ["total", "read", "write" ,"totalbar", "readbar", "writebar" ,"totalvbar", "readvbar", "writevbar" - ,"totaldstr", "readdstr", "writedstr" + ,"totalipat", "readipat", "writeipat" ] data DiskUOpts = DiskUOpts - { freeDynamicString :: Maybe DynamicString - , usedDynamicString :: Maybe DynamicString + { freeIconPattern :: Maybe IconPattern + , usedIconPattern :: Maybe IconPattern } parseDiskUOpts :: [String] -> IO DiskUOpts @@ -70,21 +70,21 @@ parseDiskUOpts argv = (o, _, []) -> return $ foldr id defaultOpts o (_, _, errs) -> ioError . userError $ concat errs where defaultOpts = DiskUOpts - { freeDynamicString = Nothing - , usedDynamicString = Nothing + { freeIconPattern = Nothing + , usedIconPattern = 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}) "") "" + [ Option "" ["free-icon-pattern"] (ReqArg (\x o -> + o { freeIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["used-icon-pattern"] (ReqArg (\x o -> + o { usedIconPattern = Just $ parseIconPattern x}) "") "" ] diskUConfig :: IO MConfig diskUConfig = mkMConfig "" [ "size", "free", "used", "freep", "usedp" - , "freebar", "freevbar", "freedstr" - , "usedbar", "usedvbar", "useddstr" + , "freebar", "freevbar", "freeipat" + , "usedbar", "usedvbar", "usedipat" ] type DevName = String @@ -183,10 +183,10 @@ 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 + ipat <- mapM (\(f,v) -> showLogIconPattern (f opts) 0.8 v) + $ zip [totalIconPattern, readIconPattern, writeIconPattern] xs setConfigValue tmp template - parseTemplate $ s ++ b ++ vb ++ dstr + parseTemplate $ s ++ b ++ vb ++ ipat runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String runDiskIO dref disks argv = do @@ -225,11 +225,11 @@ runDiskU' opts tmp path = do sp <- showPercentsWithColors [fr, 1 - fr] fb <- showPercentBar (fromIntegral freep) fr fvb <- showVerticalBar (fromIntegral freep) fr - fdstr <- showDynamicString (freeDynamicString opts) fr + fipat <- showIconPattern (freeIconPattern opts) fr ub <- showPercentBar (fromIntegral $ 100 - freep) (1 - fr) uvb <- showVerticalBar (fromIntegral $ 100 - freep) (1 - fr) - udstr <- showDynamicString (usedDynamicString opts) (1 - fr) - parseTemplate $ [sizeToStr total] ++ s ++ sp ++ [fb,fvb,fdstr,ub,uvb,udstr] + uipat <- showIconPattern (usedIconPattern opts) (1 - fr) + parseTemplate $ [sizeToStr total] ++ s ++ sp ++ [fb,fvb,fipat,ub,uvb,uipat] where ign = const (return [0, 0, 0]) :: SomeException -> IO [Integer] diff --git a/src/Plugins/Monitors/MPD.hs b/src/Plugins/Monitors/MPD.hs index 3c1615e..1a49ad3 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: " - [ "bar", "vbar", "dstr", "state", "statei", "volume", "length" + [ "bar", "vbar", "ipat", "state", "statei", "volume", "length" , "lapsed", "remaining", "plength", "ppos", "file" , "name", "artist", "composer", "performer" , "album", "title", "track", "genre" @@ -32,7 +32,7 @@ data MOpts = MOpts { mPlaying :: String , mStopped :: String , mPaused :: String - , mLapsedDynamicString :: Maybe DynamicString + , mLapsedIconPattern :: Maybe IconPattern } defaultOpts :: MOpts @@ -40,7 +40,7 @@ defaultOpts = MOpts { mPlaying = ">>" , mStopped = "><" , mPaused = "||" - , mLapsedDynamicString = Nothing + , mLapsedIconPattern = Nothing } options :: [OptDescr (MOpts -> MOpts)] @@ -48,8 +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 }) "") "" + , Option "" ["lapsed-icon-pattern"] (ReqArg (\x o -> + o { mLapsedIconPattern = Just $ parseIconPattern x }) "") "" ] runMPD :: [String] -> Monitor String @@ -91,8 +91,8 @@ parseMPD (Right st) song opts = do songData <- parseSong song bar <- showPercentBar (100 * b) b vbar <- showVerticalBar (100 * b) b - dstr <- showDynamicString (mLapsedDynamicString opts) b - return $ [bar, vbar, dstr, ss, si, vol, len, lap, remain, plen, ppos] ++ songData + ipat <- showIconPattern (mLapsedIconPattern opts) b + return $ [bar, vbar, ipat, 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 7524989..b19c5a7 100644 --- a/src/Plugins/Monitors/Mem.hs +++ b/src/Plugins/Monitors/Mem.hs @@ -19,22 +19,22 @@ import qualified Data.Map as M import System.Console.GetOpt data MemOpts = MemOpts - { usedDynamicString :: Maybe DynamicString - , freeDynamicString :: Maybe DynamicString + { usedIconPattern :: Maybe IconPattern + , freeIconPattern :: Maybe IconPattern } defaultOpts :: MemOpts defaultOpts = MemOpts - { usedDynamicString = Nothing - , freeDynamicString = Nothing + { usedIconPattern = Nothing + , freeIconPattern = 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 }) "") "" + [ Option "" ["used-icon-pattern"] (ReqArg (\x o -> + o { usedIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["free-icon-pattern"] (ReqArg (\x o -> + o { freeIconPattern = Just $ parseIconPattern x }) "") "" ] parseOpts :: [String] -> IO MemOpts @@ -46,7 +46,7 @@ parseOpts argv = memConfig :: IO MConfig memConfig = mkMConfig "Mem: % (M)" -- template - ["usedbar", "usedvbar", "useddstr", "freebar", "freevbar", "freedstr", "usedratio", "freeratio", + ["usedbar", "usedvbar", "usedipat", "freebar", "freevbar", "freeipat", "usedratio", "freeratio", "total", "free", "buffer", "cache", "rest", "used"] -- available replacements fileMEM :: IO String @@ -76,14 +76,14 @@ formatMem opts (r:fr:xs) = rr = 100 * r ub <- showPercentBar rr r uvb <- showVerticalBar rr r - udstr <- showDynamicString (usedDynamicString opts) r + uipat <- showIconPattern (usedIconPattern opts) r fb <- showPercentBar (100 - rr) (1 - r) fvb <- showVerticalBar (100 - rr) ( 1 - r) - fdstr <- showDynamicString (freeDynamicString opts) (1 - r) + fipat <- showIconPattern (freeIconPattern opts) (1 - r) rs <- showPercentWithColors r fs <- showPercentWithColors fr s <- mapM (showWithColors f) xs - return (ub:uvb:udstr:fb:fvb:fdstr:rs:fs:s) + return (ub:uvb:uipat:fb:fvb:fipat:rs:fs:s) formatMem _ _ = replicate 10 `fmap` getConfigValue naString runMem :: [String] -> Monitor String diff --git a/src/Plugins/Monitors/MultiCpu.hs b/src/Plugins/Monitors/MultiCpu.hs index 9f8c191..eab21da 100644 --- a/src/Plugins/Monitors/MultiCpu.hs +++ b/src/Plugins/Monitors/MultiCpu.hs @@ -22,22 +22,22 @@ import Data.IORef (IORef, newIORef, readIORef, writeIORef) import System.Console.GetOpt data MultiCpuOpts = MultiCpuOpts - { loadDynamicStrings :: [DynamicString] - , loadDynamicString :: Maybe DynamicString + { loadIconPatterns :: [IconPattern] + , loadIconPattern :: Maybe IconPattern } defaultOpts :: MultiCpuOpts defaultOpts = MultiCpuOpts - { loadDynamicStrings = [] - , loadDynamicString = Nothing + { loadIconPatterns = [] + , loadIconPattern = 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 }) "") "" + [ Option "" ["load-icon-pattern"] (ReqArg (\x o -> + o { loadIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["load-icon-patterns"] (ReqArg (\x o -> + o { loadIconPatterns = parseIconPattern x : loadIconPatterns o }) "") "" ] parseOpts :: [String] -> IO MultiCpuOpts @@ -47,7 +47,7 @@ parseOpts argv = (_, _, errs) -> ioError . userError $ concat errs variables :: [String] -variables = ["bar", "vbar","dstr","total","user","nice","system","idle"] +variables = ["bar", "vbar","ipat","total","user","nice","system","idle"] vNum :: Int vNum = length variables @@ -91,12 +91,12 @@ formatCpu opts i xs | otherwise = let t = sum $ take 3 xs in do b <- showPercentBar (100 * t) t h <- showVerticalBar (100 * t) t - d <- showDynamicString tryString t + d <- showIconPattern tryString t ps <- showPercentsWithColors (t:xs) return (b:h:d:ps) where tryString - | i == 0 = loadDynamicString opts - | i <= length (loadDynamicStrings opts) = Just $ (loadDynamicStrings opts) !! (i - 1) + | i == 0 = loadIconPattern opts + | i <= length (loadIconPatterns opts) = Just $ (loadIconPatterns opts) !! (i - 1) | otherwise = Nothing splitEvery :: (Eq a) => Int -> [a] -> [[a]] diff --git a/src/Plugins/Monitors/Net.hs b/src/Plugins/Monitors/Net.hs index 137770c..5954a77 100644 --- a/src/Plugins/Monitors/Net.hs +++ b/src/Plugins/Monitors/Net.hs @@ -30,22 +30,22 @@ import System.Console.GetOpt import qualified Data.ByteString.Lazy.Char8 as B data NetOpts = NetOpts - { rxDynamicString :: Maybe DynamicString - , txDynamicString :: Maybe DynamicString + { rxIconPattern :: Maybe IconPattern + , txIconPattern :: Maybe IconPattern } defaultOpts :: NetOpts defaultOpts = NetOpts - { rxDynamicString = Nothing - , txDynamicString = Nothing + { rxIconPattern = Nothing + , txIconPattern = 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 }) "") "" + [ Option "" ["rx-icon-pattern"] (ReqArg (\x o -> + o { rxIconPattern = Just $ parseIconPattern x }) "") "" + , Option "" ["tx-icon-pattern"] (ReqArg (\x o -> + o { txIconPattern = Just $ parseIconPattern x }) "") "" ] parseOpts :: [String] -> IO NetOpts @@ -88,7 +88,7 @@ instance Ord NetDev where netConfig :: IO MConfig netConfig = mkMConfig ": KB|KB" -- template - ["dev", "rx", "tx", "rxbar", "rxvbar", "rxdstr", "txbar", "txvbar", "txdstr"] -- available replacements + ["dev", "rx", "tx", "rxbar", "rxvbar", "rxipat", "txbar", "txvbar", "txipat"] -- available replacements operstateDir :: String -> FilePath operstateDir d = "/sys/class/net" d "operstate" @@ -132,8 +132,8 @@ findNetDev dev = do isDev (NI d) = d == dev isDev NA = False -formatNet :: Maybe DynamicString -> Float -> Monitor (String, String, String, String) -formatNet mdstr d = do +formatNet :: Maybe IconPattern -> Float -> Monitor (String, String, String, String) +formatNet mipat d = do s <- getConfigValue useSuffix dd <- getConfigValue decDigits let str True v = showDigits dd d' ++ show u @@ -141,17 +141,17 @@ formatNet mdstr 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 + ipat <- showLogIconPattern mipat 0.9 d x <- showWithColors (str s) d - return (x, b, vb, dstr) + return (x, b, vb, ipat) printNet :: NetOpts -> NetDev -> Monitor String printNet opts nd = case nd of ND d r t -> do - (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] + (rx, rb, rvb, ripat) <- formatNet (rxIconPattern opts) r + (tx, tb, tvb, tipat) <- formatNet (txIconPattern opts) t + parseTemplate [d,rx,tx,rb,rvb,ripat,tb,tvb,tipat] NI _ -> return "" NA -> getConfigValue naString diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs index 2787a3c..8c39b9f 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", "volumebar", "volumevbar", "dB","status", "volumedstr"] + ["volume", "volumebar", "volumevbar", "dB","status", "volumeipat"] data VolumeOpts = VolumeOpts @@ -34,7 +34,7 @@ data VolumeOpts = VolumeOpts , offColor :: Maybe String , highDbThresh :: Float , lowDbThresh :: Float - , volumeDynamicString :: Maybe DynamicString + , volumeIconPattern :: Maybe IconPattern } defaultOpts :: VolumeOpts @@ -45,7 +45,7 @@ defaultOpts = VolumeOpts , offColor = Just "red" , highDbThresh = -5.0 , lowDbThresh = -30.0 - , volumeDynamicString = Nothing + , volumeIconPattern = Nothing } options :: [OptDescr (VolumeOpts -> VolumeOpts)] @@ -56,8 +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 }) "") "" + , Option "" ["volume-icon-pattern"] (ReqArg (\x o -> + o { volumeIconPattern = Just $ parseIconPattern x }) "") "" ] parseOpts :: [String] -> IO VolumeOpts @@ -84,9 +84,9 @@ 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 +formatVolDStr :: Maybe IconPattern -> Integer -> Integer -> Integer -> Monitor String +formatVolDStr ipat lo hi v = + showIconPattern ipat $ percent v lo hi switchHelper :: VolumeOpts -> (VolumeOpts -> Maybe String) @@ -134,8 +134,8 @@ runVolume mixerName controlName argv = do v <- liftMonitor $ liftM3 formatVolVBar lo hi val d <- getFormatDB opts db s <- getFormatSwitch opts sw - dstr <- liftMonitor $ liftM3 (formatVolDStr $ volumeDynamicString opts) lo hi val - parseTemplate [p, b, v, d, s, dstr] + ipat <- liftMonitor $ liftM3 (formatVolDStr $ volumeIconPattern opts) lo hi val + parseTemplate [p, b, v, d, s, ipat] where diff --git a/src/Plugins/Monitors/Wireless.hs b/src/Plugins/Monitors/Wireless.hs index c87bec6..b1e3c7e 100644 --- a/src/Plugins/Monitors/Wireless.hs +++ b/src/Plugins/Monitors/Wireless.hs @@ -20,18 +20,18 @@ import Plugins.Monitors.Common import IWlib data WirelessOpts = WirelessOpts - { qualityDynamicString :: Maybe DynamicString + { qualityIconPattern :: Maybe IconPattern } defaultOpts :: WirelessOpts defaultOpts = WirelessOpts - { qualityDynamicString = Nothing + { qualityIconPattern = Nothing } options :: [OptDescr (WirelessOpts -> WirelessOpts)] options = - [ Option "" ["quality-dynamic-string"] (ReqArg (\d opts -> - opts { qualityDynamicString = Just $ parseDynamicString d }) "") "" + [ Option "" ["quality-icon-pattern"] (ReqArg (\d opts -> + opts { qualityIconPattern = Just $ parseIconPattern d }) "") "" ] parseOpts :: [String] -> IO WirelessOpts @@ -42,7 +42,7 @@ parseOpts argv = wirelessConfig :: IO MConfig wirelessConfig = - mkMConfig " " ["essid", "quality", "qualitybar", "qualityvbar", "qualitydstr"] + mkMConfig " " ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"] runWireless :: String -> [String] -> Monitor String runWireless iface args = do @@ -58,5 +58,5 @@ runWireless iface args = do else showWithPadding "" qb <- showPercentBar qlty (qlty / 100) qvb <- showVerticalBar qlty (qlty / 100) - qdstr <- showDynamicString (qualityDynamicString opts) (qlty / 100) - parseTemplate [ep, q, qb, qvb, qdstr] + qipat <- showIconPattern (qualityIconPattern opts) (qlty / 100) + parseTemplate [ep, q, qb, qvb, qipat] -- cgit v1.2.3