summaryrefslogtreecommitdiffhomepage
path: root/Plugins/Monitors
diff options
context:
space:
mode:
authorJose A Ortega Ruiz <jao@gnu.org>2010-11-18 23:03:25 +0100
committerJose A Ortega Ruiz <jao@gnu.org>2010-11-18 23:03:25 +0100
commitf590bb2676c0fcdc2186d75284d353ce962dabd8 (patch)
treea0aa732e3bf584c57ab3e2c00dac3a4c3cc8c55a /Plugins/Monitors
parentcd0b3a4a3b7c485881e00eab593fbff32b9ebd01 (diff)
downloadxmobar-f590bb2676c0fcdc2186d75284d353ce962dabd8.tar.gz
xmobar-f590bb2676c0fcdc2186d75284d353ce962dabd8.tar.bz2
Fix for Issue #31
Ignore-this: ead0c61014e3de632e8deb4a4470bdc6 darcs-hash:20101118220325-748be-3b86256dc6fc57d9ce8178266a952edb5db0912a.gz
Diffstat (limited to 'Plugins/Monitors')
-rw-r--r--Plugins/Monitors/MPD.hs30
1 files changed, 16 insertions, 14 deletions
diff --git a/Plugins/Monitors/MPD.hs b/Plugins/Monitors/MPD.hs
index 349e237..b97eca4 100644
--- a/Plugins/Monitors/MPD.hs
+++ b/Plugins/Monitors/MPD.hs
@@ -61,9 +61,8 @@ runMPD args = do
let mpd = M.withMPDEx (mHost opts) (mPort opts) (mPassword opts)
status <- io $ mpd M.status
song <- io $ mpd M.currentSong
- let (b, s) = parseMPD status song opts
- bs <- showPercentBar (100 * b) b
- parseTemplate (bs:s)
+ s <- parseMPD status song opts
+ parseTemplate s
mopts :: [String] -> IO MOpts
mopts argv =
@@ -72,17 +71,19 @@ mopts argv =
(_, _, errs) -> ioError . userError $ concat errs
parseMPD :: M.Response M.Status -> M.Response (Maybe M.Song) -> MOpts
- -> (Float, [String])
-parseMPD (Left e) _ _ = (0, show e:repeat "")
-parseMPD (Right st) song opts =
- (bar, [ss, si, vol, len, lap, remain, plen, ppos] ++ parseSong song)
+ -> Monitor [String]
+parseMPD (Left e) _ _ = return $ show e:repeat ""
+parseMPD (Right st) song opts = do
+ songData <- parseSong song
+ bar <- showPercentBar (100 * b) b
+ return $ [bar, ss, si, vol, len, lap, remain, plen, ppos] ++ songData
where s = M.stState st
ss = show s
si = stateGlyph s opts
vol = int2str $ M.stVolume st
(p, t) = M.stTime st
[lap, len, remain] = map showTime [floor p, t, max 0 (t - floor p)]
- bar = if t > 0 then realToFrac $ p / fromIntegral t else 0
+ b = if t > 0 then realToFrac $ p / fromIntegral t else 0
plen = int2str $ M.stPlaylistLength st
ppos = maybe "" (int2str . (+1)) $ M.stSongPos st
@@ -93,12 +94,13 @@ stateGlyph s o =
M.Paused -> mPaused o
M.Stopped -> mStopped o
-parseSong :: M.Response (Maybe M.Song) -> [String]
-parseSong (Left _) = repeat ""
-parseSong (Right Nothing) = repeat ""
-parseSong (Right (Just s)) =
- M.sgFilePath s : map str [ M.Name, M.Artist, M.Composer, M.Performer
- , M.Album, M.Title, M.Track, M.Genre ]
+parseSong :: M.Response (Maybe M.Song) -> Monitor [String]
+parseSong (Left _) = return $ repeat ""
+parseSong (Right Nothing) = return $ repeat ""
+parseSong (Right (Just s)) = do
+ let x = M.sgFilePath s : map str [ M.Name, M.Artist, M.Composer, M.Performer
+ , M.Album, M.Title, M.Track, M.Genre ]
+ mapM showWithPadding x
where join [] = ""
join (x:xs) = foldl (\a o -> a ++ ", " ++ o) x xs
str sel = maybe "" join (M.sgGet sel s)