From e909c3b8c6887b2fcee1debf34499794e5accac1 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Sat, 22 Jan 2011 03:33:08 +0100 Subject: Bug fix: don't get confused by align separators in input (issue 14) This solves the common case of a template separator character (such as {) popping up in xmobar's input (e.g., inside a window title) and confusing the parser. --- src/Main.hs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/Main.hs') diff --git a/src/Main.hs b/src/Main.hs index aad87e7..c069b8e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -60,11 +60,26 @@ main = do doOpts civ o conf <- readIORef civ fs <- initFont d (font conf) - cl <- parseTemplate conf (template conf) - vars <- mapM startCommand cl + cls <- mapM (parseTemplate conf) (splitTemplate conf) + vars <- mapM (mapM startCommand) cls (r,w) <- createWin d fs conf eventLoop (XConf d r w fs conf) vars +-- | Splits the template in its parts +splitTemplate :: Config -> [String] +splitTemplate conf = + case break (==l) t of + (le,_:re) -> case break (==r) re of + (ce,_:ri) -> [le, ce, ri] + _ -> def + _ -> def + where [l, r] = if length (alignSep conf) == 2 + then alignSep conf + else alignSep defaultConfig + t = template conf + def = [t, "", ""] + + -- | Reads the configuration files or quits with an error readConfig :: FilePath -> IO (Config,[String]) readConfig f = do -- cgit v1.2.3