{-#LANGUAGE RankNTypes#-}
-- |

module Hum.Views.Playlists where

import           Hum.Types
import           Brick.Types
import           Graphics.Vty.Input.Events
import           Brick.Main
import           Brick.Widgets.Core
import           Brick.Widgets.Center
import           Brick.Widgets.Border
import           Brick.Widgets.Border.Style
import           Control.Lens
import           Brick.Widgets.List
import           Hum.Attributes
import           Hum.Views.Common
import           Hum.Rebuild
import qualified Data.Text                     as T
import           Network.MPD                    ( withMPD )
import qualified Network.MPD                   as MPD
import qualified Data.Map.Strict               as Map
import           Hum.Utils



drawPlaylistLeft :: HState -> Widget Name
drawPlaylistLeft :: HState -> Widget Name
drawPlaylistLeft HState
st =
  let vsize :: Int
vsize = case Maybe (Maybe (Extent Name)) -> Maybe (Extent Name)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe (Extent Name)) -> Maybe (Extent Name))
-> Maybe (Maybe (Extent Name)) -> Maybe (Extent Name)
forall a b. (a -> b) -> a -> b
$ Name
-> Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Name
PlaylistLeft (Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name)))
-> Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name))
forall a b. (a -> b) -> a -> b
$ HState -> Map Name (Maybe (Extent Name))
extentMap HState
st of
        Just Extent Name
e  -> (Int, Int) -> Int
forall a b. (a, b) -> b
snd ((Int, Int) -> Int)
-> (Extent Name -> (Int, Int)) -> Extent Name -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extent Name -> (Int, Int)
forall n. Extent n -> (Int, Int)
extentSize (Extent Name -> Int) -> Extent Name -> Int
forall a b. (a -> b) -> a -> b
$ Extent Name
e
        Maybe (Extent Name)
Nothing -> Int
20
  in  Name -> Widget Name -> Widget Name
forall n. n -> Widget n -> Widget n
reportExtent Name
PlaylistLeft (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Widget Name -> Widget Name
forall n. Widget n -> Widget n
hCenter
        (   Name -> ViewportType -> Widget Name -> Widget Name
forall n.
(Ord n, Show n) =>
n -> ViewportType -> Widget n -> Widget n
viewport Name
PlaylistLeft ViewportType
Vertical
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Widget Name -> Widget Name
forall n. Widget n -> Widget n
visible
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
vsize
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Widget Name -> Widget Name
forall n. Widget n -> Widget n
center
        (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$   Widget Name
forall n. Widget n
hBorder
        Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=> Widget Name -> Widget Name
forall n. Widget n -> Widget n
hCenter
              ((Bool -> Text -> Widget Name)
-> Bool -> GenericList Name Vector Text -> Widget Name
forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
renderList ((Text -> Widget Name) -> Bool -> Text -> Widget Name
forall a b. a -> b -> a
const ((Text -> Widget Name) -> Bool -> Text -> Widget Name)
-> (Text -> Widget Name) -> Bool -> Text -> Widget Name
forall a b. (a -> b) -> a -> b
$ HState -> Text -> Widget Name
forall n. HState -> Text -> Widget n
playlistRow HState
st)
                          ((Focus -> FocPlay
focPlay (Focus -> FocPlay) -> (HState -> Focus) -> HState -> FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> Focus
focus (HState -> FocPlay) -> HState -> FocPlay
forall a b. (a -> b) -> a -> b
$ HState
st) FocPlay -> FocPlay -> Bool
forall a. Eq a => a -> a -> Bool
== FocPlay
FocPlaylists)
                          (PlaylistName -> Text
forall a. ToString a => a -> Text
MPD.toText (PlaylistName -> Text)
-> GenericList Name Vector PlaylistName
-> GenericList Name Vector Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HState
st HState
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
-> GenericList Name Vector PlaylistName
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> HState -> Const (GenericList Name Vector PlaylistName) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
 -> HState -> Const (GenericList Name Vector PlaylistName) HState)
-> ((GenericList Name Vector PlaylistName
     -> Const
          (GenericList Name Vector PlaylistName)
          (GenericList Name Vector PlaylistName))
    -> PlaylistsState
    -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector PlaylistName
 -> Const
      (GenericList Name Vector PlaylistName)
      (GenericList Name Vector PlaylistName))
-> PlaylistsState
-> Const (GenericList Name Vector PlaylistName) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector PlaylistName)
plListL)
              )
        )
drawPlaylistRight :: HState -> Widget Name
drawPlaylistRight :: HState -> Widget Name
drawPlaylistRight HState
st =
  let vsize :: Int
vsize = case Maybe (Maybe (Extent Name)) -> Maybe (Extent Name)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join (Maybe (Maybe (Extent Name)) -> Maybe (Extent Name))
-> Maybe (Maybe (Extent Name)) -> Maybe (Extent Name)
forall a b. (a -> b) -> a -> b
$ Name
-> Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name))
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Name
PlaylistRight (Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name)))
-> Map Name (Maybe (Extent Name)) -> Maybe (Maybe (Extent Name))
forall a b. (a -> b) -> a -> b
$ HState -> Map Name (Maybe (Extent Name))
extentMap HState
st of
        Just Extent Name
e  -> (Int, Int) -> Int
forall a b. (a, b) -> b
snd ((Int, Int) -> Int)
-> (Extent Name -> (Int, Int)) -> Extent Name -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Extent Name -> (Int, Int)
forall n. Extent n -> (Int, Int)
extentSize (Extent Name -> Int) -> Extent Name -> Int
forall a b. (a -> b) -> a -> b
$ Extent Name
e
        Maybe (Extent Name)
Nothing -> Int
20
  in  Name -> Widget Name -> Widget Name
forall n. n -> Widget n -> Widget n
reportExtent Name
PlaylistRight (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Widget Name -> Widget Name
forall n. Widget n -> Widget n
hCenter
        (   Name -> ViewportType -> Widget Name -> Widget Name
forall n.
(Ord n, Show n) =>
n -> ViewportType -> Widget n -> Widget n
viewport Name
PlaylistRight ViewportType
Vertical
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Widget Name -> Widget Name
forall n. Widget n -> Widget n
visible
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
vLimit Int
vsize
        (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Widget Name -> Widget Name
forall n. Widget n -> Widget n
center
        (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$   (if HState
st HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL
              then
                AttrName -> Widget Name -> Widget Name
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
listHighlightedAttr
                (Widget Name -> Widget Name)
-> (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BorderStyle -> Widget Name -> Widget Name
forall n. BorderStyle -> Widget n -> Widget n
withBorderStyle (Char -> BorderStyle
borderStyleFromChar Char
'=')
                (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Widget Name -> Widget Name
forall n. Widget n -> Widget n
hBorderWithLabel
                (Widget Name -> Widget Name) -> Widget Name -> Widget Name
forall a b. (a -> b) -> a -> b
$ Text -> Widget Name
forall n. Text -> Widget n
txt Text
"editing"
              else Widget Name
forall n. Widget n
hBorder
            )
        Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=> Widget Name -> Widget Name
forall n. Widget n -> Widget n
hCenter
              ((Bool -> (Song, Bool) -> Widget Name)
-> Bool -> GenericList Name Vector (Song, Bool) -> Widget Name
forall (t :: * -> *) n e.
(Traversable t, Splittable t, Ord n, Show n) =>
(Bool -> e -> Widget n) -> Bool -> GenericList n t e -> Widget n
renderList (((Song, Bool) -> Widget Name)
-> Bool -> (Song, Bool) -> Widget Name
forall a b. a -> b -> a
const (((Song, Bool) -> Widget Name)
 -> Bool -> (Song, Bool) -> Widget Name)
-> ((Song, Bool) -> Widget Name)
-> Bool
-> (Song, Bool)
-> Widget Name
forall a b. (a -> b) -> a -> b
$ HState -> (Song, Bool) -> Widget Name
forall n. HState -> (Song, Bool) -> Widget n
playlistSongRow HState
st)
                          ((Focus -> FocPlay
focPlay (Focus -> FocPlay) -> (HState -> Focus) -> HState -> FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> Focus
focus (HState -> FocPlay) -> HState -> FocPlay
forall a b. (a -> b) -> a -> b
$ HState
st) FocPlay -> FocPlay -> Bool
forall a. Eq a => a -> a -> Bool
== FocPlay
FocPSongs)
                          (HState
st HState
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> HState -> Const (GenericList Name Vector (Song, Bool)) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
 -> HState -> Const (GenericList Name Vector (Song, Bool)) HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Const
          (GenericList Name Vector (Song, Bool))
          (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState
    -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Const
      (GenericList Name Vector (Song, Bool))
      (GenericList Name Vector (Song, Bool)))
-> PlaylistsState
-> Const (GenericList Name Vector (Song, Bool)) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL)
              )
        )

playlistRow :: HState -> T.Text -> Widget n
playlistRow :: HState -> Text -> Widget n
playlistRow HState
_ Text
val =
  AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr AttrName
queueAlbumAttr (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Maybe PerCol -> Padding -> Padding -> Widget n -> Widget n
forall n.
Maybe PerCol -> Padding -> Padding -> Widget n -> Widget n
column Maybe PerCol
forall a. Maybe a
Nothing (Int -> Padding
Pad Int
1) Padding
Max (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Text -> Widget n
forall n. Text -> Widget n
txt Text
val

playlistSongRow :: HState -> (MPD.Song,Highlight) -> Widget n
playlistSongRow :: HState -> (Song, Bool) -> Widget n
playlistSongRow HState
st (Song
song,Bool
hl) =
  let pathsInQueue :: Vector Path
pathsInQueue =
        (Song -> Path
MPD.sgFilePath (Song -> Path) -> Vector Song -> Vector Path
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Vector Song -> Vector Path)
-> (HState -> Vector Song) -> HState -> Vector Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Song, Bool) -> Song
forall a b. (a, b) -> a
fst ((Song, Bool) -> Song) -> Vector (Song, Bool) -> Vector Song
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Vector (Song, Bool) -> Vector Song)
-> (HState -> Vector (Song, Bool)) -> HState -> Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector (Song, Bool) -> Vector (Song, Bool)
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements (GenericList Name Vector (Song, Bool) -> Vector (Song, Bool))
-> (HState -> GenericList Name Vector (Song, Bool))
-> HState
-> Vector (Song, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> GenericList Name Vector (Song, Bool)
queue (HState -> Vector Path) -> HState -> Vector Path
forall a b. (a -> b) -> a -> b
$ HState
st
  in (if Bool
hl then Widget n -> Widget n
forall n. Widget n -> Widget n
highlightOverQueueAttrs else Widget n -> Widget n
forall a. a -> a
id) (Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr
          (if Song -> Path
MPD.sgFilePath Song
song Path -> Vector Path -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` Vector Path
pathsInQueue
            then AttrName
queueTitleBoldAttr
            else AttrName
queueTitleAttr
          )
        (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Maybe PerCol -> Padding -> Padding -> Widget n -> Widget n
forall n.
Maybe PerCol -> Padding -> Padding -> Widget n -> Widget n
column Maybe PerCol
forall a. Maybe a
Nothing (Int -> Padding
Pad Int
1) Padding
Max
        (Widget n -> Widget n) -> Widget n -> Widget n
forall a b. (a -> b) -> a -> b
$ Text -> Widget n
forall n. Text -> Widget n
txt (Text -> Metadata -> Song -> Text
meta (Path -> Text
forall a. ToString a => a -> Text
MPD.toText (Path -> Text) -> (Song -> Path) -> Song -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Song -> Path
MPD.sgFilePath (Song -> Text) -> Song -> Text
forall a b. (a -> b) -> a -> b
$ Song
song) Metadata
MPD.Title Song
song)






drawViewPlaylists :: HState -> Widget Name
drawViewPlaylists :: HState -> Widget Name
drawViewPlaylists HState
st =
  Int -> Widget Name -> Widget Name
forall n. Int -> Widget n -> Widget n
hLimitPercent Int
25 (HState -> Widget Name
drawPlaylistLeft HState
st) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> HState -> Widget Name
drawPlaylistRight HState
st

playlistsMove
  :: (forall e . List Name e -> List Name e) -> HState -> EventM Name HState
playlistsMove :: (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove forall e. List Name e -> List Name e
moveFunc HState
s =
  let playfoc :: FocPlay
playfoc = HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL
  in  case FocPlay
playfoc of
        FocPlay
FocPlaylists -> HState -> EventM Name HState
forall (m :: * -> *). MonadIO m => HState -> m HState
rebuildPlList (HState -> EventM Name HState) -> HState -> EventM Name HState
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector PlaylistName
     -> Identity (GenericList Name Vector PlaylistName))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector PlaylistName
    -> Identity (GenericList Name Vector PlaylistName))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector PlaylistName
 -> Identity (GenericList Name Vector PlaylistName))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector PlaylistName)
plListL ((GenericList Name Vector PlaylistName
  -> Identity (GenericList Name Vector PlaylistName))
 -> HState -> Identity HState)
-> (GenericList Name Vector PlaylistName
    -> GenericList Name Vector PlaylistName)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall e. List Name e -> List Name e
moveFunc
        FocPlay
FocPSongs    -> do
          HState -> EventM Name HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure (HState -> EventM Name HState) -> HState -> EventM Name HState
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Identity (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector (Song, Bool)
    -> Identity (GenericList Name Vector (Song, Bool)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Identity (GenericList Name Vector (Song, Bool)))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL ((GenericList Name Vector (Song, Bool)
  -> Identity (GenericList Name Vector (Song, Bool)))
 -> HState -> Identity HState)
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall e. List Name e -> List Name e
moveFunc

playlistsAddtoQ :: Bool -> HState -> EventM Name HState
playlistsAddtoQ :: Bool -> HState -> EventM Name HState
playlistsAddtoQ Bool
play HState
s =
  let playfoc :: FocPlay
playfoc = HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL
  in  case FocPlay
playfoc of
        FocPlay
FocPlaylists -> do
          Bool -> Vector Song -> HState -> EventM Name HState
forall n. Bool -> Vector Song -> HState -> EventM n HState
songBulkAddtoQ Bool
play ((Song, Bool) -> Song
forall a b. (a, b) -> a
fst ((Song, Bool) -> Song) -> Vector (Song, Bool) -> Vector Song
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector (Song, Bool) -> Vector (Song, Bool)
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements (HState
s HState
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> HState -> Const (GenericList Name Vector (Song, Bool)) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
 -> HState -> Const (GenericList Name Vector (Song, Bool)) HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Const
          (GenericList Name Vector (Song, Bool))
          (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState
    -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Const
      (GenericList Name Vector (Song, Bool))
      (GenericList Name Vector (Song, Bool)))
-> PlaylistsState
-> Const (GenericList Name Vector (Song, Bool)) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL)) HState
s
        FocPlay
FocPSongs -> do
          let maybeFilePath :: Maybe Path
maybeFilePath = Song -> Path
MPD.sgFilePath (Song -> Path)
-> ((Int, (Song, Bool)) -> Song) -> (Int, (Song, Bool)) -> Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Song, Bool) -> Song
forall a b. (a, b) -> a
fst ((Song, Bool) -> Song)
-> ((Int, (Song, Bool)) -> (Song, Bool))
-> (Int, (Song, Bool))
-> Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, (Song, Bool)) -> (Song, Bool)
forall a b. (a, b) -> b
snd ((Int, (Song, Bool)) -> Path)
-> Maybe (Int, (Song, Bool)) -> Maybe Path
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector (Song, Bool) -> Maybe (Int, (Song, Bool))
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement
                (HState
s HState
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> HState -> Const (GenericList Name Vector (Song, Bool)) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
 -> HState -> Const (GenericList Name Vector (Song, Bool)) HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Const
          (GenericList Name Vector (Song, Bool))
          (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState
    -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Const
      (GenericList Name Vector (Song, Bool))
      (GenericList Name Vector (Song, Bool)))
-> PlaylistsState
-> Const (GenericList Name Vector (Song, Bool)) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL)
          (Path -> EventM Name (Response ())) -> Maybe Path -> EventM Name ()
forall (t :: * -> *) (f :: * -> *) a b.
(Foldable t, Applicative f) =>
(a -> f b) -> t a -> f ()
traverse_
            (\Path
sel -> IO (Response ()) -> EventM Name (Response ())
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
              (MPD () -> IO (Response ())
forall a. MPD a -> IO (Response a)
withMPD (MPD () -> IO (Response ())) -> MPD () -> IO (Response ())
forall a b. (a -> b) -> a -> b
$ Path -> Maybe Int -> MPD Id
forall (m :: * -> *). MonadMPD m => Path -> Maybe Int -> m Id
MPD.addId Path
sel Maybe Int
forall a. Maybe a
Nothing MPD Id -> (Id -> MPD ()) -> MPD ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= if Bool
play
                then Id -> MPD ()
forall (m :: * -> *). MonadMPD m => Id -> m ()
MPD.playId
                else MPD () -> Id -> MPD ()
forall a b. a -> b -> a
const MPD ()
forall (f :: * -> *). Applicative f => f ()
pass
              )
            )
            Maybe Path
maybeFilePath
          Response (Maybe Song)
song <- IO (Response (Maybe Song)) -> EventM Name (Response (Maybe Song))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (MPD (Maybe Song) -> IO (Response (Maybe Song))
forall a. MPD a -> IO (Response a)
withMPD MPD (Maybe Song)
forall (m :: * -> *). MonadMPD m => m (Maybe Song)
MPD.currentSong)
          HState -> EventM Name HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure HState
s { currentSong :: Maybe Song
currentSong = Maybe Song -> Response (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing Response (Maybe Song)
song, queue :: GenericList Name Vector (Song, Bool)
queue = HState -> GenericList Name Vector (Song, Bool)
queue HState
s }

playlistsSearch :: Bool -> HState -> EventM Name HState
playlistsSearch :: Bool -> HState -> EventM Name HState
playlistsSearch Bool
direction HState
s =
  let playfoc :: FocPlay
playfoc   = HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL
      dir :: GenericList n Vector e -> GenericList n Vector e
dir       = if Bool
direction then GenericList n Vector e -> GenericList n Vector e
forall a. a -> a
id else GenericList n Vector e -> GenericList n Vector e
forall (t :: * -> *) n e.
(Reversible t, Foldable t) =>
GenericList n t e -> GenericList n t e
listReverse
      searchkey :: Text
searchkey = Text -> Maybe Text -> Text
forall a. a -> Maybe a -> a
fromMaybe Text
"" ((HState
s HState -> Getting [Text] HState [Text] -> [Text]
forall s a. s -> Getting a s a -> a
^. (ExState -> Const [Text] ExState) -> HState -> Const [Text] HState
Lens' HState ExState
exL ((ExState -> Const [Text] ExState)
 -> HState -> Const [Text] HState)
-> (([Text] -> Const [Text] [Text])
    -> ExState -> Const [Text] ExState)
-> Getting [Text] HState [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([Text] -> Const [Text] [Text]) -> ExState -> Const [Text] ExState
Lens' ExState [Text]
searchHistoryL) [Text] -> Int -> Maybe Text
forall a. [a] -> Int -> Maybe a
!!? Int
0)
  in  if Text
searchkey Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
""
        then HState -> EventM Name HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure HState
s
        else case FocPlay
playfoc of
          FocPlay
FocPlaylists -> do
            Map Name (Maybe (Extent Name))
extentMap <- EventM Name (Map Name (Maybe (Extent Name)))
updateExtentMap
            HState -> EventM Name HState
forall (m :: * -> *). MonadIO m => HState -> m HState
rebuildPlList
              (HState -> EventM Name HState) -> HState -> EventM Name HState
forall a b. (a -> b) -> a -> b
$  (HState
s { Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap })
              HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
&  (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL
              ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector PlaylistName
     -> Identity (GenericList Name Vector PlaylistName))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector PlaylistName
    -> Identity (GenericList Name Vector PlaylistName))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  (GenericList Name Vector PlaylistName
 -> Identity (GenericList Name Vector PlaylistName))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector PlaylistName)
plListL
              ((GenericList Name Vector PlaylistName
  -> Identity (GenericList Name Vector PlaylistName))
 -> HState -> Identity HState)
-> (GenericList Name Vector PlaylistName
    -> GenericList Name Vector PlaylistName)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall n e. GenericList n Vector e -> GenericList n Vector e
dir (GenericList Name Vector PlaylistName
 -> GenericList Name Vector PlaylistName)
-> (GenericList Name Vector PlaylistName
    -> GenericList Name Vector PlaylistName)
-> GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PlaylistName -> Bool)
-> GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy (Text -> PlaylistName -> Bool
forall a. ToString a => Text -> a -> Bool
stringySearch Text
searchkey) (GenericList Name Vector PlaylistName
 -> GenericList Name Vector PlaylistName)
-> (GenericList Name Vector PlaylistName
    -> GenericList Name Vector PlaylistName)
-> GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector PlaylistName
-> GenericList Name Vector PlaylistName
forall n e. GenericList n Vector e -> GenericList n Vector e
dir)
          FocPlay
FocPSongs -> do
            Map Name (Maybe (Extent Name))
extentMap <- EventM Name (Map Name (Maybe (Extent Name)))
updateExtentMap
            HState -> EventM Name HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure
              (HState -> EventM Name HState) -> HState -> EventM Name HState
forall a b. (a -> b) -> a -> b
$  HState
s { Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap }
              HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
&  (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL
              ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Identity (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector (Song, Bool)
    -> Identity (GenericList Name Vector (Song, Bool)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.  (GenericList Name Vector (Song, Bool)
 -> Identity (GenericList Name Vector (Song, Bool)))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL
              ((GenericList Name Vector (Song, Bool)
  -> Identity (GenericList Name Vector (Song, Bool)))
 -> HState -> Identity HState)
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall n e. GenericList n Vector e -> GenericList n Vector e
dir (GenericList Name Vector (Song, Bool)
 -> GenericList Name Vector (Song, Bool))
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Song, Bool) -> Bool)
-> GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy (Text -> [Metadata] -> Song -> Bool
songSearch Text
searchkey [Metadata
MPD.Title] (Song -> Bool) -> ((Song, Bool) -> Song) -> (Song, Bool) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Song, Bool) -> Song
forall a b. (a, b) -> a
fst) (GenericList Name Vector (Song, Bool)
 -> GenericList Name Vector (Song, Bool))
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall n e. GenericList n Vector e -> GenericList n Vector e
dir)


handleEventPlaylists
  :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventPlaylists :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventPlaylists HState
s BrickEvent Name HumEvent
e = case BrickEvent Name HumEvent
e of
  VtyEvent Event
vtye -> case Event
vtye of
    EvKey (KChar Char
'j') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove forall e. List Name e -> List Name e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown HState
s
    EvKey (KChar Char
'k') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove forall e. List Name e -> List Name e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveUp HState
s
    EvKey (KChar Char
'l') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Focus -> Identity Focus) -> HState -> Identity HState
Lens' HState Focus
focusL ((Focus -> Identity Focus) -> HState -> Identity HState)
-> ((FocPlay -> Identity FocPlay) -> Focus -> Identity Focus)
-> (FocPlay -> Identity FocPlay)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Identity FocPlay) -> Focus -> Identity Focus
Lens' Focus FocPlay
focPlayL ((FocPlay -> Identity FocPlay) -> HState -> Identity HState)
-> FocPlay -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ FocPlay
FocPSongs
    EvKey (KChar Char
'h') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Focus -> Identity Focus) -> HState -> Identity HState
Lens' HState Focus
focusL ((Focus -> Identity Focus) -> HState -> Identity HState)
-> ((FocPlay -> Identity FocPlay) -> Focus -> Identity Focus)
-> (FocPlay -> Identity FocPlay)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Identity FocPlay) -> Focus -> Identity Focus
Lens' Focus FocPlay
focPlayL ((FocPlay -> Identity FocPlay) -> HState -> Identity HState)
-> FocPlay -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ FocPlay
FocPlaylists
    EvKey (KChar Char
'n') [] ->
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> HState -> EventM Name HState
playlistsSearch (HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (ExState -> Const Bool ExState) -> HState -> Const Bool HState
Lens' HState ExState
exL ((ExState -> Const Bool ExState) -> HState -> Const Bool HState)
-> ((Bool -> Const Bool Bool) -> ExState -> Const Bool ExState)
-> Getting Bool HState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> ExState -> Const Bool ExState
Lens' ExState Bool
searchDirectionL) HState
s
    EvKey (KChar Char
'N') [] ->
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> HState -> EventM Name HState
playlistsSearch (HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (ExState -> Const Bool ExState) -> HState -> Const Bool HState
Lens' HState ExState
exL ((ExState -> Const Bool ExState) -> HState -> Const Bool HState)
-> ((Bool -> Const Bool Bool) -> ExState -> Const Bool ExState)
-> Getting Bool HState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> ExState -> Const Bool ExState
Lens' ExState Bool
searchDirectionL Bool -> (Bool -> Bool) -> Bool
forall a b. a -> (a -> b) -> b
& Bool -> Bool
not) HState
s
    EvKey Key
KEnter [] ->
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove forall e. List Name e -> List Name e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown (HState -> EventM Name HState)
-> EventM Name HState -> EventM Name HState
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> HState -> EventM Name HState
playlistsAddtoQ Bool
True HState
s
    EvKey (KChar Char
' ') [] -> if HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL then
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Identity (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector (Song, Bool)
    -> Identity (GenericList Name Vector (Song, Bool)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Identity (GenericList Name Vector (Song, Bool)))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL ((GenericList Name Vector (Song, Bool)
  -> Identity (GenericList Name Vector (Song, Bool)))
 -> HState -> Identity HState)
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown (GenericList Name Vector (Song, Bool)
 -> GenericList Name Vector (Song, Bool))
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall (t :: * -> *) n e.
Traversable t =>
GenericList n t (e, Bool) -> GenericList n t (e, Bool)
listToggleHighlight)
      else
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove forall e. List Name e -> List Name e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown (HState -> EventM Name HState)
-> EventM Name HState -> EventM Name HState
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Bool -> HState -> EventM Name HState
playlistsAddtoQ Bool
False HState
s
    EvKey (KChar Char
'd') []
       | HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
-> Lens' HState (GenericList Name Vector (Song, Bool)) -> HState
deleteHighlighted HState
s ((PlaylistsState -> f PlaylistsState) -> HState -> f HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState -> f PlaylistsState) -> HState -> f HState)
-> ((GenericList Name Vector (Song, Bool)
     -> f (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState -> f PlaylistsState)
-> (GenericList Name Vector (Song, Bool)
    -> f (GenericList Name Vector (Song, Bool)))
-> HState
-> f HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> f (GenericList Name Vector (Song, Bool)))
-> PlaylistsState -> f PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL)
       | HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL FocPlay -> FocPlay -> Bool
forall a. Eq a => a -> a -> Bool
== FocPlay
FocPlaylists
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Mode -> Identity Mode) -> HState -> Identity HState
Lens' HState Mode
modeL ((Mode -> Identity Mode) -> HState -> Identity HState)
-> Mode -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Mode
PromptMode
                         HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((PromptType -> Identity PromptType)
    -> Prompts -> Identity Prompts)
-> (PromptType -> Identity PromptType)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PromptType -> Identity PromptType) -> Prompts -> Identity Prompts
Lens' Prompts PromptType
currentPromptL ((PromptType -> Identity PromptType) -> HState -> Identity HState)
-> PromptType -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PromptType
YNPrompt
                         HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((Text -> Identity Text) -> Prompts -> Identity Prompts)
-> (Text -> Identity Text)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Identity Text) -> Prompts -> Identity Prompts
Lens' Prompts Text
promptTitleL ((Text -> Identity Text) -> HState -> Identity HState)
-> Text -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Text
"DELETE " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
selectedPl Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"?\nYou can't paste it back yet")
                         HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> (((HState -> EventM Name HState)
     -> Identity (HState -> EventM Name HState))
    -> Prompts -> Identity Prompts)
-> ((HState -> EventM Name HState)
    -> Identity (HState -> EventM Name HState))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
 -> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL (((HState -> EventM Name HState)
  -> Identity (HState -> EventM Name HState))
 -> HState -> Identity HState)
-> (HState -> EventM Name HState) -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ HState -> EventM Name HState
forall n. HState -> EventM n HState
deleteSelectedPl
       | Bool
otherwise ->  HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
    EvKey (KChar Char
'y') []
       | HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Clipboard -> Identity Clipboard) -> HState -> Identity HState
Lens' HState Clipboard
clipboardL ((Clipboard -> Identity Clipboard) -> HState -> Identity HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Identity (GenericList Name Vector (Song, Bool)))
    -> Clipboard -> Identity Clipboard)
-> (GenericList Name Vector (Song, Bool)
    -> Identity (GenericList Name Vector (Song, Bool)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Identity (GenericList Name Vector (Song, Bool)))
-> Clipboard -> Identity Clipboard
Lens' Clipboard (GenericList Name Vector (Song, Bool))
clSongsL ((GenericList Name Vector (Song, Bool)
  -> Identity (GenericList Name Vector (Song, Bool)))
 -> HState -> Identity HState)
-> GenericList Name Vector (Song, Bool) -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (HState
s HState
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> HState -> Const (GenericList Name Vector (Song, Bool)) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
 -> HState -> Const (GenericList Name Vector (Song, Bool)) HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Const
          (GenericList Name Vector (Song, Bool))
          (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState
    -> Const (GenericList Name Vector (Song, Bool)) PlaylistsState)
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Const
      (GenericList Name Vector (Song, Bool))
      (GenericList Name Vector (Song, Bool)))
-> PlaylistsState
-> Const (GenericList Name Vector (Song, Bool)) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL GenericList Name Vector (Song, Bool)
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall a b. a -> (a -> b) -> b
& GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall e (t :: * -> *) n.
(Eq e, Filterable t, Foldable t, Splittable t) =>
GenericList n t (e, Bool) -> GenericList n t (e, Bool)
getHighlighted)
       | HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL FocPlay -> FocPlay -> Bool
forall a. Eq a => a -> a -> Bool
== FocPlay
FocPlaylists
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Clipboard -> Identity Clipboard) -> HState -> Identity HState
Lens' HState Clipboard
clipboardL ((Clipboard -> Identity Clipboard) -> HState -> Identity HState)
-> ((Maybe PlaylistName -> Identity (Maybe PlaylistName))
    -> Clipboard -> Identity Clipboard)
-> (Maybe PlaylistName -> Identity (Maybe PlaylistName))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe PlaylistName -> Identity (Maybe PlaylistName))
-> Clipboard -> Identity Clipboard
Lens' Clipboard (Maybe PlaylistName)
clPlNameL ((Maybe PlaylistName -> Identity (Maybe PlaylistName))
 -> HState -> Identity HState)
-> Maybe PlaylistName -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (HState
s HState
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
-> GenericList Name Vector PlaylistName
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> HState -> Const (GenericList Name Vector PlaylistName) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
 -> HState -> Const (GenericList Name Vector PlaylistName) HState)
-> ((GenericList Name Vector PlaylistName
     -> Const
          (GenericList Name Vector PlaylistName)
          (GenericList Name Vector PlaylistName))
    -> PlaylistsState
    -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector PlaylistName
 -> Const
      (GenericList Name Vector PlaylistName)
      (GenericList Name Vector PlaylistName))
-> PlaylistsState
-> Const (GenericList Name Vector PlaylistName) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector PlaylistName)
plListL GenericList Name Vector PlaylistName
-> (GenericList Name Vector PlaylistName
    -> Maybe (Int, PlaylistName))
-> Maybe (Int, PlaylistName)
forall a b. a -> (a -> b) -> b
& GenericList Name Vector PlaylistName -> Maybe (Int, PlaylistName)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement Maybe (Int, PlaylistName)
-> ((Int, PlaylistName) -> PlaylistName) -> Maybe PlaylistName
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Int, PlaylistName) -> PlaylistName
forall a b. (a, b) -> b
snd)
       | Bool
otherwise -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
    EvKey (KChar Char
'p') []
       | HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (PlaylistsState -> Identity PlaylistsState)
-> HState -> Identity HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState -> Identity PlaylistsState)
 -> HState -> Identity HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Identity (GenericList Name Vector (Song, Bool)))
    -> PlaylistsState -> Identity PlaylistsState)
-> (GenericList Name Vector (Song, Bool)
    -> Identity (GenericList Name Vector (Song, Bool)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Identity (GenericList Name Vector (Song, Bool)))
-> PlaylistsState -> Identity PlaylistsState
Lens' PlaylistsState (GenericList Name Vector (Song, Bool))
plSongsL ((GenericList Name Vector (Song, Bool)
  -> Identity (GenericList Name Vector (Song, Bool)))
 -> HState -> Identity HState)
-> (GenericList Name Vector (Song, Bool)
    -> GenericList Name Vector (Song, Bool))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
-> GenericList Name Vector (Song, Bool)
forall (t :: * -> *) e n.
(Splittable t, Semigroup (t e)) =>
GenericList n t e -> GenericList n t e -> GenericList n t e
listPaste (HState
sHState
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
-> GenericList Name Vector (Song, Bool)
forall s a. s -> Getting a s a -> a
^. (Clipboard
 -> Const (GenericList Name Vector (Song, Bool)) Clipboard)
-> HState -> Const (GenericList Name Vector (Song, Bool)) HState
Lens' HState Clipboard
clipboardL((Clipboard
  -> Const (GenericList Name Vector (Song, Bool)) Clipboard)
 -> HState -> Const (GenericList Name Vector (Song, Bool)) HState)
-> ((GenericList Name Vector (Song, Bool)
     -> Const
          (GenericList Name Vector (Song, Bool))
          (GenericList Name Vector (Song, Bool)))
    -> Clipboard
    -> Const (GenericList Name Vector (Song, Bool)) Clipboard)
-> Getting
     (GenericList Name Vector (Song, Bool))
     HState
     (GenericList Name Vector (Song, Bool))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector (Song, Bool)
 -> Const
      (GenericList Name Vector (Song, Bool))
      (GenericList Name Vector (Song, Bool)))
-> Clipboard
-> Const (GenericList Name Vector (Song, Bool)) Clipboard
Lens' Clipboard (GenericList Name Vector (Song, Bool))
clSongsL)
       | HState
s HState -> Getting FocPlay HState FocPlay -> FocPlay
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState
Lens' HState Focus
focusL ((Focus -> Const FocPlay Focus) -> HState -> Const FocPlay HState)
-> ((FocPlay -> Const FocPlay FocPlay)
    -> Focus -> Const FocPlay Focus)
-> Getting FocPlay HState FocPlay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocPlay -> Const FocPlay FocPlay) -> Focus -> Const FocPlay Focus
Lens' Focus FocPlay
focPlayL FocPlay -> FocPlay -> Bool
forall a. Eq a => a -> a -> Bool
== FocPlay
FocPlaylists
         -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< HState -> EventM Name HState
forall n. HState -> EventM n HState
pastePlaylist HState
s
       | Bool
otherwise -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
    EvKey (KChar Char
'G') [] ->
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove (\List Name e
ls -> Int -> List Name e -> List Name e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveBy (List Name e -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length List Name e
ls) List Name e
ls) HState
s
    EvKey (KChar Char
'g') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
playlistsMove (Int -> GenericList Name Vector e -> GenericList Name Vector e
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
0) HState
s -- TODO change this to  'gg', somehow
    EvKey (KChar Char
'e') [] -> if HState
s HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. Getting Bool HState Bool
Lens' HState Bool
editableL then
      HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> HState -> EventM Name (Next HState)
forall a b. (a -> b) -> a -> b
$ HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Bool -> Identity Bool) -> HState -> Identity HState
Lens' HState Bool
editableL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> (Bool -> Bool) -> HState -> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Bool -> Bool
not
                   HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Mode -> Identity Mode) -> HState -> Identity HState
Lens' HState Mode
modeL ((Mode -> Identity Mode) -> HState -> Identity HState)
-> Mode -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Mode
PromptMode
                   HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((PromptType -> Identity PromptType)
    -> Prompts -> Identity Prompts)
-> (PromptType -> Identity PromptType)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PromptType -> Identity PromptType) -> Prompts -> Identity Prompts
Lens' Prompts PromptType
currentPromptL ((PromptType -> Identity PromptType) -> HState -> Identity HState)
-> PromptType -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PromptType
YNPrompt
                   HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((Text -> Identity Text) -> Prompts -> Identity Prompts)
-> (Text -> Identity Text)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Identity Text) -> Prompts -> Identity Prompts
Lens' Prompts Text
promptTitleL ((Text -> Identity Text) -> HState -> Identity HState)
-> Text -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Text
"Save changes to " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
selectedPl Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"?")
                   HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> (((HState -> EventM Name HState)
     -> Identity (HState -> EventM Name HState))
    -> Prompts -> Identity Prompts)
-> ((HState -> EventM Name HState)
    -> Identity (HState -> EventM Name HState))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
 -> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL (((HState -> EventM Name HState)
  -> Identity (HState -> EventM Name HState))
 -> HState -> Identity HState)
-> (HState -> EventM Name HState) -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ HState -> EventM Name HState
forall n. HState -> EventM n HState
saveEditedPl
      else HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< HState -> EventM Name HState
forall (m :: * -> *). MonadIO m => HState -> m HState
rebuildPlList (HState
s HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Bool -> Identity Bool) -> HState -> Identity HState
Lens' HState Bool
editableL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> (Bool -> Bool) -> HState -> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Bool -> Bool
not)
    Event
_                    -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
  BrickEvent Name HumEvent
_ -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
  where selectedPl :: Text
selectedPl = HState
s HState
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
-> GenericList Name Vector PlaylistName
forall s a. s -> Getting a s a -> a
^. (PlaylistsState
 -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> HState -> Const (GenericList Name Vector PlaylistName) HState
Lens' HState PlaylistsState
playlistsL ((PlaylistsState
  -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
 -> HState -> Const (GenericList Name Vector PlaylistName) HState)
-> ((GenericList Name Vector PlaylistName
     -> Const
          (GenericList Name Vector PlaylistName)
          (GenericList Name Vector PlaylistName))
    -> PlaylistsState
    -> Const (GenericList Name Vector PlaylistName) PlaylistsState)
-> Getting
     (GenericList Name Vector PlaylistName)
     HState
     (GenericList Name Vector PlaylistName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector PlaylistName
 -> Const
      (GenericList Name Vector PlaylistName)
      (GenericList Name Vector PlaylistName))
-> PlaylistsState
-> Const (GenericList Name Vector PlaylistName) PlaylistsState
Lens' PlaylistsState (GenericList Name Vector PlaylistName)
plListL GenericList Name Vector PlaylistName
-> (GenericList Name Vector PlaylistName -> Text) -> Text
forall a b. a -> (a -> b) -> b
& GenericList Name Vector PlaylistName -> Maybe (Int, PlaylistName)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement (GenericList Name Vector PlaylistName -> Maybe (Int, PlaylistName))
-> (Maybe (Int, PlaylistName) -> PlaylistName)
-> GenericList Name Vector PlaylistName
-> PlaylistName
forall a b c. (a -> b) -> (b -> c) -> a -> c
? PlaylistName
-> ((Int, PlaylistName) -> PlaylistName)
-> Maybe (Int, PlaylistName)
-> PlaylistName
forall b a. b -> (a -> b) -> Maybe a -> b
maybe PlaylistName
"<error>" (Int, PlaylistName) -> PlaylistName
forall a b. (a, b) -> b
snd (GenericList Name Vector PlaylistName -> PlaylistName)
-> (PlaylistName -> Text)
-> GenericList Name Vector PlaylistName
-> Text
forall a b c. (a -> b) -> (b -> c) -> a -> c
? PlaylistName -> Text
forall a. ToString a => a -> Text
MPD.toText