From 691f97181129642b5a1bd4d2e347afb182db90a5 Mon Sep 17 00:00:00 2001 From: nzeh <nzeh@cs.dal.ca> Date: Wed, 18 Mar 2009 23:51:52 +0100 Subject: Allow color markup in monitor output templates With this patch, colors can be included in the output template of a monitor. E.g., ["-t", "TX <fc darcs-hash:20090318225152-c6b6b-54a807a7f88612b89fdbf7e0ba5ecc0336a5cfa1.gz --- Plugins/Monitors/Common.hs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'Plugins/Monitors') diff --git a/Plugins/Monitors/Common.hs b/Plugins/Monitors/Common.hs index 03b40d8..1b5cb60 100644 --- a/Plugins/Monitors/Common.hs +++ b/Plugins/Monitors/Common.hs @@ -196,19 +196,30 @@ skipTillString s = -- | Parses the output template string templateStringParser :: Parser (String,String,String) templateStringParser = - do{ s <- many $ noneOf "<" - ; (_,com,_) <- templateCommandParser - ; ss <- many $ noneOf "<" - ; return (s, com, ss) - } + do { s <- nonPlaceHolder + ; com <- templateCommandParser + ; ss <- nonPlaceHolder + ; return (s, com, ss) + } + where + nonPlaceHolder = liftM concat . many $ + (many1 $ noneOf "<") <|> colorSpec + +-- | Recognizes color specification and returns it unchanged +colorSpec :: Parser String +colorSpec = (try $ string "</fc>") <|> try ( + do string "<fc=" + s <- many1 (alphaNum <|> char ',' <|> char '#') + char '>' + return $ "<fc=" ++ s ++ ">") -- | Parses the command part of the template string -templateCommandParser :: Parser (String,String,String) +templateCommandParser :: Parser String templateCommandParser = do { char '<' ; com <- many $ noneOf ">" ; char '>' - ; return $ ("",com,"") + ; return com } -- | Combines the template parsers -- cgit v1.2.3