summaryrefslogtreecommitdiffhomepage
path: root/Parsers.hs
diff options
context:
space:
mode:
authorAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-12 19:50:34 +0200
committerAndrea Rossato <andrea.rossato@ing.unitn.it>2007-07-12 19:50:34 +0200
commite85b0920a06ad019754e1cb8e72eb6cc34cdeedc (patch)
tree34a28f6a54290bd7347f83efc4a7a5f387419f31 /Parsers.hs
parent14267de1e03841980ce99206c0cf63e40bfa6cca (diff)
downloadxmobar-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 'Parsers.hs')
-rw-r--r--Parsers.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/Parsers.hs b/Parsers.hs
index fa85193..8c25004 100644
--- a/Parsers.hs
+++ b/Parsers.hs
@@ -27,6 +27,7 @@ module Parsers (
import Config
import Commands
+import Runnable
import Text.ParserCombinators.Parsec
import qualified Data.Map as Map
@@ -103,20 +104,20 @@ templateParser :: Config -> Parser [(String,String,String)]
templateParser c = many (templateStringParser c)
-- | Actually runs the template parsers
-parseTemplate :: Config -> String -> IO [(Command,String,String)]
+parseTemplate :: Config -> String -> IO [(Runnable,String,String)]
parseTemplate config s =
do str <- case (parse (templateParser config) "" s) of
Left _ -> return [("","","")]
Right x -> return x
- let comList = map (show . fst) $ commands config
- m = Map.fromList . zip comList . map fst $ (commands config)
- return $ combine m str
+ let comList = map alias (commands config)
+ m = Map.fromList $ zip comList (commands config)
+ return $ combine config m str
-- | Given a finite "Map" and a parsed templatet produces the
-- | resulting output string.
-combine :: Map.Map String Command -> [(String, String, String)] -> [(Command,String,String)]
-combine _ [] = []
-combine m ((ts,s,ss):xs) =
- [(com, s, ss)] ++ combine m xs
+combine :: Config -> Map.Map String Runnable -> [(String, String, String)] -> [(Runnable,String,String)]
+combine _ _ [] = []
+combine config m ((ts,s,ss):xs) =
+ [(com, s, ss)] ++ combine config m xs
where com = Map.findWithDefault dflt ts m
- dflt = Exec ts [] [] --"<" ++ ts ++ " not found!>"
+ dflt = Run $ Com ts [] [] (refresh config) --"<" ++ ts ++ " not found!>"