summaryrefslogtreecommitdiffhomepage
path: root/Plugins
diff options
context:
space:
mode:
authorJose A Ortega Ruiz <jao@gnu.org>2010-04-15 23:16:16 +0200
committerJose A Ortega Ruiz <jao@gnu.org>2010-04-15 23:16:16 +0200
commit6bbdc91ea0025e816b800ea0239287f5bf763452 (patch)
treea8fd31967e9f920b53b7bae60963b1e6a82f14df /Plugins
parent316f2be0a518a21deabf26a742f0e494dddea17b (diff)
downloadxmobar-6bbdc91ea0025e816b800ea0239287f5bf763452.tar.gz
xmobar-6bbdc91ea0025e816b800ea0239287f5bf763452.tar.bz2
Some tweaks to the MBox monitor.
Ignore-this: 9d59cfdd0596e777051d318c1c5226e2 darcs-hash:20100415211616-748be-6f662a80dcd5df77707542bf4f7fc06671a424d0.gz
Diffstat (limited to 'Plugins')
-rw-r--r--Plugins/MBox.hs19
1 files changed, 12 insertions, 7 deletions
diff --git a/Plugins/MBox.hs b/Plugins/MBox.hs
index ce153e1..265e860 100644
--- a/Plugins/MBox.hs
+++ b/Plugins/MBox.hs
@@ -31,17 +31,21 @@ import qualified Data.ByteString.Lazy.Char8 as B
data Options = Options
{ oAll :: Bool
+ , oUniq :: Bool
, oDir :: FilePath
, oPrefix :: String
, oSuffix :: String
}
defaults :: Options
-defaults = Options { oAll = False, oDir = "", oPrefix = "", oSuffix = "" }
+defaults = Options {
+ oAll = False, oUniq = False, oDir = "", oPrefix = "", oSuffix = ""
+ }
options :: [OptDescr (Options -> Options)]
options =
[ Option "a" ["all"] (NoArg (\o -> o { oAll = True })) ""
+ , Option "u" [] (NoArg (\o -> o { oUniq = True })) ""
, Option "d" ["dir"] (ReqArg (\x o -> o { oDir = x }) "") ""
, Option "p" ["prefix"] (ReqArg (\x o -> o { oPrefix = x }) "") ""
, Option "s" ["suffix"] (ReqArg (\x o -> o { oSuffix = x }) "") ""
@@ -68,6 +72,7 @@ instance Exec MBox where
allb = oAll opts
pref = oPrefix opts
suff = oSuffix opts
+ uniq = oUniq opts
dirExists <- doesDirectoryExist dir
let ts = map (\(t, _, _) -> t) ms
@@ -75,7 +80,7 @@ instance Exec MBox where
md = if dirExists then (dir </>) . sec else sec
fs = map md ms
cs = map (\(_, _, c) -> c) ms
- ev = [Modify, Create]
+ ev = [CloseWrite]
i <- initINotify
zipWithM_ (\f v -> addWatch i ev f (handleNotification v)) fs vs
@@ -86,14 +91,14 @@ instance Exec MBox where
atomically $ writeTVar v (f, n)
changeLoop (mapM (fmap snd . readTVar) vs) $ \ns ->
- let s = unwords [ showC m n c | (m, n, c) <- zip3 ts ns cs
- , allb || n /= 0 ]
+ let s = unwords [ showC uniq m n c | (m, n, c) <- zip3 ts ns cs
+ , allb || n /= 0 ]
in cb (if length s == 0 then "" else pref ++ s ++ suff)
-showC :: String -> Int -> String -> String
-showC m n c =
+showC :: Bool -> String -> Int -> String -> String
+showC u m n c =
if c == "" then msg else "<fc=" ++ c ++ ">" ++ msg ++ "</fc>"
- where msg = m ++ show n
+ where msg = m ++ if not u || n > 1 then show n else ""
countMails :: FilePath -> IO Int
countMails f =