summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-13 00:24:55 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-13 00:24:55 +0100
commit19f36a28d501773708da02ba149e8d8dae5756aa (patch)
treee6012f6d7a1c21c8dad2e7f027dc921f361251ec
parentefd9bc7177c66d7bb9a994e919d915ecb5c75154 (diff)
downloadxmobar-19f36a28d501773708da02ba149e8d8dae5756aa.tar.gz
xmobar-19f36a28d501773708da02ba149e8d8dae5756aa.tar.bz2
Use -S in Network to control units display
We've made -P a synonym of -S, and renamed the option to useSuffix.
-rw-r--r--NEWS3
-rw-r--r--Plugins/Monitors/Common.hs10
-rw-r--r--Plugins/Monitors/Net.hs6
-rw-r--r--Plugins/Monitors/Uptime.hs2
-rw-r--r--README10
5 files changed, 20 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index 44a2e0f..766a7b4 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,9 @@ _New features_
- New monitor, `Uptime`, showing the system uptime.
- New monitor argument (`-P`) to enable displaying the `%` sign in
percentages; the sign is now never included by default.
+ - New monitor argument (`-S`) to enable displaying suffixes in some
+ cases: equivalent to `-P` for percentages and used by Uptime and
+ Network to control units display.
- New 'run once' commands, by specifying a 0 refresh rate in `Run
Com` ([issue 26]).
- MPD monitor: updated to libmpd 1.5. New fields `ppos` (playlist
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
diff --git a/README b/README
index a8e7e0c..19c16f5 100644
--- a/README
+++ b/README
@@ -321,7 +321,7 @@ Monitors have default aliases.
thresholds refer to the number of days.
- Variables that can be used with the `-t`/`--template` argument:
`days`, `hours`, `minutes`, `seconds`. The total uptime is the
- sum of all those fields. You can set the `-P` argument to "True"
+ sum of all those fields. You can set the `-S` argument to "True"
to add units to the display of those numeric fields.
- Default template: `Up: <days>d <hours>h <minutes>m`
@@ -343,7 +343,10 @@ Monitors have default aliases.
`%eth0%`
- Args: default monitor arguments (see below)
- Variables that can be used with the `-t`/`--template` argument:
- `dev`, `rx`, `tx`, `rxbar`, `txbar`
+ `dev`, `rx`, `tx`, `rxbar`, `txbar`. 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: `<dev>: <rx>KB|<tx>KB`
`Wireless Interface Args RefreshRate`
@@ -608,7 +611,8 @@ These are the arguments that can be used for internal commands in the
-h color number --high=color number Color for the high threshold: es "#FF0000"
-n color number --normal=color number Color for the normal threshold: es "#00FF00"
-l color number --low=color number Color for the low threshold: es "#0000FF"
- -P True/False --percent=True/False Use % to display percents (default: True)
+ -P True/False --suffix=True/False Use % to display percents (default: False)
+ -S True/False --suffix=True/False Display optional suffixes (default: False)
-p number --ppad=number Pad percentages to given width
-m number --minwidth=number Minimum field width
-M number --maxwidth=number Maximum field width