packages feed

xmonad-extras 0.13.1 → 0.13.2

raw patch · 5 files changed

+129/−25 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ XMonad.Prompt.MPD: addAndPlayAny :: RunMPD -> XPConfig -> [Metadata] -> X ()
+ XMonad.Prompt.MPD: addAndPlayWith :: (String -> String -> Bool) -> RunMPD -> XPConfig -> [Metadata] -> X ()
+ XMonad.Prompt.MPD: addMatchingWith :: (String -> String -> Bool) -> RunMPD -> XPConfig -> [Metadata] -> X [Int]
+ XMonad.Prompt.MPD: findMatchingWith :: (String -> String -> Bool) -> RunMPD -> XPConfig -> [Metadata] -> X [Song]
+ XMonad.Prompt.MPD: loadPlaylist :: RunMPD -> XPConfig -> X ()
+ XMonad.Prompt.MPD: loadPlaylistWith :: (String -> String -> Bool) -> RunMPD -> XPConfig -> X ()
+ XMonad.Prompt.MPD: pickPlayListItem :: RunMPD -> XPConfig -> X ()

Files

CHANGELOG.md view
@@ -1,5 +1,10 @@+# 0.13.2++* Add additional functions to MPD. (Credits to @u11gh)+ # 0.13.1  * Remove small_base flag. * Remove unused dependencies like process, random, unix, directory, old-time, old-locale * Remove ghc-options specific to 6.10.1, 7.2+
README.md view
@@ -2,5 +2,9 @@ ---------------  [![Build Status](https://travis-ci.org/xmonad/xmonad-extras.svg?branch=master)](https://travis-ci.org/xmonad/xmonad-extras)+[![Hackage](https://img.shields.io/hackage/v/xmonad-extras.svg)](https://hackage.haskell.org/package/xmonad-extras)+[![Stackage Nightly](http://stackage.org/package/xmonad-extras/badge/nightly)](http://stackage.org/nightly/package/xmonad-extras)+[![Stackage LTS](http://stackage.org/package/xmonad-extras/badge/lts)](http://stackage.org/lts/package/xmonad-extras)+  Third party extensions for xmonad with wacky dependencies
XMonad/Prompt/Eval.hs view
@@ -8,7 +8,7 @@ -- Stability   :  unstable -- Portability :  unportable ----- A prompt for evaluating Haskell expressions(in the context of the running+-- A prompt for evaluating Haskell expressions (in the context of the running -- xmonad instance). -- -----------------------------------------------------------------------------
XMonad/Prompt/MPD.hs view
@@ -20,20 +20,30 @@  module XMonad.Prompt.MPD (-- * Usage                           -- $usage-                          findMatching-                         ,addMatching-                         ,addAndPlay-                         ,RunMPD-                         ,findOrAdd+                          findMatching,+                          findMatchingWith,+                          addMatching,+                          addMatchingWith,+                          addAndPlay,+                          addAndPlayWith,+                          loadPlaylist,+                          loadPlaylistWith,+                          addAndPlayAny,+                          pickPlayListItem,+                          RunMPD,+                          findOrAdd                          )  where import Control.Monad import Data.Char+import Data.List as L import qualified Data.Map as M import Data.Maybe+import Data.String import Network.MPD-import XMonad+import XMonad hiding ((=?)) import XMonad.Prompt-import Data.List as L (nub,isPrefixOf,find)+import Data.List as L (find, isPrefixOf, nub)+import qualified Data.ByteString.Char8 as C  -- $usage --@@ -75,16 +85,17 @@                        M.lookup meta . M.map (map toString) . sgTags  -- | Creates a case-insensitive completion function from a list.-mkComplLst :: [String] -> String -> IO [String]-mkComplLst lst s = return . filter isPrefix' $ lst-    where isPrefix' s' = map toLower s `isPrefixOf` map toLower s'+mkComplLst :: (String -> String -> Bool) -> [String] -> String -> IO [String]+mkComplLst cmp lst s = return . filter matches $ lst+    where matches s' = map toLower s `cmp` map toLower s'  -- | Helper function for 'findMatching'-findMatching' :: XPConfig -> [Song] -> Metadata -> X [Song]-findMatching' _ [] _ = return []-findMatching' xp songs meta = do+findMatching' :: (String -> String -> Bool) -> XPConfig -> [Song] -> Metadata+              -> X [Song]+findMatching' _ _ [] _ = return []+findMatching' cmp xp songs meta = do   answer <- mkXPromptWithReturn (MPDPrompt (show meta)) xp-           (mkComplLst . nub . map (extractMetadata meta) $ songs)+           (mkComplLst cmp . nub . map (extractMetadata meta) $ songs)            return   case answer of     Just input -> return $ filter ((==input) . extractMetadata meta) songs@@ -99,14 +110,24 @@ -- [Artist, Album] as third argument, this will prompt the user for an -- artist(with tab-completion), then for an album by that artist and then -- returns the songs from that album.-findMatching :: RunMPD -> XPConfig -> [Metadata] -> X [Song]-findMatching runMPD xp metas = do+--+-- @since 0.13.2+findMatchingWith :: (String -> String -> Bool) -> RunMPD -> XPConfig+                 -> [Metadata] -> X [Song]+findMatchingWith matchFun runMPD xp metas = do   resp <- io . runMPD . fmap extractSongs . listAllInfo $ ("" :: Path)   case resp of     Left err -> trace ("XMonad.Prompt.MPD: MPD returned an error: " ++ show err)                 >> return []-    Right songs -> foldM (findMatching' xp) songs metas+    Right songs -> foldM (findMatching' matchFun xp) songs metas +-- | Lets the user filter out non-matching songs. For example, if given+-- [Artist, Album] as third argument, this will prompt the user for an+-- artist(with tab-completion), then for an album by that artist and then+-- returns the songs from that album.+findMatching :: RunMPD -> XPConfig -> [Metadata] -> X [Song]+findMatching = findMatchingWith isPrefixOf+ -- | Determine playlist position of the song and add it, if it isn't present. findOrAdd :: Song -> MPD Int findOrAdd s = playlistInfo Nothing >>= \pl ->@@ -116,13 +137,87 @@   where unwrapId (Id i) = i  -- | Add all selected songs to the playlist if they are not in it.-addMatching :: RunMPD -> XPConfig -> [Metadata] -> X [Int]-addMatching runMPD xp metas = do-  matches <- findMatching runMPD xp metas+--+-- @since 0.13.2+addMatchingWith :: (String -> String -> Bool) -> RunMPD -> XPConfig+                -> [Metadata] -> X [Int]+addMatchingWith matchFun runMPD xp metas = do+  matches <- findMatchingWith matchFun runMPD xp metas   fmap (either (const []) id) . io . runMPD . mapM findOrAdd $ matches +-- | Add all selected songs to the playlist if they are not in it.+addMatching :: RunMPD -> XPConfig -> [Metadata] -> X [Int]+addMatching = addMatchingWith isPrefixOf+ -- | Add matching songs and play the first one.-addAndPlay :: RunMPD -> XPConfig -> [Metadata] -> X ()-addAndPlay runMPD xp ms = do-  ids <- addMatching runMPD xp ms+--+-- @since 0.13.2+addAndPlayWith :: (String -> String -> Bool) -> RunMPD -> XPConfig+               -> [Metadata] -> X ()+addAndPlayWith matchFun runMPD xp ms = do+  ids <- addMatchingWith matchFun runMPD xp ms   whenJust (listToMaybe ids) ((>> return ()) . io . runMPD . playId . Id)++-- | Add matching songs and play the first one.+addAndPlay :: RunMPD ->  XPConfig -> [Metadata] -> X ()+addAndPlay = addAndPlayWith isPrefixOf++-- | Load an existing playlist and play it.+--+-- @since 0.13.2+loadPlaylistWith :: (String -> String -> Bool) -> RunMPD ->  XPConfig -> X ()+loadPlaylistWith matchFun runMPD xp = do+  playlists <- fmap (either (const []) id) . io . runMPD $ listPlaylists+  mkXPrompt (MPDPrompt "Playlist: ") xp+    (mkComplLst matchFun . nub . map toString $ playlists)+    (\s -> do io $ runMPD $ do clear+                               load $ PlaylistName $ C.pack s+                               play Nothing+              return ())+  +-- | Load an existing playlist and play it.+loadPlaylist :: RunMPD ->  XPConfig -> X ()+loadPlaylist = loadPlaylistWith isPrefixOf++-- | Add songs which match all of the given words with regard to any+-- of the metadata.+--+-- @since 0.13.2+addAndPlayAny :: RunMPD -> XPConfig -> [Metadata] -> X ()+addAndPlayAny runMPD xp metas = do+  mkXPrompt (MPDPrompt "Search") xp+    (historyCompletionP (showXPrompt (MPDPrompt "Search: ") ==))+    (\s -> do io $ runMPD $ do+                clear+                songlists <- mapM (\t -> do+                                      sl <- mapM (\m -> search+                                                        (m =? fromString t))+                                            metas+                                      return $ concat sl) $ words s+                let songs = foldl L.intersect (head songlists) songlists+                fmap (either (const []) id) . io . runMPD . mapM findOrAdd $+                  songs+                play Nothing+              return ())+++-- | Pick a song from the current playlist.+--+-- @since 0.13.2+pickPlayListItem :: RunMPD -> XPConfig -> X ()+pickPlayListItem runMPD xp = do+  mkXPrompt (MPDPrompt "Pick") xp+    (\s -> do pSongs <- io $ runMPD $ playlistSearch (Title =? fromString s)+              case pSongs of+                Left _ -> return []+                Right songs -> return $ take 100 $ nub $ map toString+                               $ concat $ catMaybes+                               $ map (M.lookup Title . sgTags) songs)+    (\s -> do io $ runMPD $ do+                pSongs <- io $ runMPD $ playlistSearch (Title =? fromString s)+                case pSongs of+                  Left _      -> return ()+                  Right songs -> case sgId $ head songs of+                                   Nothing    -> return ()+                                   Just theId -> playId theId+              return ())
xmonad-extras.cabal view
@@ -1,5 +1,5 @@ name:               xmonad-extras-version:            0.13.1+version:            0.13.2 homepage:           https://github.com/xmonad/xmonad-extras synopsis:           Third party extensions for xmonad with wacky dependencies description:        Various modules for xmonad that cannot be added to xmonad-contrib