summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/Monitors/Bright.hs
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2012-10-06 22:37:25 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2012-10-06 22:37:25 +0200
commita01c73f820813ad0c9459ecf1465cdc99093ee27 (patch)
tree926e4655df27e2d672a37e1115473b60db7f1ad1 /src/Plugins/Monitors/Bright.hs
parent1d7adde585e21f5eeb7fc44528ebb0cf7351cf7a (diff)
downloadxmobar-a01c73f820813ad0c9459ecf1465cdc99093ee27.tar.gz
xmobar-a01c73f820813ad0c9459ecf1465cdc99093ee27.tar.bz2
Whitespace and untabification
Diffstat (limited to 'src/Plugins/Monitors/Bright.hs')
-rw-r--r--src/Plugins/Monitors/Bright.hs127
1 files changed, 56 insertions, 71 deletions
diff --git a/src/Plugins/Monitors/Bright.hs b/src/Plugins/Monitors/Bright.hs
index 499e5bc..107bd89 100644
--- a/src/Plugins/Monitors/Bright.hs
+++ b/src/Plugins/Monitors/Bright.hs
@@ -14,105 +14,90 @@
module Plugins.Monitors.Bright (brightConfig, runBright) where
-import Plugins.Monitors.Common
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Char
import System.FilePath ((</>))
import System.Posix.Files (fileExist)
import System.Console.GetOpt
-data BrightOpts = BrightOpts
- { subDir :: String
- , currBright :: String
- , maxBright :: String
- }
+import Plugins.Monitors.Common
+
+data BrightOpts = BrightOpts { subDir :: String
+ , currBright :: String
+ , maxBright :: String
+ }
defaultOpts :: BrightOpts
-defaultOpts = BrightOpts
- { subDir = "acpi_video0"
- , currBright = "actual_brightness"
- , maxBright = "max_brightness"
- }
+defaultOpts = BrightOpts { subDir = "acpi_video0"
+ , currBright = "actual_brightness"
+ , maxBright = "max_brightness"
+ }
options :: [OptDescr (BrightOpts -> BrightOpts)]
-options =
- [ Option "D" ["device"] (ReqArg (\x o -> o { subDir = x }) "") ""
- , Option "C" ["curr"] (ReqArg (\x o -> o { currBright = x }) "") ""
- , Option "M" ["max"] (ReqArg (\x o -> o { maxBright = x }) "") ""
- ]
+options = [ Option "D" ["device"] (ReqArg (\x o -> o { subDir = x }) "") ""
+ , Option "C" ["curr"] (ReqArg (\x o -> o { currBright = x }) "") ""
+ , Option "M" ["max"] (ReqArg (\x o -> o { maxBright = x }) "") ""
+ ]
-- from Batt.hs
parseOpts :: [String] -> IO BrightOpts
parseOpts argv =
- case getOpt Permute options argv of
- (o, _, []) -> return $ foldr id defaultOpts o
- (_, _, errs) -> ioError . userError $ concat errs
+ case getOpt Permute options argv of
+ (o, _, []) -> return $ foldr id defaultOpts o
+ (_, _, errs) -> ioError . userError $ concat errs
sysDir :: FilePath
sysDir = "/sys/class/backlight/"
brightConfig :: IO MConfig
-brightConfig = mkMConfig
- "<percent>" -- template
- ["hbar", "percent", "bar"] -- replacements
+brightConfig = mkMConfig "<percent>" -- template
+ ["hbar", "percent", "bar"] -- replacements
-data Files = Files
- { fCurr :: String
- , fMax :: String
- } | NoFiles
+data Files = Files { fCurr :: String
+ , fMax :: String
+ }
+ | NoFiles
brightFiles :: BrightOpts -> IO Files
-brightFiles opts =
- do
- is_curr <- fileExist $ (fCurr files)
- is_max <- fileExist $ (fCurr files)
- if is_curr && is_max
- then return files
- else return NoFiles
- where
- prefix = sysDir </> (subDir opts)
- files = Files { fCurr = prefix </> (currBright opts)
- , fMax = prefix </> (maxBright opts)
- }
-
+brightFiles opts = do
+ is_curr <- fileExist $ (fCurr files)
+ is_max <- fileExist $ (fCurr files)
+ if is_curr && is_max then return files else return NoFiles
+ where prefix = sysDir </> (subDir opts)
+ files = Files { fCurr = prefix </> (currBright opts)
+ , fMax = prefix </> (maxBright opts)
+ }
runBright :: [String] -> Monitor String
runBright args = do
- opts <- io $ parseOpts args
- f <- io $ brightFiles opts
- c <- io $ readBright f
- case f of
- NoFiles -> return "hurz"
- _ -> do x <- fmtPercent c
- parseTemplate (x)
- where
- fmtPercent :: Float -> Monitor [String]
- fmtPercent c = do
- r <- showHorizontalBar (100 * c)
- s <- showPercentWithColors c
- t <- showPercentBar (100 * c) c
- return [r,s,t]
+ opts <- io $ parseOpts args
+ f <- io $ brightFiles opts
+ c <- io $ readBright f
+ case f of
+ NoFiles -> return "hurz"
+ _ -> fmtPercent c >>= parseTemplate
+ where fmtPercent :: Float -> Monitor [String]
+ fmtPercent c = do r <- showHorizontalBar (100 * c)
+ s <- showPercentWithColors c
+ t <- showPercentBar (100 * c) c
+ return [r,s,t]
readBright :: Files -> IO Float
readBright NoFiles = return 0
-readBright files =
- do
- currVal<- grab $ (fCurr files)
- maxVal <- grab $ (fMax files)
- return $ (currVal / maxVal)
- where
- grab f = catch (fmap (read . B.unpack) $ B.readFile f)(\_ -> return 0)
-
+readBright files = do
+ currVal<- grab $ (fCurr files)
+ maxVal <- grab $ (fMax files)
+ return $ (currVal / maxVal)
+ where grab f = catch (fmap (read . B.unpack) $ B.readFile f)(\_ -> return 0)
showHorizontalBar :: Float -> Monitor String
showHorizontalBar x = do
- return $ [convert x]
- where
- convert :: Float -> Char
- convert val
- | t <= 9600 = ' '
- | t > 9608 = chr 9608
- | otherwise = chr t
- where
- -- we scale from 0 to 100, we have 8 slots (9 elements), 100/8 = 12
- t = 9600 + ((round val) `div` 12)
+ return $ [convert x]
+ where convert :: Float -> Char
+ convert val
+ | t <= 9600 = ' '
+ | t > 9608 = chr 9608
+ | otherwise = chr t
+ where
+ -- we scale from 0 to 100, we have 8 slots (9 elements), 100/8 = 12
+ t = 9600 + ((round val) `div` 12)