summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors/Common.hs
diff options
context:
space:
mode:
authorJose A Ortega Ruiz <jao@gnu.org>2010-03-19 21:33:24 +0100
committerJose A Ortega Ruiz <jao@gnu.org>2010-03-19 21:33:24 +0100
commitdc171e4a07e597f9f5d7839c231b8b9c3ae19437 (patch)
treecae45f74db3ffd894b7fb593288ebc46538aede3 /Plugins/Monitors/Common.hs
parent4f8ba03c51570925fb59e90e65747da37a2a4b65 (diff)
downloadxmobar-dc171e4a07e597f9f5d7839c231b8b9c3ae19437.tar.gz
xmobar-dc171e4a07e597f9f5d7839c231b8b9c3ae19437.tar.bz2
Usage bars
Ignore-this: 63fd21a117029674e33a9c4419dbc4de ASCII art bars for a bunch of monitors. darcs-hash:20100319203324-748be-2f927aa0e16d8874e10a04f0245427d32e0e53ce.gz
Diffstat (limited to 'Plugins/Monitors/Common.hs')
-rw-r--r--Plugins/Monitors/Common.hs34
1 files changed, 25 insertions, 9 deletions
diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs
index 101907b..535329e 100644
--- a/Plugins/Monitors/Common.hs
+++ b/Plugins/Monitors/Common.hs
@@ -40,6 +40,7 @@ module Plugins.Monitors.Common (
, showWithColors
, showWithColors'
, showPercentsWithColors
+ , showPercentBar
, showWithUnits
, takeDigits
, showDigits
@@ -348,16 +349,18 @@ showWithPadding s =
pr <- getConfigValue padRight
return $ padString mn mx p pr s
+colorizeString :: (Num a, Ord a) => a -> String -> Monitor String
+colorizeString x s = do
+ h <- getConfigValue high
+ l <- getConfigValue low
+ let col = setColor s
+ [ll,hh] = map fromIntegral $ sort [l, h] -- consider high < low
+ head $ [col highColor | x > hh ] ++
+ [col normalColor | x > ll ] ++
+ [col lowColor | True]
+
showWithColors :: (Num a, Ord a) => (a -> String) -> a -> Monitor String
-showWithColors f x =
- do h <- getConfigValue high
- l <- getConfigValue low
- s <- showWithPadding $ f x
- let col = setColor s
- [ll,hh] = map fromIntegral $ sort [l, h] -- consider high < low
- head $ [col highColor | x > hh ] ++
- [col normalColor | x > ll ] ++
- [col lowColor | True]
+showWithColors f x = showWithPadding (f x) >>= colorizeString x
showWithColors' :: (Num a, Ord a) => String -> a -> Monitor String
showWithColors' str v = showWithColors (const str) v
@@ -367,6 +370,19 @@ showPercentsWithColors fs =
do fstrs <- mapM floatToPercent fs
zipWithM (showWithColors . const) fstrs (map (*100) fs)
+barBackground :: Char
+barBackground = ':'
+barForeground :: Char
+barForeground = '#'
+barLength :: Int
+barLength = 10
+
+showPercentBar :: Float -> Float -> Monitor String
+showPercentBar v x = do
+ let len = min barLength $ round (fromIntegral barLength * x)
+ s <- colorizeString v (replicate len barForeground)
+ return $ s ++ replicate (barLength - len) barBackground
+
-- $threads
doActionTwiceWithDelay :: Int -> IO [a] -> IO ([a], [a])