From 6150993d0528b2a081b3d7e0b7e76732a611625d Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 13 Nov 2019 23:49:52 +0000 Subject: MPD monitor: host and port specifiable in config --- changelog.md | 1 + readme.md | 4 +++- src/Xmobar/Plugins/Monitors/MPD.hs | 18 ++++++++++++++---- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 2c3098c..97e866a 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ _New features_ + - New options `--host` and `--port` for `MPD` monitor. - New plugin `MailX` extending `Mail` with colors and prefix/suffix. - New options `--lows`, `--mediums`, and `--highs` for `Battery` to display an additional string depending on battery level (thanks diff --git a/readme.md b/readme.md index 10eb91b..903149d 100644 --- a/readme.md +++ b/readme.md @@ -1214,7 +1214,9 @@ following differences: `-S` and `-Z`, with an string argument, to represent the playing, stopped and paused states in the `statei` template field. The environment variables `MPD_HOST` and `MPD_PORT` are used to - configure the mpd server to communicate with. Also available: + configure the mpd server to communicate with, unless given in the + additional arguments `-p` (`--port`) and `-h` (`--host`). Also + available: - `lapsed-icon-pattern`: dynamic string for current track position in `ipat`. - Variables that can be used with the `-t`/`--template` argument: `bar`, `vbar`, `ipat`, `state`, `statei`, `volume`, `length`, diff --git a/src/Xmobar/Plugins/Monitors/MPD.hs b/src/Xmobar/Plugins/Monitors/MPD.hs index b6d154a..cd08cda 100644 --- a/src/Xmobar/Plugins/Monitors/MPD.hs +++ b/src/Xmobar/Plugins/Monitors/MPD.hs @@ -34,6 +34,8 @@ data MOpts = MOpts , mStopped :: String , mPaused :: String , mLapsedIconPattern :: Maybe IconPattern + , mPort :: Maybe String + , mHost :: Maybe String } defaultOpts :: MOpts @@ -42,6 +44,8 @@ defaultOpts = MOpts , mStopped = "><" , mPaused = "||" , mLapsedIconPattern = Nothing + , mPort = Nothing + , mHost = Nothing } options :: [OptDescr (MOpts -> MOpts)] @@ -49,15 +53,20 @@ options = [ Option "P" ["playing"] (ReqArg (\x o -> o { mPlaying = x }) "") "" , Option "S" ["stopped"] (ReqArg (\x o -> o { mStopped = x }) "") "" , Option "Z" ["paused"] (ReqArg (\x o -> o { mPaused = x }) "") "" + , Option "p" ["port"] (ReqArg (\x o -> o { mPort = Just x }) "") "" + , Option "h" ["host"] (ReqArg (\x o -> o { mHost = Just x }) "") "" , Option "" ["lapsed-icon-pattern"] (ReqArg (\x o -> o { mLapsedIconPattern = Just $ parseIconPattern x }) "") "" ] +withMPD :: MOpts -> M.MPD a -> IO (M.Response a) +withMPD opts = M.withMPD_ (mHost opts) (mPort opts) + runMPD :: [String] -> Monitor String runMPD args = do opts <- io $ mopts args - status <- io $ M.withMPD M.status - song <- io $ M.withMPD M.currentSong + status <- io $ withMPD opts M.status + song <- io $ withMPD opts M.currentSong s <- parseMPD status song opts parseTemplate s @@ -69,8 +78,9 @@ mpdWait = do _ -> return () mpdReady :: [String] -> Monitor Bool -mpdReady _ = do - response <- io $ M.withMPD M.ping +mpdReady args = do + opts <- io $ mopts args + response <- io $ withMPD opts M.ping case response of Right _ -> return True -- Only cases where MPD isn't responding is an issue; bogus information at -- cgit v1.2.3