diff options
author | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-12 19:50:34 +0200 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@ing.unitn.it> | 2007-07-12 19:50:34 +0200 |
commit | e85b0920a06ad019754e1cb8e72eb6cc34cdeedc (patch) | |
tree | 34a28f6a54290bd7347f83efc4a7a5f387419f31 /XMobar.hs | |
parent | 14267de1e03841980ce99206c0cf63e40bfa6cca (diff) | |
download | xmobar-e85b0920a06ad019754e1cb8e72eb6cc34cdeedc.tar.gz xmobar-e85b0920a06ad019754e1cb8e72eb6cc34cdeedc.tar.bz2 |
use of existential types for plugin support
This patch, which *changes the configuration format*, adds easy plugin support
by using an existential type for storing the list of commands to be
executed. Adding a plugin is just a matter of writing the appropriate
instance of the Exec class, after importing Commands.hs.
I must thank Claus Reinke for the help in understanding the mysteries of
reading existential types. The Read instance of Runnable must be credited to
him. See here:
http://www.haskell.org/pipermail/haskell-cafe/2007-July/028227.html
darcs-hash:20070712175034-d6583-f10174bb3b0a9b4f6e08d05052c18f30e539b319.gz
Diffstat (limited to 'XMobar.hs')
-rw-r--r-- | XMobar.hs | 18 |
1 files changed, 5 insertions, 13 deletions
@@ -47,6 +47,7 @@ import Control.Concurrent import Config import Parsers import Commands +import Runnable -- $main -- @@ -163,31 +164,22 @@ printStrings p gc fontst offs sl@((s,c,l):xs) = -- $commands --- | Gets the refresh rate set in configuration for a given command. -getRefRate :: Config -> Command -> 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 as independent threads and returns their thread id -- and the MVar they will be writing to. -execCommands :: Config -> [(Command,String,String)] -> IO [(ThreadId, MVar String)] +execCommands :: Config -> [(Runnable,String,String)] -> IO [(ThreadId, MVar String)] execCommands _ [] = return [] execCommands c (x:xs) = do i <- execCommand c x is <- execCommands c xs return $ i : is -execCommand :: Config -> (Command,String,String) -> IO (ThreadId, MVar String) +execCommand :: Config -> (Runnable,String,String) -> IO (ThreadId, MVar String) execCommand c com = do var <- newMVar "Updating..." h <- forkIO $ runCommandLoop var c com return (h,var) -runCommandLoop :: MVar String -> Config -> (Command,String,String) -> IO () +runCommandLoop :: MVar String -> Config -> (Runnable,String,String) -> IO () runCommandLoop var conf c@(com,s,ss) | show com == "" = do modifyMVar_ var (\_ -> return $ "Could not parse the template") @@ -196,7 +188,7 @@ runCommandLoop var conf c@(com,s,ss) | otherwise = do str <- run com modifyMVar_ var (\_ -> return $ s ++ str ++ ss) - tenthSeconds (getRefRate conf com) + tenthSeconds (rate com) runCommandLoop var conf c -- | Reads MVars set by 'runCommandLoop' |