diff options
Diffstat (limited to 'src/Xmobar')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Disk.hs | 74 | ||||
-rw-r--r-- | src/Xmobar/Plugins/Monitors/MPD.hs | 10 |
2 files changed, 37 insertions, 47 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Disk.hs b/src/Xmobar/Plugins/Monitors/Disk.hs index 6af99a1..debc522 100644 --- a/src/Xmobar/Plugins/Monitors/Disk.hs +++ b/src/Xmobar/Plugins/Monitors/Disk.hs @@ -34,26 +34,24 @@ data DiskIOOpts = DiskIOOpts , contiguous :: Bool } -parseDiskIOOpts :: [String] -> IO DiskIOOpts -parseDiskIOOpts argv = - case getOpt Permute options argv of - (o, _, []) -> return $ foldr id defaultOpts o - (_, _, errs) -> ioError . userError $ concat errs - where defaultOpts = DiskIOOpts - { totalIconPattern = Nothing - , writeIconPattern = Nothing - , readIconPattern = Nothing - , contiguous = False - } - options = - [ Option "" ["total-icon-pattern"] (ReqArg (\x o -> - o { totalIconPattern = Just $ parseIconPattern x}) "") "" - , Option "" ["write-icon-pattern"] (ReqArg (\x o -> - o { writeIconPattern = Just $ parseIconPattern x}) "") "" - , Option "" ["read-icon-pattern"] (ReqArg (\x o -> - o { readIconPattern = Just $ parseIconPattern x}) "") "" - , Option "c" ["contiguous"] (NoArg (\o -> o {contiguous = True})) "" - ] +dioDefaultOpts :: DiskIOOpts +dioDefaultOpts = DiskIOOpts + { totalIconPattern = Nothing + , writeIconPattern = Nothing + , readIconPattern = Nothing + , contiguous = False + } + +dioOptions :: [OptDescr (DiskIOOpts -> DiskIOOpts)] +dioOptions = + [ Option "" ["total-icon-pattern"] (ReqArg (\x o -> + o { totalIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["write-icon-pattern"] (ReqArg (\x o -> + o { writeIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["read-icon-pattern"] (ReqArg (\x o -> + o { readIconPattern = Just $ parseIconPattern x}) "") "" + , Option "c" ["contiguous"] (NoArg (\o -> o {contiguous = True})) "" + ] diskIOConfig :: IO MConfig diskIOConfig = mkMConfig "" ["total", "read", "write" @@ -72,23 +70,21 @@ data DiskUOpts = DiskUOpts , contiguousU :: Bool } -parseDiskUOpts :: [String] -> IO DiskUOpts -parseDiskUOpts argv = - case getOpt Permute options argv of - (o, _, []) -> return $ foldr id defaultOpts o - (_, _, errs) -> ioError . userError $ concat errs - where defaultOpts = DiskUOpts - { freeIconPattern = Nothing - , usedIconPattern = Nothing - , contiguousU = False - } - options = - [ Option "" ["free-icon-pattern"] (ReqArg (\x o -> - o { freeIconPattern = Just $ parseIconPattern x}) "") "" - , Option "" ["used-icon-pattern"] (ReqArg (\x o -> - o { usedIconPattern = Just $ parseIconPattern x}) "") "" - , Option "c" ["contiguous"] (NoArg (\o -> o {contiguousU = True})) "" - ] +duDefaultOpts :: DiskUOpts +duDefaultOpts = DiskUOpts + { freeIconPattern = Nothing + , usedIconPattern = Nothing + , contiguousU = False + } + +duOptions :: [OptDescr (DiskUOpts -> DiskUOpts)] +duOptions = + [ Option "" ["free-icon-pattern"] (ReqArg (\x o -> + o { freeIconPattern = Just $ parseIconPattern x}) "") "" + , Option "" ["used-icon-pattern"] (ReqArg (\x o -> + o { usedIconPattern = Just $ parseIconPattern x}) "") "" + , Option "c" ["contiguous"] (NoArg (\o -> o {contiguousU = True})) "" + ] diskUConfig :: IO MConfig diskUConfig = mkMConfig "" @@ -208,7 +204,7 @@ runDiskIO' opts (tmp, xs) = do runDiskIO :: DevDataRef -> [(String, String)] -> [String] -> Monitor String runDiskIO dref disks argv = do - opts <- io $ parseDiskIOOpts argv + opts <- io $ parseOptsWith dioOptions dioDefaultOpts argv dev <- io $ mountedOrDiskDevices (map fst disks) dat <- io $ mountedData dref (map fst dev) strs <- mapM (runDiskIO' opts) $ devTemplates disks dev dat @@ -254,6 +250,6 @@ runDiskU' opts tmp path = do runDiskU :: [(String, String)] -> [String] -> Monitor String runDiskU disks argv = do devs <- io $ mountedDevices (map fst disks) - opts <- io $ parseDiskUOpts argv + opts <- io $ parseOptsWith duOptions duDefaultOpts argv strs <- mapM (\(d, p) -> runDiskU' opts (findTempl d p disks) p) devs return $ (if contiguousU opts then concat else unwords) strs diff --git a/src/Xmobar/Plugins/Monitors/MPD.hs b/src/Xmobar/Plugins/Monitors/MPD.hs index cd08cda..3274c42 100644 --- a/src/Xmobar/Plugins/Monitors/MPD.hs +++ b/src/Xmobar/Plugins/Monitors/MPD.hs @@ -64,7 +64,7 @@ withMPD opts = M.withMPD_ (mHost opts) (mPort opts) runMPD :: [String] -> Monitor String runMPD args = do - opts <- io $ mopts args + opts <- io $ parseOptsWith options defaultOpts args status <- io $ withMPD opts M.status song <- io $ withMPD opts M.currentSong s <- parseMPD status song opts @@ -79,7 +79,7 @@ mpdWait = do mpdReady :: [String] -> Monitor Bool mpdReady args = do - opts <- io $ mopts args + opts <- io $ parseOptsWith options defaultOpts args response <- io $ withMPD opts M.ping case response of Right _ -> return True @@ -89,12 +89,6 @@ mpdReady args = do Left (M.ConnectionError _) -> return False Left _ -> return True -mopts :: [String] -> IO MOpts -mopts argv = - case getOpt Permute options argv of - (o, _, []) -> return $ foldr id defaultOpts o - (_, _, errs) -> ioError . userError $ concat errs - parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts -> Monitor [String] parseMPD (Left e) _ _ = return $ show e:replicate 19 "" |