diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2013-10-27 16:20:25 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2013-10-27 16:20:25 +0100 |
commit | 3d2af8a47332235d6556d2d2a40f7392269cf0b0 (patch) | |
tree | 75f75e4dd2bbae0106b77e333213ee6c9b6d4754 /src/Plugins/Monitors | |
parent | 7e89ff8e2007e057a0b00a5a9c1fd953c565db25 (diff) | |
download | xmobar-3d2af8a47332235d6556d2d2a40f7392269cf0b0.tar.gz xmobar-3d2af8a47332235d6556d2d2a40f7392269cf0b0.tar.bz2 |
New N/A string monitor option (cf. #119)
Diffstat (limited to 'src/Plugins/Monitors')
-rw-r--r-- | src/Plugins/Monitors/Batt.hs | 2 | ||||
-rw-r--r-- | src/Plugins/Monitors/Common.hs | 43 | ||||
-rw-r--r-- | src/Plugins/Monitors/CoreTemp.hs | 2 | ||||
-rw-r--r-- | src/Plugins/Monitors/CpuFreq.hs | 6 | ||||
-rw-r--r-- | src/Plugins/Monitors/Mem.hs | 2 | ||||
-rw-r--r-- | src/Plugins/Monitors/Net.hs | 4 | ||||
-rw-r--r-- | src/Plugins/Monitors/ThermalZone.hs | 5 | ||||
-rw-r--r-- | src/Plugins/Monitors/Volume.hs | 10 | ||||
-rw-r--r-- | src/Plugins/Monitors/Weather.hs | 2 | ||||
-rw-r--r-- | src/Plugins/Monitors/Wireless.hs | 9 |
10 files changed, 46 insertions, 39 deletions
diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index 410aec6..4976b61 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -165,7 +165,7 @@ runBatt' bfs args = do do l <- fmtPercent x ws <- fmtWatts w opts suffix d parseTemplate (l ++ [s, fmtTime $ floor t, ws]) - NA -> return "N/A" + NA -> getConfigValue naString where fmtPercent :: Float -> Monitor [String] fmtPercent x = do let x' = minimum [1, x] diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index 973c5f9..58bfef3 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -89,6 +89,7 @@ data MConfig = , barFore :: IORef String , barWidth :: IORef Int , useSuffix :: IORef Bool + , naString :: IORef String } -- | from 'http:\/\/www.haskell.org\/hawiki\/MonadState' @@ -132,7 +133,8 @@ mkMConfig tmpl exprts = bf <- newIORef "#" bw <- newIORef 10 up <- newIORef False - return $ MC nc l lc h hc t e p d mn mx pc pr bb bf bw up + na <- newIORef "N/A" + return $ MC nc l lc h hc t e p d mn mx pc pr bb bf bw up na data Opts = HighColor String | NormalColor String @@ -151,27 +153,29 @@ data Opts = HighColor String | BarFore String | BarWidth String | UseSuffix String + | NAString String options :: [OptDescr Opts] options = [ - Option "H" ["High"] (ReqArg High "number") "The high threshold" - , Option "L" ["Low"] (ReqArg Low "number") "The low threshold" - , Option "h" ["high"] (ReqArg HighColor "color number") "Color for the high threshold: ex \"#FF0000\"" - , Option "n" ["normal"] (ReqArg NormalColor "color number") "Color for the normal threshold: ex \"#00FF00\"" - , Option "l" ["low"] (ReqArg LowColor "color number") "Color for the low threshold: ex \"#0000FF\"" - , Option "t" ["template"] (ReqArg Template "output template") "Output template." - , Option "S" ["suffix"] (ReqArg UseSuffix "True/False") "Use % to display percents or other suffixes." - , Option "d" ["ddigits"] (ReqArg DecDigits "decimal digits") "Number of decimal digits to display." - , Option "p" ["ppad"] (ReqArg PercentPad "percent padding") "Minimum percentage width." - , Option "m" ["minwidth"] (ReqArg MinWidth "minimum width") "Minimum field width" - , Option "M" ["maxwidth"] (ReqArg MaxWidth "maximum width") "Maximum field width" - , Option "w" ["width"] (ReqArg Width "fixed width") "Fixed field width" - , Option "c" ["padchars"] (ReqArg PadChars "padding chars") "Characters to use for padding" - , Option "a" ["align"] (ReqArg PadAlign "padding alignment") "'l' for left padding, 'r' for right" - , Option "b" ["bback"] (ReqArg BarBack "bar background") "Characters used to draw bar backgrounds" - , Option "f" ["bfore"] (ReqArg BarFore "bar foreground") "Characters used to draw bar foregrounds" - , Option "W" ["bwidth"] (ReqArg BarWidth "bar width") "Bar width" + Option "H" ["High"] (ReqArg High "number") "The high threshold" + , Option "L" ["Low"] (ReqArg Low "number") "The low threshold" + , Option "h" ["high"] (ReqArg HighColor "color number") "Color for the high threshold: ex \"#FF0000\"" + , Option "n" ["normal"] (ReqArg NormalColor "color number") "Color for the normal threshold: ex \"#00FF00\"" + , Option "l" ["low"] (ReqArg LowColor "color number") "Color for the low threshold: ex \"#0000FF\"" + , Option "t" ["template"] (ReqArg Template "output template") "Output template." + , Option "S" ["suffix"] (ReqArg UseSuffix "True/False") "Use % to display percents or other suffixes." + , Option "d" ["ddigits"] (ReqArg DecDigits "decimal digits") "Number of decimal digits to display." + , Option "p" ["ppad"] (ReqArg PercentPad "percent padding") "Minimum percentage width." + , Option "m" ["minwidth"] (ReqArg MinWidth "minimum width") "Minimum field width" + , Option "M" ["maxwidth"] (ReqArg MaxWidth "maximum width") "Maximum field width" + , Option "w" ["width"] (ReqArg Width "fixed width") "Fixed field width" + , Option "c" ["padchars"] (ReqArg PadChars "padding chars") "Characters to use for padding" + , Option "a" ["align"] (ReqArg PadAlign "padding alignment") "'l' for left padding, 'r' for right" + , Option "b" ["bback"] (ReqArg BarBack "bar background") "Characters used to draw bar backgrounds" + , Option "f" ["bfore"] (ReqArg BarFore "bar foreground") "Characters used to draw bar foregrounds" + , Option "W" ["bwidth"] (ReqArg BarWidth "bar width") "Bar width" + , Option "x" ["nastring"] (ReqArg NAString "N/A string") "String used when the monitor is not available" ] doArgs :: [String] -> ([String] -> Monitor String) -> Monitor String @@ -205,7 +209,8 @@ doConfigOptions (o:oo) = BarBack s -> setConfigValue s barBack BarFore s -> setConfigValue s barFore BarWidth w -> setConfigValue (nz w) barWidth - UseSuffix u -> setConfigValue (bool u) useSuffix) >> next + UseSuffix u -> setConfigValue (bool u) useSuffix + NAString s -> setConfigValue s naString) >> next runM :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int -> (String -> IO ()) -> IO () diff --git a/src/Plugins/Monitors/CoreTemp.hs b/src/Plugins/Monitors/CoreTemp.hs index c6f98da..5109070 100644 --- a/src/Plugins/Monitors/CoreTemp.hs +++ b/src/Plugins/Monitors/CoreTemp.hs @@ -36,9 +36,9 @@ coreTempConfig = mkMConfig runCoreTemp :: [String] -> Monitor String runCoreTemp _ = do dn <- getConfigValue decDigits + failureMessage <- getConfigValue naString let path = ["/sys/bus/platform/devices/coretemp.", "/temp", "_input"] lbl = Just ("_label", read . (dropWhile (not . isDigit))) divisor = 1e3 :: Double - failureMessage = "CoreTemp: N/A" show' = showDigits (max 0 dn) checkedDataRetrieval failureMessage path lbl (/divisor) show' diff --git a/src/Plugins/Monitors/CpuFreq.hs b/src/Plugins/Monitors/CpuFreq.hs index 6209ef3..8334d1a 100644 --- a/src/Plugins/Monitors/CpuFreq.hs +++ b/src/Plugins/Monitors/CpuFreq.hs @@ -30,10 +30,10 @@ cpuFreqConfig = mkMConfig -- | -- Function retrieves monitor string holding the cpu frequency (or frequencies) runCpuFreq :: [String] -> Monitor String -runCpuFreq _ = +runCpuFreq _ = do let path = ["/sys/devices/system/cpu/cpu", "/cpufreq/scaling_cur_freq"] divisor = 1e6 :: Double - failureMessage = "CpuFreq: N/A" fmt x | x < 1 = (show (round (x * 1000) :: Integer)) ++ "MHz" | otherwise = (show x) ++ "GHz" - in checkedDataRetrieval failureMessage path Nothing (/divisor) fmt + failureMessage <- getConfigValue naString + checkedDataRetrieval failureMessage path Nothing (/divisor) fmt diff --git a/src/Plugins/Monitors/Mem.hs b/src/Plugins/Monitors/Mem.hs index 3cf46c7..7e9341f 100644 --- a/src/Plugins/Monitors/Mem.hs +++ b/src/Plugins/Monitors/Mem.hs @@ -52,7 +52,7 @@ formatMem (r:fr:xs) = fs <- showPercentWithColors fr s <- mapM (showWithColors f) xs return (ub:fb:rs:fs:s) -formatMem _ = return $ replicate 10 "N/A" +formatMem _ = replicate 10 `fmap` getConfigValue naString runMem :: [String] -> Monitor String runMem _ = diff --git a/src/Plugins/Monitors/Net.hs b/src/Plugins/Monitors/Net.hs index b8adc74..2117a2d 100644 --- a/src/Plugins/Monitors/Net.hs +++ b/src/Plugins/Monitors/Net.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Net --- Copyright : (c) 2011, 2012 Jose Antonio Ortega Ruiz +-- Copyright : (c) 2011, 2012, 2013 Jose Antonio Ortega Ruiz -- (c) 2007-2010 Andrea Rossato -- License : BSD-style (see LICENSE) -- @@ -114,7 +114,7 @@ printNet nd = (tx, tb) <- formatNet t parseTemplate [d,rx,tx,rb,tb] NI _ -> return "" - NA -> return "N/A" + NA -> getConfigValue naString parseNet :: NetDevRef -> String -> IO NetDev parseNet nref nd = do diff --git a/src/Plugins/Monitors/ThermalZone.hs b/src/Plugins/Monitors/ThermalZone.hs index 55fb2ca..d692191 100644 --- a/src/Plugins/Monitors/ThermalZone.hs +++ b/src/Plugins/Monitors/ThermalZone.hs @@ -1,7 +1,7 @@ ------------------------------------------------------------------------------ -- | -- Module : Plugins.Monitors.ThermalZone --- Copyright : (c) 2011 Jose Antonio Ortega Ruiz +-- Copyright : (c) 2011, 2013 Jose Antonio Ortega Ruiz -- License : BSD3-style (see LICENSE) -- -- Maintainer : jao@gnu.org @@ -39,5 +39,4 @@ runThermalZone args = do then do mdegrees <- io $ B.readFile file >>= parse temp <- showWithColors show (mdegrees `quot` 1000) parseTemplate [ temp ] - else return "N/A" - + else getConfigValue naString diff --git a/src/Plugins/Monitors/Volume.hs b/src/Plugins/Monitors/Volume.hs index f3d0f4c..76831ff 100644 --- a/src/Plugins/Monitors/Volume.hs +++ b/src/Plugins/Monitors/Volume.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Volume --- Copyright : (c) 2011 Thomas Tuegel +-- Copyright : (c) 2011, 2013 Thomas Tuegel -- License : BSD-style (see LICENSE) -- -- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org> @@ -135,7 +135,7 @@ runVolume mixerName controlName argv = do liftMaybe = fmap (liftM2 (,) (fmap fst) (fmap snd)) . sequenceA liftMonitor :: Maybe (Monitor String) -> Monitor String - liftMonitor Nothing = return unavailable + liftMonitor Nothing = unavailable liftMonitor (Just m) = m getDB :: Maybe Volume -> Monitor (Maybe Integer) @@ -152,11 +152,11 @@ runVolume mixerName controlName argv = do getSw (Just s) = io $ getChannel FrontLeft s getFormatDB :: VolumeOpts -> Maybe Integer -> Monitor String - getFormatDB _ Nothing = return unavailable + getFormatDB _ Nothing = unavailable getFormatDB opts (Just d) = formatDb opts d getFormatSwitch :: VolumeOpts -> Maybe Bool -> Monitor String - getFormatSwitch _ Nothing = return unavailable + getFormatSwitch _ Nothing = unavailable getFormatSwitch opts (Just sw) = formatSwitch opts sw - unavailable = "N/A" + unavailable = getConfigValue naString diff --git a/src/Plugins/Monitors/Weather.hs b/src/Plugins/Monitors/Weather.hs index 6c685ec..bb3d5da 100644 --- a/src/Plugins/Monitors/Weather.hs +++ b/src/Plugins/Monitors/Weather.hs @@ -149,7 +149,7 @@ formatWeather [(WI st ss y m d h w v sk tC tF dp r p)] = do cel <- showWithColors show tC far <- showWithColors show tF parseTemplate [st, ss, y, m, d, h, w, v, sk, cel, far, dp, show r , show p ] -formatWeather _ = return "N/A" +formatWeather _ = getConfigValue naString runWeather :: [String] -> Monitor String runWeather str = diff --git a/src/Plugins/Monitors/Wireless.hs b/src/Plugins/Monitors/Wireless.hs index 8d32c99..f8192dc 100644 --- a/src/Plugins/Monitors/Wireless.hs +++ b/src/Plugins/Monitors/Wireless.hs @@ -24,11 +24,14 @@ wirelessConfig = runWireless :: [String] -> Monitor String runWireless (iface:_) = do wi <- io $ getWirelessInfo iface + na <- getConfigValue naString let essid = wiEssid wi qlty = fromIntegral $ wiQuality wi - e = if essid == "" then "N/A" else essid + e = if essid == "" then na else essid ep <- showWithPadding e - q <- if qlty >= 0 then showPercentWithColors (qlty/100) else showWithPadding "" + q <- if qlty >= 0 + then showPercentWithColors (qlty / 100) + else showWithPadding "" qb <- showPercentBar qlty (qlty / 100) parseTemplate [ep, q, qb] -runWireless _ = return "" +runWireless _ = getConfigValue naString |