summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors/Common.hs
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-19 20:52:50 +0100
committerJose Antonio Ortega Ruiz <jao@gnu.org>2010-12-19 20:52:50 +0100
commiteb9f19c593c25eb4ad2a458f00ef486189818ac9 (patch)
tree4e18e269330f0ca28ec6ba736dec9d9cb9a18cf8 /Plugins/Monitors/Common.hs
parent2c91687f0d2a3bcfd39d0f70cb2f824574709989 (diff)
downloadxmobar-eb9f19c593c25eb4ad2a458f00ef486189818ac9.tar.gz
xmobar-eb9f19c593c25eb4ad2a458f00ef486189818ac9.tar.bz2
Non-throwing parsing of ints and floats
Diffstat (limited to 'Plugins/Monitors/Common.hs')
-rw-r--r--Plugins/Monitors/Common.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs
index e177e19..cc1a6a7 100644
--- a/Plugins/Monitors/Common.hs
+++ b/Plugins/Monitors/Common.hs
@@ -47,6 +47,8 @@ module Plugins.Monitors.Common (
, takeDigits
, showDigits
, floatToPercent
+ , parseFloat
+ , parseInt
, stringParser
-- * Threaded Actions
-- $thread
@@ -335,6 +337,16 @@ padString mnw mxw pad pr s =
else let ps = take (rlen - len) (cycle pad)
in if pr then s ++ ps else ps ++ s
+parseFloat :: String -> Float
+parseFloat s = case readFloat s of
+ (v, _):_ -> v
+ _ -> 0
+
+parseInt :: String -> Int
+parseInt s = case readDec s of
+ (v, _):_ -> v
+ _ -> 0
+
floatToPercent :: Float -> Monitor String
floatToPercent n =
do pad <- getConfigValue ppad