From 19f36a28d501773708da02ba149e8d8dae5756aa Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Mon, 13 Dec 2010 00:24:55 +0100 Subject: Use -S in Network to control units display We've made -P a synonym of -S, and renamed the option to useSuffix. --- Plugins/Monitors/Common.hs | 10 +++++----- Plugins/Monitors/Net.hs | 6 ++++-- Plugins/Monitors/Uptime.hs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) (limited to 'Plugins') diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 6761e76..bbd9097 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -88,7 +88,7 @@ data MConfig = , barBack :: IORef String , barFore :: IORef String , barWidth :: IORef Int - , usePercent :: IORef Bool + , useSuffix :: IORef Bool } -- | from 'http:\/\/www.haskell.org\/hawiki\/MonadState' @@ -148,7 +148,7 @@ data Opts = HighColor String | BarBack String | BarFore String | BarWidth String - | UsePercent String + | UseSuffix String options :: [OptDescr Opts] options = @@ -158,7 +158,7 @@ options = , 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 "P" ["percent"] (ReqArg UsePercent "True/False" ) "Use % to display percents." + , Option "PS" ["suffix"] (ReqArg UseSuffix "True/False" ) "Use % to display percents or other suffixes." , 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" @@ -202,7 +202,7 @@ doConfigOptions (o:oo) = BarBack bb -> setConfigValue bb barBack >> next BarFore bf -> setConfigValue bf barFore >> next BarWidth bw -> setConfigValue (nz bw) barWidth >> next - UsePercent up -> setConfigValue (bool up) usePercent >> next + UseSuffix up -> setConfigValue (bool up) useSuffix >> next runM :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int -> (String -> IO ()) -> IO () @@ -345,7 +345,7 @@ floatToPercent n = do pad <- getConfigValue ppad pc <- getConfigValue padChars pr <- getConfigValue padRight - up <- getConfigValue usePercent + up <- getConfigValue useSuffix let p = showDigits 0 (n * 100) ps = if up then "%" else "" return $ padString pad pad pc pr p ++ ps diff --git a/Plugins/Monitors/Net.hs b/Plugins/Monitors/Net.hs index b17aa44..d9cd534 100644 --- a/Plugins/Monitors/Net.hs +++ b/Plugins/Monitors/Net.hs @@ -12,7 +12,7 @@ -- ----------------------------------------------------------------------------- -module Plugins.Monitors.Net where +module Plugins.Monitors.Net (netConfig, runNet) where import Plugins.Monitors.Common import qualified Data.ByteString.Lazy.Char8 as B @@ -64,8 +64,10 @@ netParser = formatNet :: Float -> Monitor (String, String) formatNet d = do + s <- getConfigValue useSuffix + let str = if s then (++"Kb/s") . showDigits 1 else showDigits 1 b <- showLogBar 0.9 d - x <- showWithColors (showDigits 1) d + x <- showWithColors str d return (x, b) printNet :: NetDev -> Monitor String diff --git a/Plugins/Monitors/Uptime.hs b/Plugins/Monitors/Uptime.hs index 453b9ad..8524bcc 100644 --- a/Plugins/Monitors/Uptime.hs +++ b/Plugins/Monitors/Uptime.hs @@ -35,7 +35,7 @@ secsPerDay = 24 * 3600 uptime :: Monitor [String] uptime = do t <- io readUptime - u <- getConfigValue usePercent + u <- getConfigValue useSuffix let tsecs = floor t secs = tsecs `mod` secsPerDay days = tsecs `quot` secsPerDay -- cgit v1.2.3