summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2013-06-05 00:23:32 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2013-06-05 00:23:32 +0200
commit85fdac20a36675559802dd215a81f640b91693fe (patch)
tree8fff8ccb15e611547f9501cd53fd569917769510
parent3d1fe35837bc756a96f8bf529455794bc1ac7d8b (diff)
downloadxmobar-85fdac20a36675559802dd215a81f640b91693fe.tar.gz
xmobar-85fdac20a36675559802dd215a81f640b91693fe.tar.bz2
Stripping actions in stdin and xprop plugins
-rw-r--r--src/Actions.hs7
-rw-r--r--src/Plugins/StdinReader.hs19
-rw-r--r--src/Plugins/XMonadLog.hs8
-rw-r--r--xmobar.cabal1
4 files changed, 22 insertions, 13 deletions
diff --git a/src/Actions.hs b/src/Actions.hs
index cba027b..f3dc55a 100644
--- a/src/Actions.hs
+++ b/src/Actions.hs
@@ -10,13 +10,18 @@
--
-----------------------------------------------------------------------------
-module Actions where
+module Actions (Action(..), runAction, stripActions) where
import System.Process (system)
import Control.Monad (void)
+import Text.Regex (subRegex, mkRegex)
data Action = Spawn String
deriving (Eq)
runAction :: Action -> IO ()
runAction (Spawn s) = void $ system (s ++ "&")
+
+stripActions :: String -> String
+stripActions s = subRegex actionRegex s "[action=\1]\2[action]"
+ where actionRegex = mkRegex "<action=([^>])*>(.+?)</action>"
diff --git a/src/Plugins/StdinReader.hs b/src/Plugins/StdinReader.hs
index fddd0bc..f242f93 100644
--- a/src/Plugins/StdinReader.hs
+++ b/src/Plugins/StdinReader.hs
@@ -20,15 +20,16 @@ import System.Exit
import System.IO
import Control.Exception (SomeException(..), handle)
import Plugins
+import Actions (stripActions)
-data StdinReader = StdinReader
- deriving (Read, Show)
+data StdinReader = StdinReader deriving (Read, Show)
instance Exec StdinReader where
- start StdinReader cb = do
- cb =<< handle (\(SomeException e) -> do hPrint stderr e; return "")
- (hGetLineSafe stdin)
- eof <- hIsEOF stdin
- if eof
- then exitImmediately ExitSuccess
- else start StdinReader cb
+ start StdinReader cb = do
+ s <- handle (\(SomeException e) -> do hPrint stderr e; return "")
+ (hGetLineSafe stdin)
+ cb (stripActions s)
+ eof <- hIsEOF stdin
+ if eof
+ then exitImmediately ExitSuccess
+ else start StdinReader cb
diff --git a/src/Plugins/XMonadLog.hs b/src/Plugins/XMonadLog.hs
index 1403800..8f63dc9 100644
--- a/src/Plugins/XMonadLog.hs
+++ b/src/Plugins/XMonadLog.hs
@@ -28,9 +28,11 @@ import Codec.Binary.UTF8.String as UTF8
#endif
import Foreign.C (CChar)
import XUtil (nextEvent')
+import Actions (stripActions)
-
-data XMonadLog = XMonadLog | XPropertyLog String | NamedXPropertyLog String String
+data XMonadLog = XMonadLog
+ | XPropertyLog String
+ | NamedXPropertyLog String String
deriving (Read, Show)
instance Exec XMonadLog where
@@ -51,7 +53,7 @@ instance Exec XMonadLog where
let update = do
mwp <- getWindowProperty8 d xlog root
- maybe (return ()) (cb . decodeCChar) mwp
+ maybe (return ()) (cb . stripActions. decodeCChar) mwp
update
diff --git a/xmobar.cabal b/xmobar.cabal
index bc0028a..b88301f 100644
--- a/xmobar.cabal
+++ b/xmobar.cabal
@@ -97,6 +97,7 @@ executable xmobar
build-depends:
base == 4.*,
containers,
+ regex-compat,
process,
old-locale,
bytestring,