summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Common.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2014-09-24 20:54:16 +0200
committerjao <jao@gnu.org>2014-09-24 20:54:16 +0200
commitb0f07db920d9ed446532dfc1aaddd3e7f57d0592 (patch)
tree53c0c3ee80a8db536b6fb6decc492c72e7c5a663 /src/Plugins/Monitors/Common.hs
parentb7973cb8af3b03f6add1a0f0bb4cc790b1223609 (diff)
parentf8b7b22253d72b7b6ecf83bac87a8cda41040f49 (diff)
downloadxmobar-b0f07db920d9ed446532dfc1aaddd3e7f57d0592.tar.gz
xmobar-b0f07db920d9ed446532dfc1aaddd3e7f57d0592.tar.bz2
Merge branch 'dynamic-strings' of https://github.com/projedi/xmobar
Diffstat (limited to 'src/Plugins/Monitors/Common.hs')
-rw-r--r--src/Plugins/Monitors/Common.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs
index 971de16..7d11258 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
+ , IconPattern
+ , parseIconPattern
, padString
, showWithPadding
, showWithColors
@@ -48,8 +50,10 @@ module Plugins.Monitors.Common (
, showPercentsWithColors
, showPercentBar
, showVerticalBar
+ , showIconPattern
, showLogBar
, showLogVBar
+ , showLogIconPattern
, showWithUnits
, takeDigits
, showDigits
@@ -348,6 +352,18 @@ combine m ((s,ts,ss):xs) =
-- $strings
+type IconPattern = Int -> String
+
+parseIconPattern :: String -> IconPattern
+parseIconPattern 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)
+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
+ | 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
+
+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
+ let [ll, hh] = sort [l, h]
+ choose x | x == 0.0 = 0
+ | x <= ll = 1 / bw
+ | otherwise = f + logBase 2 (x / hh) / bw
+ showIconPattern str $ choose v