{-# options_haddock prune #-}
module Helic.App where
import qualified Conc
import Conc (interpretAtomic, interpretEventsChan, interpretSync, withAsync_)
import Polysemy.Http (Manager)
import Polysemy.Http.Interpreter.Manager (interpretManager)
import Helic.Data.Config (Config (Config))
import Helic.Data.Event (Event)
import Helic.Data.ListConfig (ListConfig)
import Helic.Data.LoadConfig (LoadConfig (LoadConfig))
import Helic.Data.NetConfig (NetConfig)
import Helic.Data.YankConfig (YankConfig)
import qualified Helic.Effect.Client as Client
import Helic.Effect.Client (Client)
import qualified Helic.Effect.History as History
import Helic.Interpreter.AgentNet (interpretAgentNetIfEnabled)
import Helic.Interpreter.AgentTmux (interpretAgentTmuxIfEnabled)
import Helic.Interpreter.AgentX (interpretX)
import Helic.Interpreter.Client (interpretClientNet)
import Helic.Interpreter.History (interpretHistory)
import Helic.Interpreter.InstanceName (interpretInstanceName)
import Helic.List (list)
import Helic.Net.Api (serve)
import Helic.Yank (yank)
listenApp ::
Config ->
Sem AppStack ()
listenApp :: Config -> Sem AppStack ()
listenApp (Config Maybe Text
name Maybe TmuxConfig
tmux Maybe NetConfig
net Maybe X11Config
x11 Maybe Int
maxHistory Maybe Bool
_) =
forall i (r :: EffectRow) a. i -> Sem (Reader i : r) a -> Sem r a
runReader (forall a. a -> Maybe a -> a
fromMaybe forall a. Default a => a
def Maybe NetConfig
net) forall a b. (a -> b) -> a -> b
$
forall i (r :: EffectRow) a. i -> Sem (Reader i : r) a -> Sem r a
runReader (forall a. a -> Maybe a -> a
fromMaybe forall a. Default a => a
def Maybe X11Config
x11) forall a b. (a -> b) -> a -> b
$
forall i (r :: EffectRow) a. i -> Sem (Reader i : r) a -> Sem r a
runReader (forall a. a -> Maybe a -> a
fromMaybe forall a. Default a => a
def Maybe TmuxConfig
tmux) forall a b. (a -> b) -> a -> b
$
forall e (r :: EffectRow).
Members '[Resource, Race, Async, Embed IO] r =>
InterpretersFor '[Events e, EventConsumer e] r
interpretEventsChan @Event forall a b. (a -> b) -> a -> b
$
forall a (r :: EffectRow).
Member (Embed IO) r =>
a -> InterpreterFor (AtomicState a) r
interpretAtomic forall a. Monoid a => a
mempty forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members '[Error Text, Embed IO] r =>
Maybe Text -> InterpreterFor (Reader InstanceName) r
interpretInstanceName Maybe Text
name forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Member (Embed IO) r =>
InterpreterFor Manager r
interpretManager forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
(Members '[Reader X11Config, Events Event, Reader InstanceName] r,
Members
'[ChronosTime, Log, Error Text, Race, Resource,
UninterruptibleMask, Async, Embed IO, Final IO]
r) =>
InterpreterFor (Agent @@ AgentX) r
interpretX forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
(Members '[Manager, Reader NetConfig] r,
Members
'[Log, Interrupt, Race, Resource, Async, Embed IO, Final IO] r) =>
InterpreterFor (Agent @@ AgentNet) r
interpretAgentNetIfEnabled forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members
'[Reader TmuxConfig, Log, Resource, Race, Async, Embed IO] r =>
InterpreterFor (Agent @@ AgentTmux) r
interpretAgentTmuxIfEnabled forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
(Members Agents r,
Members
'[Reader InstanceName, AtomicState (Seq Event), ChronosTime, Log]
r) =>
Maybe Int -> InterpreterFor History r
interpretHistory Maybe Int
maxHistory forall a b. (a -> b) -> a -> b
$
forall d (r :: EffectRow).
Members '[Race, Embed IO] r =>
InterpreterFor (Sync d) r
interpretSync forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow) b a.
Members '[Resource, Race, Async] r =>
Sem r b -> Sem r a -> Sem r a
withAsync_ forall (r :: EffectRow).
Members
'[History, Reader NetConfig, Sync ServerReady, Log, Interrupt,
Final IO]
r =>
Sem r ()
serve forall a b. (a -> b) -> a -> b
$
forall e (r :: EffectRow).
Member (EventConsumer e) r =>
(e -> Sem r ()) -> Sem r ()
Conc.subscribeLoop forall (r :: EffectRow). Member History r => Event -> Sem r ()
History.receive
runClient ::
Members [Log, Error Text, Race, Embed IO] r =>
Maybe NetConfig ->
InterpretersFor [Client, Reader NetConfig, Manager] r
runClient :: forall (r :: EffectRow).
Members '[Log, Error Text, Race, Embed IO] r =>
Maybe NetConfig
-> InterpretersFor '[Client, Reader NetConfig, Manager] r
runClient Maybe NetConfig
net =
forall (r :: EffectRow).
Member (Embed IO) r =>
InterpreterFor Manager r
interpretManager forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall i (r :: EffectRow) a. i -> Sem (Reader i : r) a -> Sem r a
runReader (forall a. a -> Maybe a -> a
fromMaybe forall a. Default a => a
def Maybe NetConfig
net) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (r :: EffectRow).
Members
'[Manager, Reader NetConfig, Log, Error Text, Race, Embed IO] r =>
InterpreterFor Client r
interpretClientNet
yankApp ::
Config ->
YankConfig ->
Sem AppStack ()
yankApp :: Config -> YankConfig -> Sem AppStack ()
yankApp (Config Maybe Text
name Maybe TmuxConfig
_ Maybe NetConfig
net Maybe X11Config
_ Maybe Int
_ Maybe Bool
_) YankConfig
yankConfig =
forall (r :: EffectRow).
Members '[Error Text, Embed IO] r =>
Maybe Text -> InterpreterFor (Reader InstanceName) r
interpretInstanceName Maybe Text
name forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members '[Log, Error Text, Race, Embed IO] r =>
Maybe NetConfig
-> InterpretersFor '[Client, Reader NetConfig, Manager] r
runClient Maybe NetConfig
net forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members
'[Reader InstanceName, Client, ChronosTime, Log, Error Text,
Embed IO]
r =>
YankConfig -> Sem r ()
yank YankConfig
yankConfig
listApp ::
Config ->
ListConfig ->
Sem AppStack ()
listApp :: Config -> ListConfig -> Sem AppStack ()
listApp (Config Maybe Text
_ Maybe TmuxConfig
_ Maybe NetConfig
net Maybe X11Config
_ Maybe Int
_ Maybe Bool
_) ListConfig
listConfig =
forall i (r :: EffectRow) a. i -> Sem (Reader i : r) a -> Sem r a
runReader ListConfig
listConfig forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members '[Log, Error Text, Race, Embed IO] r =>
Maybe NetConfig
-> InterpretersFor '[Client, Reader NetConfig, Manager] r
runClient Maybe NetConfig
net forall a b. (a -> b) -> a -> b
$
forall (r :: EffectRow).
Members '[Reader ListConfig, Client, Error Text, Embed IO] r =>
Sem r ()
list
loadApp ::
Config ->
LoadConfig ->
Sem AppStack ()
loadApp :: Config -> LoadConfig -> Sem AppStack ()
loadApp (Config Maybe Text
_ Maybe TmuxConfig
_ Maybe NetConfig
net Maybe X11Config
_ Maybe Int
_ Maybe Bool
_) (LoadConfig Int
event) =
forall (r :: EffectRow).
Members '[Log, Error Text, Race, Embed IO] r =>
Maybe NetConfig
-> InterpretersFor '[Client, Reader NetConfig, Manager] r
runClient Maybe NetConfig
net forall a b. (a -> b) -> a -> b
$
(forall (f :: * -> *) a. Functor f => f a -> f ()
void forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall e (r :: EffectRow) a.
Member (Error e) r =>
Either e a -> Sem r a
fromEither forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< forall (r :: EffectRow).
Member Client r =>
Int -> Sem r (Either Text Event)
Client.load Int
event)