summaryrefslogtreecommitdiffhomepage
path: root/src/Parsers.hs
diff options
context:
space:
mode:
authorMarcin Mikołajczyk <marcinmikolajcz@gmail.com>2014-02-20 15:27:43 +0100
committerMarcin Mikołajczyk <marcinmikolajcz@gmail.com>2014-02-20 15:27:43 +0100
commit6ef984e25433608183004086f21a75e51209012c (patch)
tree0c7401c21cd08b6c3a313a3dcb20562e886040ce /src/Parsers.hs
parentfc240b66c24b8d257299c9ccc8e51f30129e774c (diff)
downloadxmobar-6ef984e25433608183004086f21a75e51209012c.tar.gz
xmobar-6ef984e25433608183004086f21a75e51209012c.tar.bz2
Change actions syntax
Diffstat (limited to 'src/Parsers.hs')
-rw-r--r--src/Parsers.hs32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/Parsers.hs b/src/Parsers.hs
index 2b00f37..a1d60d8 100644
--- a/src/Parsers.hs
+++ b/src/Parsers.hs
@@ -56,17 +56,11 @@ textParser c a = do s <- many1 $
noneOf "<" <|>
try (notFollowedBy' (char '<')
(try (string "fc=") <|>
- try (tryChoice openings) <|>
- try (tryChoice closings) <|>
+ try (string "action=") <|>
+ try (string "/action>") <|>
try (string "icon=") <|>
string "/fc>"))
return [(Text s, c, a)]
- where
- openings = map (++ "=") buttons
- closings = map (\s -> '/' : s ++ ">") buttons
-
- tryChoice strs = choice $ map (try . string) strs
-
-- | Wrapper for notFollowedBy that returns the result of the first parser.
-- Also works around the issue that, at least in Parsec 3.0.0, notFollowedBy
@@ -85,26 +79,22 @@ iconParser c a = do
actionParser :: String -> Maybe [Action] -> Parser [(Widget, ColorString, Maybe [Action])]
actionParser c act = do
- string "<"
- button <- choice $ map (try . string) buttons
- command <- between (string "=") (string ">") (many1 (noneOf ">"))
- let a = Spawn (toButton button) command
+ string "<action="
+ command <- choice [between (char '`') (char '`') (many1 (noneOf "`")),
+ many1 (noneOf ">")]
+ buttons <- (char '>' >> return "1") <|> (space >> spaces >>
+ between (string "button=") (string ">") (many1 (oneOf "12345")))
+ let a = Spawn (toButtons buttons) command
a' = case act of
Nothing -> Just [a]
Just act' -> Just $ a : act'
s <- manyTill (try (textParser c a') <|> try (iconParser c a') <|>
try (colorParser a') <|> actionParser c a')
- (try $ string $ "</" ++ button ++ ">")
+ (try $ string "</action>")
return (concat s)
--- List of accepted buttons plus action for backward compatibility
-buttons :: [String]
-buttons = "action" : zipWith (++) (repeat "button") (map show ([1..5] :: [Int]))
-
-toButton :: String -> Button
-toButton s = case s of
- "action" -> 1
- _ -> read $ [last s]
+toButtons :: String -> [Button]
+toButtons s = map (\x -> read [x]) s
-- | Parsers a string wrapped in a color specification.
colorParser :: Maybe [Action] -> Parser [(Widget, ColorString, Maybe [Action])]