module Hum.Modes.PromptMode where
import Brick.Widgets.Edit hiding ( decodeUtf8 )
import Brick.Types
import Brick.Main
import Hum.Types
import Hum.Utils
import Graphics.Vty.Input.Events
import qualified Data.Text.Zipper as Z
hiding ( textZipper )
import Control.Lens
import qualified Network.MPD as MPD
import qualified Data.Vector as V
import Brick.Widgets.List
handlePromptEvent
:: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePromptEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePromptEvent HState
s BrickEvent Name HumEvent
e = case HState
s 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 of
PromptType
PlSelectPrompt -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePlSelectPromptEvent HState
s BrickEvent Name HumEvent
e
PromptType
TextPrompt -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleTextPromptEvent HState
s BrickEvent Name HumEvent
e
PromptType
YNPrompt -> HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleYNPromptEvent HState
s BrickEvent Name HumEvent
e
handlePlSelectPromptEvent
:: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePlSelectPromptEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handlePlSelectPromptEvent HState
s BrickEvent Name HumEvent
e = case BrickEvent Name HumEvent
e of
VtyEvent Event
vtye -> case Event
vtye of
EvKey Key
KEsc [] -> 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
NormalMode
EvKey (KChar Char
'q') [] -> 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
NormalMode
EvKey (KChar Char
'j') [] -> do
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
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> Prompts -> Identity Prompts)
-> (List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> Prompts -> Identity Prompts
Lens' Prompts (List Name (Maybe PlaylistName))
plSelectPromptL ((List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> HState -> Identity HState)
-> (List Name (Maybe PlaylistName)
-> List Name (Maybe PlaylistName))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ List Name (Maybe PlaylistName) -> List Name (Maybe PlaylistName)
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveDown
EvKey (KChar Char
'k') [] -> do
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
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> Prompts -> Identity Prompts)
-> (List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> Prompts -> Identity Prompts
Lens' Prompts (List Name (Maybe PlaylistName))
plSelectPromptL ((List Name (Maybe PlaylistName)
-> Identity (List Name (Maybe PlaylistName)))
-> HState -> Identity HState)
-> (List Name (Maybe PlaylistName)
-> List Name (Maybe PlaylistName))
-> HState
-> HState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ List Name (Maybe PlaylistName) -> List Name (Maybe PlaylistName)
forall (t :: * -> *) n e.
(Foldable t, Splittable t) =>
GenericList n t e -> GenericList n t e
listMoveUp
EvKey (KChar Char
'l') [] -> do
let songs :: Vector Song
songs = HState
s HState -> Getting SongList HState SongList -> SongList
forall s a. s -> Getting a s a -> a
^. Getting SongList HState SongList
Lens' HState SongList
queueL SongList -> (SongList -> SongList) -> SongList
forall a b. a -> (a -> b) -> b
& SongList -> SongList
forall e (t :: * -> *) n.
(Eq e, Filterable t, Foldable t, Splittable t) =>
GenericList n t (e, Highlight) -> GenericList n t (e, Highlight)
getHighlighted SongList
-> ((Song, Highlight) -> Song) -> GenericList Name Vector Song
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Song, Highlight) -> Song
forall a b. (a, b) -> a
fst GenericList Name Vector Song
-> (GenericList Name Vector Song -> Vector Song) -> Vector Song
forall a b. a -> (a -> b) -> b
& GenericList Name Vector Song -> Vector Song
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements
case HState
s HState
-> Getting
(List Name (Maybe PlaylistName))
HState
(List Name (Maybe PlaylistName))
-> List Name (Maybe PlaylistName)
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> HState -> Const (List Name (Maybe PlaylistName)) HState
Lens' HState Prompts
promptsL ((Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> HState -> Const (List Name (Maybe PlaylistName)) HState)
-> ((List Name (Maybe PlaylistName)
-> Const
(List Name (Maybe PlaylistName)) (List Name (Maybe PlaylistName)))
-> Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> Getting
(List Name (Maybe PlaylistName))
HState
(List Name (Maybe PlaylistName))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name (Maybe PlaylistName)
-> Const
(List Name (Maybe PlaylistName)) (List Name (Maybe PlaylistName)))
-> Prompts -> Const (List Name (Maybe PlaylistName)) Prompts
Lens' Prompts (List Name (Maybe PlaylistName))
plSelectPromptL List Name (Maybe PlaylistName)
-> (List Name (Maybe PlaylistName)
-> Maybe (Int, Maybe PlaylistName))
-> Maybe (Int, Maybe PlaylistName)
forall a b. a -> (a -> b) -> b
& List Name (Maybe PlaylistName) -> Maybe (Int, Maybe PlaylistName)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement Maybe (Int, Maybe PlaylistName)
-> ((Int, Maybe PlaylistName) -> Maybe PlaylistName)
-> Maybe (Maybe PlaylistName)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Int, Maybe PlaylistName) -> Maybe PlaylistName
forall a b. (a, b) -> b
snd Maybe (Maybe PlaylistName)
-> (Maybe (Maybe PlaylistName) -> Maybe PlaylistName)
-> Maybe PlaylistName
forall a b. a -> (a -> b) -> b
& Maybe (Maybe PlaylistName) -> Maybe PlaylistName
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join of
Maybe PlaylistName
Nothing -> 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
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((PromptType -> Identity PromptType)
-> Prompts -> Identity Prompts)
-> (PromptType -> Identity PromptType)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PromptType -> Identity PromptType) -> Prompts -> Identity Prompts
Lens' Prompts PromptType
currentPromptL ((PromptType -> Identity PromptType) -> HState -> Identity HState)
-> PromptType -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PromptType
TextPrompt
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> (((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts)
-> ((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL (((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> HState -> Identity HState)
-> (HState -> EventM Name HState) -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Vector Song -> HState -> EventM Name HState
forall n. Vector Song -> HState -> EventM n HState
songBulkAddtoNewPl Vector Song
songs
Just PlaylistName
plname -> 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
=<< String -> Vector Song -> HState -> EventM Name HState
forall n. String -> Vector Song -> HState -> EventM n HState
songBulkAddtoPl (PlaylistName -> String
forall a. ToString a => a -> String
MPD.toString PlaylistName
plname) Vector Song
songs HState
s
EvKey Key
KEnter [] -> do
let songs :: Vector Song
songs = HState
s HState -> Getting SongList HState SongList -> SongList
forall s a. s -> Getting a s a -> a
^. Getting SongList HState SongList
Lens' HState SongList
queueL SongList -> (SongList -> SongList) -> SongList
forall a b. a -> (a -> b) -> b
& SongList -> SongList
forall e (t :: * -> *) n.
(Eq e, Filterable t, Foldable t, Splittable t) =>
GenericList n t (e, Highlight) -> GenericList n t (e, Highlight)
getHighlighted SongList
-> ((Song, Highlight) -> Song) -> GenericList Name Vector Song
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Song, Highlight) -> Song
forall a b. (a, b) -> a
fst GenericList Name Vector Song
-> (GenericList Name Vector Song -> Vector Song) -> Vector Song
forall a b. a -> (a -> b) -> b
& GenericList Name Vector Song -> Vector Song
forall n (t :: * -> *) e. GenericList n t e -> t e
listElements
case HState
s HState
-> Getting
(List Name (Maybe PlaylistName))
HState
(List Name (Maybe PlaylistName))
-> List Name (Maybe PlaylistName)
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> HState -> Const (List Name (Maybe PlaylistName)) HState
Lens' HState Prompts
promptsL ((Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> HState -> Const (List Name (Maybe PlaylistName)) HState)
-> ((List Name (Maybe PlaylistName)
-> Const
(List Name (Maybe PlaylistName)) (List Name (Maybe PlaylistName)))
-> Prompts -> Const (List Name (Maybe PlaylistName)) Prompts)
-> Getting
(List Name (Maybe PlaylistName))
HState
(List Name (Maybe PlaylistName))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name (Maybe PlaylistName)
-> Const
(List Name (Maybe PlaylistName)) (List Name (Maybe PlaylistName)))
-> Prompts -> Const (List Name (Maybe PlaylistName)) Prompts
Lens' Prompts (List Name (Maybe PlaylistName))
plSelectPromptL List Name (Maybe PlaylistName)
-> (List Name (Maybe PlaylistName)
-> Maybe (Int, Maybe PlaylistName))
-> Maybe (Int, Maybe PlaylistName)
forall a b. a -> (a -> b) -> b
& List Name (Maybe PlaylistName) -> Maybe (Int, Maybe PlaylistName)
forall (t :: * -> *) n e.
(Splittable t, Foldable t) =>
GenericList n t e -> Maybe (Int, e)
listSelectedElement Maybe (Int, Maybe PlaylistName)
-> ((Int, Maybe PlaylistName) -> Maybe PlaylistName)
-> Maybe (Maybe PlaylistName)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> (Int, Maybe PlaylistName) -> Maybe PlaylistName
forall a b. (a, b) -> b
snd Maybe (Maybe PlaylistName)
-> (Maybe (Maybe PlaylistName) -> Maybe PlaylistName)
-> Maybe PlaylistName
forall a b. a -> (a -> b) -> b
& Maybe (Maybe PlaylistName) -> Maybe PlaylistName
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join of
Maybe PlaylistName
Nothing -> 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
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> ((PromptType -> Identity PromptType)
-> Prompts -> Identity Prompts)
-> (PromptType -> Identity PromptType)
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PromptType -> Identity PromptType) -> Prompts -> Identity Prompts
Lens' Prompts PromptType
currentPromptL ((PromptType -> Identity PromptType) -> HState -> Identity HState)
-> PromptType -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ PromptType
TextPrompt
HState -> (HState -> HState) -> HState
forall a b. a -> (a -> b) -> b
& (Prompts -> Identity Prompts) -> HState -> Identity HState
Lens' HState Prompts
promptsL ((Prompts -> Identity Prompts) -> HState -> Identity HState)
-> (((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts)
-> ((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> HState
-> Identity HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> Prompts -> Identity Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL (((HState -> EventM Name HState)
-> Identity (HState -> EventM Name HState))
-> HState -> Identity HState)
-> (HState -> EventM Name HState) -> HState -> HState
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Vector Song -> HState -> EventM Name HState
forall n. Vector Song -> HState -> EventM n HState
songBulkAddtoNewPl Vector Song
songs
Just PlaylistName
plname -> 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
=<< String -> Vector Song -> HState -> EventM Name HState
forall n. String -> Vector Song -> HState -> EventM n HState
songBulkAddtoPl (PlaylistName -> String
forall a. ToString a => a -> String
MPD.toString PlaylistName
plname) Vector Song
songs 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
songBulkAddtoNewPl :: V.Vector MPD.Song -> HState -> EventM n HState
songBulkAddtoNewPl :: Vector Song -> HState -> EventM n HState
songBulkAddtoNewPl Vector Song
songs HState
st = String -> Vector Song -> HState -> EventM n HState
forall n. String -> Vector Song -> HState -> EventM n HState
songBulkAddtoPl
(Text -> String
forall a. ToString a => a -> String
toString (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ HState
st HState
-> Getting (TextZipper Text) HState (TextZipper Text)
-> TextZipper Text
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const (TextZipper Text) Prompts)
-> HState -> Const (TextZipper Text) HState
Lens' HState Prompts
promptsL ((Prompts -> Const (TextZipper Text) Prompts)
-> HState -> Const (TextZipper Text) HState)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Prompts -> Const (TextZipper Text) Prompts)
-> Getting (TextZipper Text) HState (TextZipper Text)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> Prompts -> Const (TextZipper Text) Prompts
Lens' Prompts (Editor Text Name)
textPromptL ((Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> Prompts -> Const (TextZipper Text) Prompts)
-> ((TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name))
-> (TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Prompts
-> Const (TextZipper Text) Prompts
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TextZipper Text -> Const (TextZipper Text) (TextZipper Text))
-> Editor Text Name -> Const (TextZipper Text) (Editor Text Name)
forall t1 n t2.
Lens (Editor t1 n) (Editor t2 n) (TextZipper t1) (TextZipper t2)
editContentsL TextZipper Text -> (TextZipper Text -> Text) -> Text
forall a b. a -> (a -> b) -> b
& TextZipper Text -> Text
forall a. Monoid a => TextZipper a -> a
Z.currentLine)
Vector Song
songs
HState
st
handleTextPromptEvent
:: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleTextPromptEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleTextPromptEvent HState
s BrickEvent Name HumEvent
e = case BrickEvent Name HumEvent
e of
VtyEvent (EvKey Key
KEsc []) -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (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)
VtyEvent (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
=<< (HState
s HState
-> Getting
(HState -> EventM Name HState)
HState
(HState -> EventM Name HState)
-> HState
-> EventM Name HState
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const (HState -> EventM Name HState) Prompts)
-> HState -> Const (HState -> EventM Name HState) HState
Lens' HState Prompts
promptsL ((Prompts -> Const (HState -> EventM Name HState) Prompts)
-> HState -> Const (HState -> EventM Name HState) HState)
-> (((HState -> EventM Name HState)
-> Const
(HState -> EventM Name HState) (HState -> EventM Name HState))
-> Prompts -> Const (HState -> EventM Name HState) Prompts)
-> Getting
(HState -> EventM Name HState)
HState
(HState -> EventM Name HState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
-> Const
(HState -> EventM Name HState) (HState -> EventM Name HState))
-> Prompts -> Const (HState -> EventM Name HState) Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL) (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)
VtyEvent Event
vtye ->
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue
(HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< HState
-> Lens' HState (Editor Text Name)
-> (Event -> Editor Text Name -> EventM Name (Editor Text Name))
-> Event
-> EventM Name HState
forall a b e n.
a -> Lens' a b -> (e -> b -> EventM n b) -> e -> EventM n a
handleEventLensed HState
s ((Prompts -> f Prompts) -> HState -> f HState
Lens' HState Prompts
promptsL ((Prompts -> f Prompts) -> HState -> f HState)
-> ((Editor Text Name -> f (Editor Text Name))
-> Prompts -> f Prompts)
-> (Editor Text Name -> f (Editor Text Name))
-> HState
-> f HState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Editor Text Name -> f (Editor Text Name)) -> Prompts -> f Prompts
Lens' Prompts (Editor Text Name)
textPromptL) Event -> Editor Text Name -> EventM Name (Editor Text Name)
forall t n.
(DecodeUtf8 t, Eq t, Monoid t) =>
Event -> Editor t n -> EventM n (Editor t n)
handleEditorEvent Event
vtye
BrickEvent Name HumEvent
_ -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s
handleYNPromptEvent
:: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleYNPromptEvent :: HState -> BrickEvent Name HumEvent -> EventM Name (Next HState)
handleYNPromptEvent HState
s BrickEvent Name HumEvent
e = case BrickEvent Name HumEvent
e of
VtyEvent (EvKey Key
KEsc []) -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (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)
VtyEvent (EvKey (KChar Char
'y') []) ->
HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (HState -> EventM Name (Next HState))
-> EventM Name HState -> EventM Name (Next HState)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (HState
s HState
-> Getting
(HState -> EventM Name HState)
HState
(HState -> EventM Name HState)
-> HState
-> EventM Name HState
forall s a. s -> Getting a s a -> a
^. (Prompts -> Const (HState -> EventM Name HState) Prompts)
-> HState -> Const (HState -> EventM Name HState) HState
Lens' HState Prompts
promptsL ((Prompts -> Const (HState -> EventM Name HState) Prompts)
-> HState -> Const (HState -> EventM Name HState) HState)
-> (((HState -> EventM Name HState)
-> Const
(HState -> EventM Name HState) (HState -> EventM Name HState))
-> Prompts -> Const (HState -> EventM Name HState) Prompts)
-> Getting
(HState -> EventM Name HState)
HState
(HState -> EventM Name HState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((HState -> EventM Name HState)
-> Const
(HState -> EventM Name HState) (HState -> EventM Name HState))
-> Prompts -> Const (HState -> EventM Name HState) Prompts
Lens' Prompts (HState -> EventM Name HState)
exitPromptL) (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)
VtyEvent (EvKey (KChar Char
'n') []) -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (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)
VtyEvent (EvKey (KChar Char
'q') []) -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue (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)
BrickEvent Name HumEvent
_ -> HState -> EventM Name (Next HState)
forall s n. s -> EventM n (Next s)
continue HState
s