{-#LANGUAGE RankNTypes#-}
module Hum.Views.Library where
import Prelude hiding ( Down )
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 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
drawLibraryLeft :: HState -> Widget Name
drawLibraryLeft :: HState -> Widget Name
drawLibraryLeft 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
LibraryLeft (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
LibraryLeft (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
LibraryLeft 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 -> Name -> Text -> Widget Name
forall n. HState -> Name -> Text -> Widget n
libraryRow HState
st Name
LibraryLeft)
((Focus -> FocLib
focLib (Focus -> FocLib) -> (HState -> Focus) -> HState -> FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> Focus
focus (HState -> FocLib) -> HState -> FocLib
forall a b. (a -> b) -> a -> b
$ HState
st) FocLib -> FocLib -> Bool
forall a. Eq a => a -> a -> Bool
== FocLib
FocArtists)
(Value -> Text
forall a. ToString a => a -> Text
MPD.toText (Value -> Text)
-> GenericList Name Vector Value -> GenericList Name Vector Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HState
st HState
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
-> GenericList Name Vector Value
forall s a. s -> Getting a s a -> a
^. (LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState)
-> ((GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState
Lens' LibraryState (GenericList Name Vector Value)
artistsL)
)
)
drawLibraryMid :: HState -> Widget Name
drawLibraryMid :: HState -> Widget Name
drawLibraryMid 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
LibraryMid (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
LibraryMid (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
LibraryMid 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 -> Name -> Text -> Widget Name
forall n. HState -> Name -> Text -> Widget n
libraryRow HState
st Name
LibraryMid)
((Focus -> FocLib
focLib (Focus -> FocLib) -> (HState -> Focus) -> HState -> FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> Focus
focus (HState -> FocLib) -> HState -> FocLib
forall a b. (a -> b) -> a -> b
$ HState
st) FocLib -> FocLib -> Bool
forall a. Eq a => a -> a -> Bool
== FocLib
FocAlbums)
(Value -> Text
forall a. ToString a => a -> Text
MPD.toText (Value -> Text)
-> GenericList Name Vector Value -> GenericList Name Vector Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HState
st HState
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
-> GenericList Name Vector Value
forall s a. s -> Getting a s a -> a
^. (LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState)
-> ((GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState
Lens' LibraryState (GenericList Name Vector Value)
albumsL)
)
)
drawLibraryRight :: HState -> Widget Name
drawLibraryRight :: HState -> Widget Name
drawLibraryRight 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
LibraryRight (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
LibraryRight (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
LibraryRight 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 -> Song -> Widget Name)
-> Bool -> GenericList Name Vector Song -> 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 -> Widget Name) -> Bool -> Song -> Widget Name
forall a b. a -> b -> a
const ((Song -> Widget Name) -> Bool -> Song -> Widget Name)
-> (Song -> Widget Name) -> Bool -> Song -> Widget Name
forall a b. (a -> b) -> a -> b
$ HState -> Song -> Widget Name
forall n. HState -> Song -> Widget n
librarySongRow HState
st)
((Focus -> FocLib
focLib (Focus -> FocLib) -> (HState -> Focus) -> HState -> FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HState -> Focus
focus (HState -> FocLib) -> HState -> FocLib
forall a b. (a -> b) -> a -> b
$ HState
st) FocLib -> FocLib -> Bool
forall a. Eq a => a -> a -> Bool
== FocLib
FocSongs)
(HState
st HState
-> Getting
(GenericList Name Vector Song)
HState
(GenericList Name Vector Song)
-> GenericList Name Vector Song
forall s a. s -> Getting a s a -> a
^. (LibraryState -> Const (GenericList Name Vector Song) LibraryState)
-> HState -> Const (GenericList Name Vector Song) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Song) LibraryState)
-> HState -> Const (GenericList Name Vector Song) HState)
-> ((GenericList Name Vector Song
-> Const
(GenericList Name Vector Song) (GenericList Name Vector Song))
-> LibraryState
-> Const (GenericList Name Vector Song) LibraryState)
-> Getting
(GenericList Name Vector Song)
HState
(GenericList Name Vector Song)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Song
-> Const
(GenericList Name Vector Song) (GenericList Name Vector Song))
-> LibraryState
-> Const (GenericList Name Vector Song) LibraryState
Lens' LibraryState (GenericList Name Vector Song)
songsL)
)
)
libraryRow :: HState -> Name -> T.Text -> Widget n
libraryRow :: HState -> Name -> Text -> Widget n
libraryRow HState
_ Name
name Text
val =
AttrName -> Widget n -> Widget n
forall n. AttrName -> Widget n -> Widget n
withAttr
(case Name
name of
Name
LibraryLeft -> AttrName
queueArtistAttr
Name
LibraryMid -> AttrName
queueAlbumAttr
Name
_ -> AttrName
listAttr
)
(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
librarySongRow :: HState -> MPD.Song -> Widget n
librarySongRow :: HState -> Song -> Widget n
librarySongRow HState
st Song
song =
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 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)
libraryMoveRight :: FocLib -> FocLib
libraryMoveRight :: FocLib -> FocLib
libraryMoveRight FocLib
FocArtists = FocLib
FocAlbums
libraryMoveRight FocLib
_ = FocLib
FocSongs
libraryMoveLeft :: FocLib -> FocLib
libraryMoveLeft :: FocLib -> FocLib
libraryMoveLeft FocLib
FocSongs = FocLib
FocAlbums
libraryMoveLeft FocLib
_ = FocLib
FocArtists
drawViewLibrary :: HState -> Widget Name
drawViewLibrary :: HState -> Widget Name
drawViewLibrary HState
st =
HState -> Widget Name
drawLibraryLeft HState
st Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> HState -> Widget Name
drawLibraryMid HState
st Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> HState -> Widget Name
drawLibraryRight HState
st
libraryMove
:: (forall e . List Name e -> List Name e) -> HState -> EventM Name HState
libraryMove :: (forall e. List Name e -> List Name e)
-> HState -> EventM Name HState
libraryMove forall e. List Name e -> List Name e
moveFunc HState
s =
let libfoc :: FocLib
libfoc = HState
s HState -> Getting FocLib HState FocLib -> FocLib
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocLib Focus) -> HState -> Const FocLib HState
Lens' HState Focus
focusL ((Focus -> Const FocLib Focus) -> HState -> Const FocLib HState)
-> ((FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus)
-> Getting FocLib HState FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus
Lens' Focus FocLib
focLibL
in case FocLib
libfoc of
FocLib
FocArtists -> HState -> EventM Name HState
forall (m :: * -> *). MonadIO m => HState -> m HState
rebuildLibArtists (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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL ((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Value)
artistsL ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState -> Identity HState)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector Value -> GenericList Name Vector Value
forall e. List Name e -> List Name e
moveFunc
FocLib
FocAlbums -> HState -> EventM Name HState
forall (m :: * -> *). MonadIO m => HState -> m HState
rebuildLibAlbums (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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL ((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Value)
albumsL ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState -> Identity HState)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector Value -> GenericList Name Vector Value
forall e. List Name e -> List Name e
moveFunc
FocLib
FocSongs -> 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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL ((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Song)
songsL ((GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> HState -> Identity HState)
-> (GenericList Name Vector Song -> GenericList Name Vector Song)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ GenericList Name Vector Song -> GenericList Name Vector Song
forall e. List Name e -> List Name e
moveFunc
libraryAddtoQ :: Bool -> HState -> EventM Name HState
libraryAddtoQ :: Bool -> HState -> EventM Name HState
libraryAddtoQ Bool
play HState
s =
let libfoc :: FocLib
libfoc = HState
s HState -> Getting FocLib HState FocLib -> FocLib
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocLib Focus) -> HState -> Const FocLib HState
Lens' HState Focus
focusL ((Focus -> Const FocLib Focus) -> HState -> Const FocLib HState)
-> ((FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus)
-> Getting FocLib HState FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus
Lens' Focus FocLib
focLibL
in
case FocLib
libfoc of
FocLib
FocArtists -> do
Vector Song
songs <-
IO (Vector Song) -> EventM Name (Vector Song)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(Maybe Value -> IO (Vector Song)
songsOfArtist
((Int, Value) -> Value
forall a b. (a, b) -> b
snd ((Int, Value) -> Value) -> Maybe (Int, Value) -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector Value -> Maybe (Int, Value)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement (HState
s HState
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
-> GenericList Name Vector Value
forall s a. s -> Getting a s a -> a
^. (LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState)
-> ((GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState
Lens' LibraryState (GenericList Name Vector Value)
artistsL))
)
Bool -> Vector Song -> HState -> EventM Name HState
forall n. Bool -> Vector Song -> HState -> EventM n HState
songBulkAddtoQ Bool
play Vector Song
songs HState
s
FocLib
FocAlbums -> do
Vector Song
songs <-
IO (Vector Song) -> EventM Name (Vector Song)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(Maybe Value -> IO (Vector Song)
songsOfAlbum
((Int, Value) -> Value
forall a b. (a, b) -> b
snd ((Int, Value) -> Value) -> Maybe (Int, Value) -> Maybe Value
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector Value -> Maybe (Int, Value)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement (HState
s HState
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
-> GenericList Name Vector Value
forall s a. s -> Getting a s a -> a
^. (LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> HState -> Const (GenericList Name Vector Value) HState)
-> ((GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState)
-> Getting
(GenericList Name Vector Value)
HState
(GenericList Name Vector Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Const
(GenericList Name Vector Value) (GenericList Name Vector Value))
-> LibraryState
-> Const (GenericList Name Vector Value) LibraryState
Lens' LibraryState (GenericList Name Vector Value)
albumsL))
)
Bool -> Vector Song -> HState -> EventM Name HState
forall n. Bool -> Vector Song -> HState -> EventM n HState
songBulkAddtoQ Bool
play Vector Song
songs HState
s
FocLib
FocSongs -> do
let maybeFilePath :: Maybe Path
maybeFilePath = Song -> Path
MPD.sgFilePath (Song -> Path) -> ((Int, Song) -> Song) -> (Int, Song) -> Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int, Song) -> Song
forall a b. (a, b) -> b
snd ((Int, Song) -> Path) -> Maybe (Int, Song) -> Maybe Path
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector Song -> Maybe (Int, Song)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement
(HState
s HState
-> Getting
(GenericList Name Vector Song)
HState
(GenericList Name Vector Song)
-> GenericList Name Vector Song
forall s a. s -> Getting a s a -> a
^. (LibraryState -> Const (GenericList Name Vector Song) LibraryState)
-> HState -> Const (GenericList Name Vector Song) HState
Lens' HState LibraryState
libraryL ((LibraryState
-> Const (GenericList Name Vector Song) LibraryState)
-> HState -> Const (GenericList Name Vector Song) HState)
-> ((GenericList Name Vector Song
-> Const
(GenericList Name Vector Song) (GenericList Name Vector Song))
-> LibraryState
-> Const (GenericList Name Vector Song) LibraryState)
-> Getting
(GenericList Name Vector Song)
HState
(GenericList Name Vector Song)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Song
-> Const
(GenericList Name Vector Song) (GenericList Name Vector Song))
-> LibraryState
-> Const (GenericList Name Vector Song) LibraryState
Lens' LibraryState (GenericList Name Vector Song)
songsL)
(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 }
librarySearch :: Bool -> HState -> EventM Name HState
librarySearch :: Bool -> HState -> EventM Name HState
librarySearch Bool
direction HState
s =
let libfoc :: FocLib
libfoc = HState
s HState -> Getting FocLib HState FocLib -> FocLib
forall s a. s -> Getting a s a -> a
^. (Focus -> Const FocLib Focus) -> HState -> Const FocLib HState
Lens' HState Focus
focusL ((Focus -> Const FocLib Focus) -> HState -> Const FocLib HState)
-> ((FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus)
-> Getting FocLib HState FocLib
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocLib -> Const FocLib FocLib) -> Focus -> Const FocLib Focus
Lens' Focus FocLib
focLibL
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 FocLib
libfoc of
FocLib
FocArtists -> 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
rebuildLibArtists
(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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL
((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Value)
artistsL
((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState -> Identity HState)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector Value -> GenericList Name Vector Value
forall n e. GenericList n Vector e -> GenericList n Vector e
dir (GenericList Name Vector Value -> GenericList Name Vector Value)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> GenericList Name Vector Value
-> GenericList Name Vector Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Value -> Bool)
-> GenericList Name Vector Value -> GenericList Name Vector Value
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy (Text -> Value -> Bool
forall a. ToString a => Text -> a -> Bool
stringySearch Text
searchkey) (GenericList Name Vector Value -> GenericList Name Vector Value)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> GenericList Name Vector Value
-> GenericList Name Vector Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector Value -> GenericList Name Vector Value
forall n e. GenericList n Vector e -> GenericList n Vector e
dir)
FocLib
FocAlbums -> 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
rebuildLibAlbums
(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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL
((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Value)
albumsL
((GenericList Name Vector Value
-> Identity (GenericList Name Vector Value))
-> HState -> Identity HState)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector Value -> GenericList Name Vector Value
forall n e. GenericList n Vector e -> GenericList n Vector e
dir (GenericList Name Vector Value -> GenericList Name Vector Value)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> GenericList Name Vector Value
-> GenericList Name Vector Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Value -> Bool)
-> GenericList Name Vector Value -> GenericList Name Vector Value
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
(e -> Bool) -> GenericList n t e -> GenericList n t e
listFindBy (Text -> Value -> Bool
forall a. ToString a => Text -> a -> Bool
stringySearch Text
searchkey) (GenericList Name Vector Value -> GenericList Name Vector Value)
-> (GenericList Name Vector Value -> GenericList Name Vector Value)
-> GenericList Name Vector Value
-> GenericList Name Vector Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector Value -> GenericList Name Vector Value
forall n e. GenericList n Vector e -> GenericList n Vector e
dir)
FocLib
FocSongs -> 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
& (LibraryState -> Identity LibraryState)
-> HState -> Identity HState
Lens' HState LibraryState
libraryL
((LibraryState -> Identity LibraryState)
-> HState -> Identity HState)
-> ((GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> LibraryState -> Identity LibraryState)
-> (GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> LibraryState -> Identity LibraryState
Lens' LibraryState (GenericList Name Vector Song)
songsL
((GenericList Name Vector Song
-> Identity (GenericList Name Vector Song))
-> HState -> Identity HState)
-> (GenericList Name Vector Song -> GenericList Name Vector Song)
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (GenericList Name Vector Song -> GenericList Name Vector Song
forall n e. GenericList n Vector e -> GenericList n Vector e
dir (GenericList Name Vector Song -> GenericList Name Vector Song)
-> (GenericList Name Vector Song -> GenericList Name Vector Song)
-> GenericList Name Vector Song
-> GenericList Name Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Song -> Bool)
-> GenericList Name Vector Song -> GenericList Name Vector Song
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]) (GenericList Name Vector Song -> GenericList Name Vector Song)
-> (GenericList Name Vector Song -> GenericList Name Vector Song)
-> GenericList Name Vector Song
-> GenericList Name Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenericList Name Vector Song -> GenericList Name Vector Song
forall n e. GenericList n Vector e -> GenericList n Vector e
dir)
handleEventLibrary
:: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventLibrary :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventLibrary 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
libraryMove 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
libraryMove 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)
-> ((FocLib -> Identity FocLib) -> Focus -> Identity Focus)
-> (FocLib -> Identity FocLib)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocLib -> Identity FocLib) -> Focus -> Identity Focus
Lens' Focus FocLib
focLibL ((FocLib -> Identity FocLib) -> HState -> Identity HState)
-> (FocLib -> FocLib) -> HState -> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ FocLib -> FocLib
libraryMoveRight
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)
-> ((FocLib -> Identity FocLib) -> Focus -> Identity Focus)
-> (FocLib -> Identity FocLib)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocLib -> Identity FocLib) -> Focus -> Identity Focus
Lens' Focus FocLib
focLibL ((FocLib -> Identity FocLib) -> HState -> Identity HState)
-> (FocLib -> FocLib) -> HState -> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ FocLib -> FocLib
libraryMoveLeft
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
librarySearch (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
librarySearch (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
libraryMove 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
libraryAddtoQ Bool
True HState
s
EvKey (KChar Char
' ') [] ->
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
libraryMove 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
libraryAddtoQ Bool
False 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
libraryMove (\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
libraryMove (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
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
addToPl :: EventM Name HState
addToPl :: EventM Name HState
addToPl = Text -> EventM Name HState
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"not implemented"