{-# LANGUAGE LambdaCase #-}
module Hum.UI where
import Brick.Main
import Brick.Types
import qualified Brick.BChan as BC
import Brick.Widgets.Core
import Brick.Widgets.List
import Brick.Widgets.Edit
import Graphics.Vty.Input.Events
import Network.MPD ( withMPD )
import qualified Network.MPD as MPD
import Hum.Types
import qualified Data.Vector as V
import qualified Data.Text as T
import Hum.Attributes
import Hum.Views
import Hum.Modes
import Hum.Utils
import Hum.Rebuild
import qualified Data.Map.Strict as Map
import Control.Lens
import System.Directory
app :: App HState HumEvent Name
app :: App HState HumEvent Name
app = App :: forall s e n.
(s -> [Widget n])
-> (s -> [CursorLocation n] -> Maybe (CursorLocation n))
-> (s -> BrickEvent n e -> EventM n (Next s))
-> (s -> EventM n s)
-> (s -> AttrMap)
-> App s e n
App { appDraw :: HState -> [Widget Name]
appDraw = HState -> [Widget Name]
drawUI
, appChooseCursor :: HState -> [CursorLocation Name] -> Maybe (CursorLocation Name)
appChooseCursor = HState -> [CursorLocation Name] -> Maybe (CursorLocation Name)
chooseCursor
, appHandleEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
appHandleEvent = HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEvent
, appStartEvent :: HState -> EventM Name HState
appStartEvent = HState -> EventM Name HState
humStartEvent
, appAttrMap :: HState -> AttrMap
appAttrMap = AttrMap -> HState -> AttrMap
forall a b. a -> b -> a
const AttrMap
humAttrMap
}
drawUI :: HState -> [Widget Name]
drawUI :: HState -> [Widget Name]
drawUI HState
st =
[if HState
st HState -> Getting Mode HState Mode -> Mode
forall s a. s -> Getting a s a -> a
^. Getting Mode HState Mode
Lens' HState Mode
modeL Mode -> Mode -> Bool
forall a. Eq a => a -> a -> Bool
== Mode
PromptMode then HState -> Widget Name
drawPrompt HState
st else Widget Name
forall n. Widget n
emptyWidget,
HState -> Widget Name
drawNowPlaying HState
st
Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=> (case HState -> View
hview HState
st of
View
QueueView -> HState -> Widget Name
drawViewQueue HState
st
View
LibraryView -> HState -> Widget Name
drawViewLibrary HState
st
View
PlaylistsView -> HState -> Widget Name
drawViewPlaylists HState
st
View
HelpView -> HState -> Widget Name
drawViewHelp HState
st
)
Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<=> if HState
st HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (Focus -> Const Bool Focus) -> HState -> Const Bool HState
Lens' HState Focus
focusL ((Focus -> Const Bool Focus) -> HState -> Const Bool HState)
-> ((Bool -> Const Bool Bool) -> Focus -> Const Bool Focus)
-> Getting Bool HState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> Focus -> Const Bool Focus
Lens' Focus Bool
focExL
then Text -> Widget Name
forall n. Text -> Widget n
txt (HState
st HState -> Getting ExSubMode HState ExSubMode -> ExSubMode
forall s a. s -> Getting a s a -> a
^. (ExState -> Const ExSubMode ExState)
-> HState -> Const ExSubMode HState
Lens' HState ExState
exL ((ExState -> Const ExSubMode ExState)
-> HState -> Const ExSubMode HState)
-> ((ExSubMode -> Const ExSubMode ExSubMode)
-> ExState -> Const ExSubMode ExState)
-> Getting ExSubMode HState ExSubMode
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ExSubMode -> Const ExSubMode ExSubMode)
-> ExState -> Const ExSubMode ExState
Lens' ExState ExSubMode
exPrefixL ExSubMode -> (ExSubMode -> Text) -> Text
forall a b. a -> (a -> b) -> b
& ExSubMode -> Text
exPrefixTxt) Widget Name -> Widget Name -> Widget Name
forall n. Widget n -> Widget n -> Widget n
<+> ([Text] -> Widget Name) -> Bool -> Editor Text Name -> Widget Name
forall n t.
(Ord n, Show n, Monoid t, TextWidth t, GenericTextZipper t) =>
([t] -> Widget n) -> Bool -> Editor t n -> Widget n
renderEditor
(Text -> Widget Name
forall n. Text -> Widget n
txt (Text -> Widget Name) -> ([Text] -> Text) -> [Text] -> Widget Name
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> Text
T.unlines)
(HState
st HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (Focus -> Const Bool Focus) -> HState -> Const Bool HState
Lens' HState Focus
focusL ((Focus -> Const Bool Focus) -> HState -> Const Bool HState)
-> ((Bool -> Const Bool Bool) -> Focus -> Const Bool Focus)
-> Getting Bool HState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> Focus -> Const Bool Focus
Lens' Focus Bool
focExL)
(HState
st HState
-> Getting (Editor Text Name) HState (Editor Text Name)
-> Editor Text Name
forall s a. s -> Getting a s a -> a
^. (ExState -> Const (Editor Text Name) ExState)
-> HState -> Const (Editor Text Name) HState
Lens' HState ExState
exL ((ExState -> Const (Editor Text Name) ExState)
-> HState -> Const (Editor Text Name) HState)
-> ((Editor Text Name
-> Const (Editor Text Name) (Editor Text Name))
-> ExState -> Const (Editor Text Name) ExState)
-> Getting (Editor Text Name) HState (Editor Text Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Editor Text Name -> Const (Editor Text Name) (Editor Text Name))
-> ExState -> Const (Editor Text Name) ExState
Lens' ExState (Editor Text Name)
exEditorL)
else Text -> Widget Name
forall n. Text -> Widget n
txt Text
" "
]
chooseCursor :: HState -> [CursorLocation Name] -> Maybe (CursorLocation Name)
chooseCursor :: HState -> [CursorLocation Name] -> Maybe (CursorLocation Name)
chooseCursor HState
st [CursorLocation Name]
ls
| HState
st HState -> Getting Bool HState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (Focus -> Const Bool Focus) -> HState -> Const Bool HState
Lens' HState Focus
focusL ((Focus -> Const Bool Focus) -> HState -> Const Bool HState)
-> ((Bool -> Const Bool Bool) -> Focus -> Const Bool Focus)
-> Getting Bool HState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> Focus -> Const Bool Focus
Lens' Focus Bool
focExL = (CursorLocation Name -> Bool)
-> [CursorLocation Name] -> Maybe (CursorLocation Name)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (Name -> CursorLocation Name -> Bool
forall n1. Eq n1 => n1 -> CursorLocation n1 -> Bool
isCurrent Name
ExEditor) [CursorLocation Name]
ls
| HState
st HState -> Getting PromptType HState PromptType -> PromptType
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const PromptType Prompts)
-> HState -> Const PromptType HState
Lens' HState Prompts
promptsL ((Prompts -> Const PromptType Prompts)
-> HState -> Const PromptType HState)
-> ((PromptType -> Const PromptType PromptType)
-> Prompts -> Const PromptType Prompts)
-> Getting PromptType HState PromptType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PromptType -> Const PromptType PromptType)
-> Prompts -> Const PromptType Prompts
Lens' Prompts PromptType
currentPromptL PromptType -> PromptType -> Bool
forall a. Eq a => a -> a -> Bool
== PromptType
TextPrompt = (CursorLocation Name -> Bool)
-> [CursorLocation Name] -> Maybe (CursorLocation Name)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find (Name -> CursorLocation Name -> Bool
forall n1. Eq n1 => n1 -> CursorLocation n1 -> Bool
isCurrent Name
TextPromptEditor) [CursorLocation Name]
ls
| Bool
otherwise = Maybe (CursorLocation Name)
forall a. Maybe a
Nothing
where
isCurrent :: n1 -> CursorLocation n1 -> Bool
isCurrent n1
n CursorLocation n1
cl = CursorLocation n1
cl CursorLocation n1
-> Getting (Maybe n1) (CursorLocation n1) (Maybe n1) -> Maybe n1
forall s a. s -> Getting a s a -> a
^. Getting (Maybe n1) (CursorLocation n1) (Maybe n1)
forall n1 n2.
Lens (CursorLocation n1) (CursorLocation n2) (Maybe n1) (Maybe n2)
cursorLocationNameL Maybe n1 -> Maybe n1 -> Bool
forall a. Eq a => a -> a -> Bool
== n1 -> Maybe n1
forall a. a -> Maybe a
Just n1
n
buildInitialState :: BC.BChan HumEvent -> IO HState
buildInitialState :: BChan HumEvent -> IO HState
buildInitialState BChan HumEvent
chan = do
FilePath
configDir <- XdgDirectory -> FilePath -> IO FilePath
getXdgDirectory XdgDirectory
XdgConfig FilePath
"hum"
()
_ <- Bool -> FilePath -> IO ()
createDirectoryIfMissing Bool
True FilePath
configDir
let mode :: Mode
mode = Mode
NormalMode
let ex :: ExState
ex = ExState :: ExSubMode
-> Editor Text Name -> Bool -> [Text] -> [Text] -> ExState
ExState { exPrefix :: ExSubMode
exPrefix = ExSubMode
Cmd
, exEditor :: Editor Text Name
exEditor = Name -> Maybe Int -> Text -> Editor Text Name
forall n. n -> Maybe Int -> Text -> Editor Text n
editorText Name
ExEditor (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1) Text
""
, searchDirection :: Bool
searchDirection = Bool
True
, searchHistory :: [Text]
searchHistory = []
, cmdHistory :: [Text]
cmdHistory = []
}
Maybe Song
currentSong <- Maybe Song -> Either MPDError (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing (Either MPDError (Maybe Song) -> Maybe Song)
-> IO (Either MPDError (Maybe Song)) -> IO (Maybe Song)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD (Maybe Song) -> IO (Either MPDError (Maybe Song))
forall a. MPD a -> IO (Response a)
withMPD MPD (Maybe Song)
forall (m :: * -> *). MonadMPD m => m (Maybe Song)
MPD.currentSong
Maybe Status
status <- Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status)
let hview :: View
hview = View
QueueView
let extentMap :: Map k a
extentMap = Map k a
forall k a. Map k a
Map.empty
let focus :: Focus
focus = Focus :: FocQueue -> FocLib -> FocPlay -> Bool -> Focus
Focus { focQueue :: FocQueue
focQueue = FocQueue
FocQueue
, focLib :: FocLib
focLib = FocLib
FocArtists
, focPlay :: FocPlay
focPlay = FocPlay
FocPlaylists
, focEx :: Bool
focEx = Bool
False
}
let clipboard :: Clipboard
clipboard = Clipboard :: SongList -> Maybe PlaylistName -> Clipboard
Clipboard { clSongs :: SongList
clSongs = Name -> Vector (Song, Bool) -> Int -> SongList
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
ClSongs Vector (Song, Bool)
forall a. Vector a
V.empty Int
1
, clPlName :: Maybe PlaylistName
clPlName = Maybe PlaylistName
forall a. Maybe a
Nothing}
Vector Song
queueVec <- [Song] -> Vector Song
forall a. [a] -> Vector a
V.fromList ([Song] -> Vector Song)
-> (Either MPDError [Song] -> [Song])
-> Either MPDError [Song]
-> Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Song] -> Either MPDError [Song] -> [Song]
forall b a. b -> Either a b -> b
fromRight [] (Either MPDError [Song] -> Vector Song)
-> IO (Either MPDError [Song]) -> IO (Vector Song)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD [Song] -> IO (Either MPDError [Song])
forall a. MPD a -> IO (Response a)
withMPD (Maybe Int -> MPD [Song]
forall (m :: * -> *). MonadMPD m => Maybe Int -> m [Song]
MPD.playlistInfo Maybe Int
forall a. Maybe a
Nothing)
let queue :: SongList
queue = (, Bool
False) (Song -> (Song, Bool)) -> GenericList Name Vector Song -> SongList
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Vector Song -> Int -> GenericList Name Vector Song
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
QueueList Vector Song
queueVec Int
1
Vector Value
artistsVec <- [Value] -> Vector Value
forall a. [a] -> Vector a
V.fromList ([Value] -> Vector Value)
-> (Either MPDError [Value] -> [Value])
-> Either MPDError [Value]
-> Vector Value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Value] -> Either MPDError [Value] -> [Value]
forall b a. b -> Either a b -> b
fromRight [] (Either MPDError [Value] -> Vector Value)
-> IO (Either MPDError [Value]) -> IO (Vector Value)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD [Value] -> IO (Either MPDError [Value])
forall a. MPD a -> IO (Response a)
withMPD
(Metadata -> Maybe Value -> MPD [Value]
forall (m :: * -> *).
MonadMPD m =>
Metadata -> Maybe Value -> m [Value]
MPD.list Metadata
MPD.AlbumArtist Maybe Value
forall a. Maybe a
Nothing)
let artists :: GenericList Name Vector Value
artists = Name -> Vector Value -> Int -> GenericList Name Vector Value
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
ArtistsList Vector Value
artistsVec Int
1
Vector Value
albumsVec <- Maybe Value -> IO (Vector Value)
albumsOfArtist ((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 GenericList Name Vector Value
artists)
let albums :: GenericList Name Vector Value
albums = Name -> Vector Value -> Int -> GenericList Name Vector Value
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
AlbumsList Vector Value
albumsVec Int
1
Vector Song
songsVec <- 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 GenericList Name Vector Value
albums)
let songs :: GenericList Name Vector Song
songs = Name -> Vector Song -> Int -> GenericList Name Vector Song
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
SongsList Vector Song
songsVec Int
1
Vector PlaylistName
plListVec <- [PlaylistName] -> Vector PlaylistName
forall a. [a] -> Vector a
V.fromList ([PlaylistName] -> Vector PlaylistName)
-> (Either MPDError [PlaylistName] -> [PlaylistName])
-> Either MPDError [PlaylistName]
-> Vector PlaylistName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [PlaylistName] -> Either MPDError [PlaylistName] -> [PlaylistName]
forall b a. b -> Either a b -> b
fromRight [] (Either MPDError [PlaylistName] -> Vector PlaylistName)
-> IO (Either MPDError [PlaylistName]) -> IO (Vector PlaylistName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD [PlaylistName] -> IO (Either MPDError [PlaylistName])
forall a. MPD a -> IO (Response a)
withMPD MPD [PlaylistName]
forall (m :: * -> *). MonadMPD m => m [PlaylistName]
MPD.listPlaylists
let plList :: GenericList Name Vector PlaylistName
plList = Name
-> Vector PlaylistName
-> Int
-> GenericList Name Vector PlaylistName
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
PlaylistList Vector PlaylistName
plListVec Int
1
Vector Song
plSongsVec <- [Song] -> Vector Song
forall a. [a] -> Vector a
V.fromList ([Song] -> Vector Song)
-> (Either MPDError [Song] -> [Song])
-> Either MPDError [Song]
-> Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Song] -> Either MPDError [Song] -> [Song]
forall b a. b -> Either a b -> b
fromRight [] (Either MPDError [Song] -> Vector Song)
-> IO (Either MPDError [Song]) -> IO (Vector Song)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD [Song] -> IO (Either MPDError [Song])
forall a. MPD a -> IO (Response a)
withMPD
( PlaylistName -> MPD [Song]
forall (m :: * -> *). MonadMPD m => PlaylistName -> m [Song]
MPD.listPlaylistInfo
(PlaylistName -> MPD [Song]) -> PlaylistName -> MPD [Song]
forall a b. (a -> b) -> a -> b
$ PlaylistName
-> ((Int, PlaylistName) -> PlaylistName)
-> Maybe (Int, PlaylistName)
-> PlaylistName
forall b a. b -> (a -> b) -> Maybe a -> b
maybe PlaylistName
"<no playlists>" (Int, PlaylistName) -> PlaylistName
forall a b. (a, b) -> b
snd (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
plList)
)
let plSongs :: SongList
plSongs = (, Bool
False) (Song -> (Song, Bool)) -> GenericList Name Vector Song -> SongList
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Vector Song -> Int -> GenericList Name Vector Song
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
PlaylistSongs Vector Song
plSongsVec Int
1
let library :: LibraryState
library = LibraryState :: GenericList Name Vector Value
-> GenericList Name Vector Value
-> GenericList Name Vector Song
-> LibraryState
LibraryState { GenericList Name Vector Value
artists :: GenericList Name Vector Value
artists :: GenericList Name Vector Value
artists, GenericList Name Vector Value
albums :: GenericList Name Vector Value
albums :: GenericList Name Vector Value
albums, GenericList Name Vector Song
songs :: GenericList Name Vector Song
songs :: GenericList Name Vector Song
songs }
let playlists :: PlaylistsState
playlists = PlaylistsState :: GenericList Name Vector PlaylistName -> SongList -> PlaylistsState
PlaylistsState { GenericList Name Vector PlaylistName
plList :: GenericList Name Vector PlaylistName
plList :: GenericList Name Vector PlaylistName
plList, SongList
plSongs :: SongList
plSongs :: SongList
plSongs }
let editable :: Bool
editable = Bool
False
let prompts :: Prompts
prompts = Prompts :: PromptType
-> Text
-> List Name (Maybe PlaylistName)
-> Editor Text Name
-> (HState -> EventM Name HState)
-> Prompts
Prompts
{ currentPrompt :: PromptType
currentPrompt = PromptType
PlSelectPrompt
, promptTitle :: Text
promptTitle = Text
""
, textPrompt :: Editor Text Name
textPrompt = Name -> Maybe Int -> Text -> Editor Text Name
forall n. n -> Maybe Int -> Text -> Editor Text n
editorText Name
TextPromptEditor (Int -> Maybe Int
forall a. a -> Maybe a
Just Int
1) Text
""
, plSelectPrompt :: List Name (Maybe PlaylistName)
plSelectPrompt = Int
-> Maybe PlaylistName
-> List Name (Maybe PlaylistName)
-> List Name (Maybe PlaylistName)
forall (t :: * -> *) e n.
(Splittable t, Applicative t, Semigroup (t e)) =>
Int -> e -> GenericList n t e -> GenericList n t e
listInsert Int
0 Maybe PlaylistName
forall a. Maybe a
Nothing (PlaylistName -> Maybe PlaylistName
forall a. a -> Maybe a
Just (PlaylistName -> Maybe PlaylistName)
-> GenericList Name Vector PlaylistName
-> List Name (Maybe PlaylistName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList Name Vector PlaylistName
plList)
, exitPrompt :: HState -> EventM Name HState
exitPrompt = \HState
s -> 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
& (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
NormalMode
}
let helpScreen :: Int
helpScreen = Int
0
HState -> IO HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure HState :: BChan HumEvent
-> View
-> Maybe Status
-> Mode
-> ExState
-> Maybe Song
-> SongList
-> LibraryState
-> PlaylistsState
-> Map Name (Maybe (Extent Name))
-> Clipboard
-> Focus
-> Bool
-> Prompts
-> Int
-> HState
HState { BChan HumEvent
chan :: BChan HumEvent
chan :: BChan HumEvent
chan
, View
hview :: View
hview :: View
hview
, Mode
mode :: Mode
mode :: Mode
mode
, ExState
ex :: ExState
ex :: ExState
ex
, Maybe Status
status :: Maybe Status
status :: Maybe Status
status
, Maybe Song
currentSong :: Maybe Song
currentSong :: Maybe Song
currentSong
, SongList
queue :: SongList
queue :: SongList
queue
, Map Name (Maybe (Extent Name))
forall k a. Map k a
extentMap :: Map Name (Maybe (Extent Name))
extentMap :: forall k a. Map k a
extentMap
, Clipboard
clipboard :: Clipboard
clipboard :: Clipboard
clipboard
, LibraryState
library :: LibraryState
library :: LibraryState
library
, PlaylistsState
playlists :: PlaylistsState
playlists :: PlaylistsState
playlists
, Focus
focus :: Focus
focus :: Focus
focus
, Bool
editable :: Bool
editable :: Bool
editable
, Prompts
prompts :: Prompts
prompts :: Prompts
prompts
, Int
helpScreen :: Int
helpScreen :: Int
helpScreen
}
humStartEvent :: HState -> EventM Name HState
humStartEvent :: HState -> EventM Name HState
humStartEvent = HState -> EventM Name HState
forall (f :: * -> *) a. Applicative f => a -> f a
pure
hBoxPad :: Padding -> [Widget n] -> Widget n
hBoxPad :: Padding -> [Widget n] -> Widget n
hBoxPad Padding
_ [] = Widget n
forall n. Widget n
emptyWidget
hBoxPad Padding
_ [Widget n
w ] = Widget n
w
hBoxPad Padding
p (Widget n
w : [Widget n]
ws) = Padding -> Widget n -> Widget n
forall n. Padding -> Widget n -> Widget n
padRight Padding
p Widget n
w Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> Padding -> [Widget n] -> Widget n
forall n. Padding -> [Widget n] -> Widget n
hBoxPad Padding
p [Widget n]
ws
seekCurEventM :: MPD.FractionalSeconds -> HState -> EventM Name HState
seekCurEventM :: FractionalSeconds -> HState -> EventM Name HState
seekCurEventM FractionalSeconds
i HState
s = do
Response ()
_ <- 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
$ Bool -> FractionalSeconds -> MPD ()
forall (m :: * -> *).
MonadMPD m =>
Bool -> FractionalSeconds -> m ()
MPD.seekCur Bool
False FractionalSeconds
i)
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
Either MPDError (Maybe Song)
song <- IO (Either MPDError (Maybe Song))
-> EventM Name (Either MPDError (Maybe Song))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (MPD (Maybe Song) -> IO (Either MPDError (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 -> Either MPDError (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing Either MPDError (Maybe Song)
song, Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
handleEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEvent HState
s BrickEvent Name HumEvent
e = case BrickEvent Name HumEvent
e of
VtyEvent Event
vtye -> case HState
s HState -> Getting Mode HState Mode -> Mode
forall s a. s -> Getting a s a -> a
^. Getting Mode HState Mode
Lens' HState Mode
modeL of
Mode
ExMode -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleExEvent HState
s BrickEvent Name HumEvent
e
Mode
PromptMode -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePromptEvent HState
s BrickEvent Name HumEvent
e
Mode
NormalMode -> case Event
vtye of
EvKey (KChar Char
'q') [] -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
halt HState
s
EvKey (KChar Char
't') [] -> do
Either MPDError PlaybackState
st <- IO (Either MPDError PlaybackState)
-> EventM Name (Either MPDError PlaybackState)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO ((Status -> PlaybackState
MPD.stState (Status -> PlaybackState)
-> Either MPDError Status -> Either MPDError PlaybackState
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (Either MPDError Status -> Either MPDError PlaybackState)
-> IO (Either MPDError Status)
-> IO (Either MPDError PlaybackState)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status)
Response ()
_ <- case Either MPDError PlaybackState
st of
Left MPDError
_ -> 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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.pause Bool
True)
Right PlaybackState
MPD.Paused -> 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
$ Maybe Int -> MPD ()
forall (m :: * -> *). MonadMPD m => Maybe Int -> m ()
MPD.play Maybe Int
forall a. Maybe a
Nothing)
Right PlaybackState
MPD.Stopped -> 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
$ Maybe Int -> MPD ()
forall (m :: * -> *). MonadMPD m => Maybe Int -> m ()
MPD.play Maybe Int
forall a. Maybe a
Nothing)
Right PlaybackState
MPD.Playing -> 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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.pause Bool
True)
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
EvKey (KChar Char
's') [] -> do
Response ()
_ <- 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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.single (Bool -> (Status -> Bool) -> Maybe Status -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Bool -> Bool
not (Bool -> Bool) -> (Status -> Bool) -> Status -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Bool
MPD.stSingle) (HState -> Maybe Status
status HState
s)))
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
EvKey (KChar Char
'c') [] -> do
Response ()
_ <-
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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.consume (Bool -> (Status -> Bool) -> Maybe Status -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Bool -> Bool
not (Bool -> Bool) -> (Status -> Bool) -> Status -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Bool
MPD.stConsume) (HState -> Maybe Status
status HState
s))
)
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
EvKey (KChar Char
'x') [] -> do
Response ()
_ <- 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
$ Seconds -> MPD ()
forall (m :: * -> *). MonadMPD m => Seconds -> m ()
MPD.crossfade
( (\case
Seconds
0 -> Seconds
5
Seconds
_ -> Seconds
0
)
(Seconds -> Seconds) -> Seconds -> Seconds
forall a b. (a -> b) -> a -> b
$ Seconds -> (Status -> Seconds) -> Maybe Status -> Seconds
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Seconds
0 Status -> Seconds
MPD.stXFadeWidth (HState -> Maybe Status
status HState
s)
)
)
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
EvKey (KChar Char
'r') [] -> do
Response ()
_ <- 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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.repeat (Bool -> (Status -> Bool) -> Maybe Status -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Bool -> Bool
not (Bool -> Bool) -> (Status -> Bool) -> Status -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Bool
MPD.stRepeat) (HState -> Maybe Status
status HState
s)))
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
EvKey (KChar Char
'z') [] -> do
Response ()
_ <- 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
$ Bool -> MPD ()
forall (m :: * -> *). MonadMPD m => Bool -> m ()
MPD.random (Bool -> (Status -> Bool) -> Maybe Status -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
False (Bool -> Bool
not (Bool -> Bool) -> (Status -> Bool) -> Status -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Status -> Bool
MPD.stRandom) (HState -> Maybe Status
status HState
s)))
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status }
EvKey (KChar Char
'/') [] ->
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
ExMode
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (ExState -> Identity ExState) -> HState -> Identity HState
Lens' HState ExState
exL ((ExState -> Identity ExState) -> HState -> Identity HState)
-> ((ExSubMode -> Identity ExSubMode)
-> ExState -> Identity ExState)
-> (ExSubMode -> Identity ExSubMode)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ExSubMode -> Identity ExSubMode) -> ExState -> Identity ExState
Lens' ExState ExSubMode
exPrefixL ((ExSubMode -> Identity ExSubMode) -> HState -> Identity HState)
-> ExSubMode -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ExSubMode
FSearch
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (ExState -> Identity ExState) -> HState -> Identity HState
Lens' HState ExState
exL ((ExState -> Identity ExState) -> HState -> Identity HState)
-> ((Bool -> Identity Bool) -> ExState -> Identity ExState)
-> (Bool -> Identity Bool)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> ExState -> Identity ExState
Lens' ExState Bool
searchDirectionL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> Bool -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True
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)
-> ((Bool -> Identity Bool) -> Focus -> Identity Focus)
-> (Bool -> Identity Bool)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> Focus -> Identity Focus
Lens' Focus Bool
focExL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> Bool -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True
EvKey (KChar Char
'?') [] ->
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
ExMode
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (ExState -> Identity ExState) -> HState -> Identity HState
Lens' HState ExState
exL ((ExState -> Identity ExState) -> HState -> Identity HState)
-> ((ExSubMode -> Identity ExSubMode)
-> ExState -> Identity ExState)
-> (ExSubMode -> Identity ExSubMode)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ExSubMode -> Identity ExSubMode) -> ExState -> Identity ExState
Lens' ExState ExSubMode
exPrefixL ((ExSubMode -> Identity ExSubMode) -> HState -> Identity HState)
-> ExSubMode -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ExSubMode
BSearch
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (ExState -> Identity ExState) -> HState -> Identity HState
Lens' HState ExState
exL ((ExState -> Identity ExState) -> HState -> Identity HState)
-> ((Bool -> Identity Bool) -> ExState -> Identity ExState)
-> (Bool -> Identity Bool)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> ExState -> Identity ExState
Lens' ExState Bool
searchDirectionL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> Bool -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False
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)
-> ((Bool -> Identity Bool) -> Focus -> Identity Focus)
-> (Bool -> Identity Bool)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> Focus -> Identity Focus
Lens' Focus Bool
focExL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> Bool -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True
EvKey (KChar Char
':') [] ->
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
ExMode
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (ExState -> Identity ExState) -> HState -> Identity HState
Lens' HState ExState
exL ((ExState -> Identity ExState) -> HState -> Identity HState)
-> ((ExSubMode -> Identity ExSubMode)
-> ExState -> Identity ExState)
-> (ExSubMode -> Identity ExSubMode)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ExSubMode -> Identity ExSubMode) -> ExState -> Identity ExState
Lens' ExState ExSubMode
exPrefixL ((ExSubMode -> Identity ExSubMode) -> HState -> Identity HState)
-> ExSubMode -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ ExSubMode
Cmd
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)
-> ((Bool -> Identity Bool) -> Focus -> Identity Focus)
-> (Bool -> Identity Bool)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> Focus -> Identity Focus
Lens' Focus Bool
focExL ((Bool -> Identity Bool) -> HState -> Identity HState)
-> Bool -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True
EvKey (KChar Char
'.') [] -> do
Response ()
_ <- 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 ()
forall (m :: * -> *). MonadMPD m => m ()
MPD.next)
Either MPDError (Maybe Song)
song <- IO (Either MPDError (Maybe Song))
-> EventM Name (Either MPDError (Maybe Song))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (MPD (Maybe Song) -> IO (Either MPDError (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 (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { currentSong :: Maybe Song
currentSong = Maybe Song -> Either MPDError (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing Either MPDError (Maybe Song)
song }
EvKey (KChar Char
',') [] -> do
Response ()
_ <- 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 ()
forall (m :: * -> *). MonadMPD m => m ()
MPD.previous)
Either MPDError (Maybe Song)
song <- IO (Either MPDError (Maybe Song))
-> EventM Name (Either MPDError (Maybe Song))
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (MPD (Maybe Song) -> IO (Either MPDError (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 (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { currentSong :: Maybe Song
currentSong = Maybe Song -> Either MPDError (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing Either MPDError (Maybe Song)
song }
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
=<< FractionalSeconds -> HState -> EventM Name HState
seekCurEventM FractionalSeconds
5 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
=<< FractionalSeconds -> HState -> EventM Name HState
seekCurEventM (-FractionalSeconds
5) 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
=<< FractionalSeconds -> HState -> EventM Name HState
seekCurEventM FractionalSeconds
30 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
=<< FractionalSeconds -> HState -> EventM Name HState
seekCurEventM (-FractionalSeconds
30) HState
s
EvKey (KChar Char
'1') [] -> do
()
_ <- IO () -> EventM Name ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (BChan HumEvent -> HumEvent -> IO ()
forall a. BChan a -> a -> IO ()
BC.writeBChan (HState -> BChan HumEvent
chan HState
s) (Tick -> HumEvent
forall a b. a -> Either a b
Left Tick
Tick))
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 -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (View -> Identity View) -> HState -> Identity HState
Lens' HState View
hviewL ((View -> Identity View) -> HState -> Identity HState)
-> View -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ View
QueueView
EvKey (KChar Char
'2') [] -> do
()
_ <- IO () -> EventM Name ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (BChan HumEvent -> HumEvent -> IO ()
forall a. BChan a -> a -> IO ()
BC.writeBChan (HState -> BChan HumEvent
chan HState
s) (Tick -> HumEvent
forall a b. a -> Either a b
Left Tick
Tick))
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 -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (View -> Identity View) -> HState -> Identity HState
Lens' HState View
hviewL ((View -> Identity View) -> HState -> Identity HState)
-> View -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ View
LibraryView
EvKey (KChar Char
'3') [] -> do
()
_ <- IO () -> EventM Name ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (BChan HumEvent -> HumEvent -> IO ()
forall a. BChan a -> a -> IO ()
BC.writeBChan (HState -> BChan HumEvent
chan HState
s) (Tick -> HumEvent
forall a b. a -> Either a b
Left Tick
Tick))
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 -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (View -> Identity View) -> HState -> Identity HState
Lens' HState View
hviewL ((View -> Identity View) -> HState -> Identity HState)
-> View -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ View
PlaylistsView
EvResize Int
_ Int
_ -> do
Map Name (Maybe (Extent Name))
extentMap <- EventM Name (Map Name (Maybe (Extent Name)))
updateExtentMap
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap }
Event
_ -> case HState -> View
hview HState
s of
View
QueueView -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventQueue HState
s BrickEvent Name HumEvent
e
View
LibraryView -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventLibrary HState
s BrickEvent Name HumEvent
e
View
PlaylistsView -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventPlaylists HState
s BrickEvent Name HumEvent
e
View
HelpView -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleEventHelp HState
s BrickEvent Name HumEvent
e
(AppEvent (Left Tick
Tick)) -> do
Map Name (Maybe (Extent Name))
extentMap <- EventM Name (Map Name (Maybe (Extent Name)))
updateExtentMap
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Status
status :: Maybe Status
status :: Maybe Status
status, Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap :: Map Name (Maybe (Extent Name))
extentMap }
(AppEvent (Right (Right [Subsystem]
_))) -> do
Maybe Song
currentSong <- IO (Maybe Song) -> EventM Name (Maybe Song)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Song -> Either MPDError (Maybe Song) -> Maybe Song
forall b a. b -> Either a b -> b
fromRight Maybe Song
forall a. Maybe a
Nothing (Either MPDError (Maybe Song) -> Maybe Song)
-> IO (Either MPDError (Maybe Song)) -> IO (Maybe Song)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD (Maybe Song) -> IO (Either MPDError (Maybe Song))
forall a. MPD a -> IO (Response a)
withMPD MPD (Maybe Song)
forall (m :: * -> *). MonadMPD m => m (Maybe Song)
MPD.currentSong)
Maybe Status
status <- IO (Maybe Status) -> EventM Name (Maybe Status)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (Maybe Status -> Either MPDError (Maybe Status) -> Maybe Status
forall b a. b -> Either a b -> b
fromRight Maybe Status
forall a. Maybe a
Nothing (Either MPDError (Maybe Status) -> Maybe Status)
-> IO (Either MPDError (Maybe Status)) -> IO (Maybe Status)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Status -> Maybe Status
forall a. a -> Maybe a
Just (Status -> Maybe Status)
-> IO (Either MPDError Status)
-> IO (Either MPDError (Maybe Status))
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>> MPD Status -> IO (Either MPDError Status)
forall a. MPD a -> IO (Response a)
withMPD MPD Status
forall (m :: * -> *). MonadMPD m => m Status
MPD.status))
Vector Song
queueVec <- IO (Vector Song) -> EventM Name (Vector Song)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
([Song] -> Vector Song
forall a. [a] -> Vector a
V.fromList ([Song] -> Vector Song)
-> (Either MPDError [Song] -> [Song])
-> Either MPDError [Song]
-> Vector Song
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Song] -> Either MPDError [Song] -> [Song]
forall b a. b -> Either a b -> b
fromRight [] (Either MPDError [Song] -> Vector Song)
-> IO (Either MPDError [Song]) -> IO (Vector Song)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MPD [Song] -> IO (Either MPDError [Song])
forall a. MPD a -> IO (Response a)
withMPD (Maybe Int -> MPD [Song]
forall (m :: * -> *). MonadMPD m => Maybe Int -> m [Song]
MPD.playlistInfo Maybe Int
forall a. Maybe a
Nothing))
let queueUnmoved :: SongList
queueUnmoved = (, Bool
False) (Song -> (Song, Bool)) -> GenericList Name Vector Song -> SongList
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Name -> Vector Song -> Int -> GenericList Name Vector Song
forall (t :: * -> *) n e.
Foldable t =>
n -> t e -> Int -> GenericList n t e
list Name
QueueList Vector Song
queueVec Int
1
let queueNew :: SongList
queueNew = case SongList -> Maybe Int
forall n (t :: * -> *) e. GenericList n t e -> Maybe Int
listSelected (HState -> SongList
queue HState
s) of
Maybe Int
Nothing -> SongList
queueUnmoved
Just Int
i -> Int -> SongList -> SongList
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
Int -> GenericList n t e -> GenericList n t e
listMoveTo Int
i SongList
queueUnmoved
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s { Maybe Song
currentSong :: Maybe Song
currentSong :: Maybe Song
currentSong, Maybe Status
status :: Maybe Status
status :: Maybe Status
status, queue :: SongList
queue = SongList
queueNew }
BrickEvent Name HumEvent
_ -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s