From 0cef0a9fded62e1d425124fd28db06f869d7f308 Mon Sep 17 00:00:00 2001 From: Andrea Rossato Date: Tue, 26 Jun 2007 10:06:19 +0200 Subject: added refresh rate config option for each command to be run darcs-hash:20070626080619-d6583-2d486498682a2f4e59c66effbfeb6861c609aef5.gz --- xmobar.config-sample | 2 +- xmobar.hs | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/xmobar.config-sample b/xmobar.config-sample index 108e870..ad333bc 100644 --- a/xmobar.config-sample +++ b/xmobar.config-sample @@ -7,7 +7,7 @@ Config { fonts = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*" , hight = 15 , align = "right" , refresh = 10 - , commands = [("xmb-net", ["eth1"])] + , commands = [("xmb-net", 10, ["eth1"])] , sepChar = "%" , template = "%xmb-cpu% %xmb-mem% %xmb-net% %date%" } diff --git a/xmobar.hs b/xmobar.hs index 9f74302..d13a760 100644 --- a/xmobar.hs +++ b/xmobar.hs @@ -79,7 +79,8 @@ data Config = , hight :: Int -- ^ Window hight , align :: String -- ^ text alignment , refresh :: Int -- ^ Refresh rate in tenth of seconds - , commands :: [(String,[String])] -- ^ For setting the options of the programs to run (optionals) + , commands :: [(String, Int, [String])] -- ^ For setting the refresh rate and + -- options for the programs to run (optionals) , sepChar :: String -- ^ The character to be used for indicating -- commands in the output template (default '%') , template :: String -- ^ The output template @@ -96,7 +97,7 @@ defaultConfig = , hight = 15 , align = "left" , refresh = 10 - , commands = [] + , commands = [("date", 100, [])] , sepChar = "%" , template = "Uptime: %uptime% ** %date%" } @@ -207,11 +208,20 @@ printStrings config dpy win gc fontst offs sl@((s,c,l):xs) = getOptions :: Config -> String -> [String] getOptions c com = let l = commands c - p = filter (\(s,_) -> s == com) l + p = filter (\(s,_,_) -> s == com) l in case p of - [(_,opts)] -> opts + [(_,_,opts)] -> opts _ -> [] +-- | Gets the command options set in configuration. +getRefRate :: Config -> String -> Int +getRefRate c com = + let l = commands c + p = filter (\(s,_,_) -> s == com) l + in case p of + [(_,int,_)] -> int + _ -> refresh c + -- | Runs a list of programs execCommands :: Config -> [(String,String,String)] -> IO [(ThreadId, MVar String)] execCommands _ [] = return [] @@ -245,18 +255,18 @@ runCommandLoop var conf c@(s,com,ss) ExitSuccess -> do str <- hGetLine o closeHandles modifyMVar_ var (\_ -> return $ s ++ str ++ ss) - threadDelay $ 100000 * refresh conf + threadDelay $ 100000 * (getRefRate conf com) runCommandLoop var conf c _ -> do closeHandles modifyMVar_ var $ \_ -> return $ "Could not execute command " ++ com - threadDelay $ 100000 * refresh conf + threadDelay $ 100000 * (getRefRate conf com) runCommandLoop var conf c -- | Reads MVars set by 'runCommandLoop' readVariables :: [(ThreadId, MVar String)] -> IO String readVariables [] = return "" -readVariables ((h,v):xs) = +readVariables ((_,v):xs) = do f <- readMVar v fs <- readVariables xs return $! f ++ fs -- cgit v1.2.3