summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorAlexander Shabalin <shabalyn.a@gmail.com>2014-09-04 22:53:06 +0400
committerAlexander Shabalin <shabalyn.a@gmail.com>2014-09-14 12:03:48 +0400
commite8e4415b7eba49d2d6ddb18ab13b3151c9a787bd (patch)
tree2b9dabb20baafad3003b0871f99d068ea83bccca /src
parenteb9f7a73677cc2bc872c3ea69f073faeefe6c989 (diff)
downloadxmobar-e8e4415b7eba49d2d6ddb18ab13b3151c9a787bd.tar.gz
xmobar-e8e4415b7eba49d2d6ddb18ab13b3151c9a787bd.tar.bz2
Add DynamicString as an alternative to vbars.
* DynamicString is an Int -> String which takes a value from 0..8 and produces a string with this value embedded. Usefull for replacing vbars with icons: an icon per one of 9 states. * API is similar to that of vbar. * Default parser of DynamicString produces a function of `i` to a string that replaces all occurences of "%%" with `show i`
Diffstat (limited to 'src')
-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..ed91c73 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
+ , DynamicString
+ , parseDynamicString
, padString
, showWithPadding
, showWithColors
@@ -48,8 +50,10 @@ module Plugins.Monitors.Common (
, showPercentsWithColors
, showPercentBar
, showVerticalBar
+ , showDynamicString
, showLogBar
, showLogVBar
+ , showLogDynamicString
, showWithUnits
, takeDigits
, showDigits
@@ -348,6 +352,18 @@ combine m ((s,ts,ss):xs) =
-- $strings
+type DynamicString = Int -> String
+
+parseDynamicString :: String -> DynamicString
+parseDynamicString 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)
+showDynamicString :: Maybe DynamicString -> Float -> Monitor String
+showDynamicString Nothing _ = return ""
+showDynamicString (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
+
+showLogDynamicString :: Maybe DynamicString -> Float -> Float -> Monitor String
+showLogDynamicString 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
+ showDynamicString str $ choose v