Skip to content

Commit 8b06dc3

Browse files
committed
Working with Eve
1 parent 6557fd0 commit 8b06dc3

File tree

13 files changed

+19
-85
lines changed

13 files changed

+19
-85
lines changed

rasa-example-config/rasa-example-config.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ executable rasa
2828
, data-default
2929
, yi-rope
3030
, mtl
31-
, reflex
31+
, eve
3232
default-language: Haskell2010
3333
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
3434

rasa-ext-views/src/Rasa/Ext/Views/Internal/Actions.hs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import Rasa.Ext.Views.Internal.BiTree
2323

2424
import Control.Lens
2525
import Control.Monad
26-
import Control.Monad.State
2726
import Data.Maybe
2827
import Data.List
2928

rasa/rasa.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ library
6464

6565
ghc-options: -Wall
6666
build-depends: base >= 4.8 && < 5
67-
, reflex
67+
, eve
6868
, async
6969
, bifunctors
7070
, profunctors

rasa/src/Rasa.hs

+2-32
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
{-# language ExistentialQuantification, Rank2Types, ScopedTypeVariables #-}
22
module Rasa (rasa) where
33

4-
import Reflex
4+
import Eve
55
import Rasa.Internal.Listeners
66

77
import Control.Monad
8-
import Control.Monad.IO.Class
9-
import Data.Maybe
10-
11-
import Pipes
12-
import Pipes.Concurrent
13-
import Pipes.Parse
148

159
-- | The main function to run rasa.
1610
--
@@ -25,32 +19,8 @@ import Pipes.Parse
2519
-- > slate
2620

2721
rasa :: App () -> IO ()
28-
rasa initialization = void $ reflex (initialization >> hooks)
22+
rasa initialization = void $ eve (initialization >> hooks)
2923
where hooks = beforeEvent_ $ do
3024
dispatchBeforeRender
3125
dispatchOnRender
3226
dispatchAfterRender
33-
34-
-- rasa :: Action () -> IO ()
35-
-- rasa initialize = do
36-
-- (output, input) <- spawn unbounded
37-
-- evalAction (mkActionState output) $ do
38-
-- initialize
39-
-- dispatchInit
40-
-- dispatchAfterInit
41-
-- eventLoop $ fromInput input
42-
-- dispatchExit
43-
44-
-- -- | This is the main event loop, it runs recursively forever until something
45-
-- -- sets 'Rasa.Editor.exiting'. It runs the pre-event listeners, then checks if any
46-
-- -- async events have finished, then runs the post event listeners and repeats.
47-
-- eventLoop :: Producer (Action ()) IO () -> Action ()
48-
-- eventLoop producer = do
49-
-- dispatchBeforeRender
50-
-- dispatchOnRender
51-
-- dispatchAfterRender
52-
-- dispatchBeforeEvent
53-
-- (mAction, nextProducer) <- liftIO $ runStateT draw producer
54-
-- fromMaybe (return ()) mAction
55-
-- isExiting <- shouldExit
56-
-- unless isExiting $ eventLoop nextProducer

rasa/src/Rasa/Ext.hs

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ module Rasa.Ext
157157
, RenderInfo(..)
158158
, Renderable(..)
159159

160-
, module Reflex
160+
, module Eve
161161
) where
162162

163-
import Reflex
163+
import Eve
164164
import Rasa.Internal.BufActions
165165
import Rasa.Internal.Buffer
166166
import Rasa.Internal.Events

rasa/src/Rasa/Internal/BufActions.hs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# language OverloadedStrings #-}
2+
{-# language RankNTypes #-}
23
module Rasa.Internal.BufActions
34
( overRange
45
, replaceRange
@@ -46,17 +47,15 @@ module Rasa.Internal.BufActions
4647

4748
) where
4849

49-
import Reflex
50+
import Eve
5051

5152
import Rasa.Internal.Buffer
5253
import Rasa.Internal.Range
5354
import Rasa.Internal.Text
5455
import Rasa.Internal.Events
55-
import Rasa.Internal.Listeners
5656

5757
import Control.Lens
5858
import Control.Monad
59-
import Control.Monad.State
6059
import Data.Maybe
6160
import Data.Default
6261
import Data.Typeable
@@ -151,18 +150,11 @@ getBuffer (BufRef bufInd) =
151150
--
152151
-- Result list is not guaranteed to be the same length or positioning as input BufRef list; some buffers may no
153152
-- longer exist.
154-
-- TODO!!!
155153
bufferDo :: [BufRef] -> BufAction r -> App [r]
156154
bufferDo bufRefs bufAct = do
157-
results <- forM bufRefs $ \(BufRef bInd) -> do
158-
zoomer (buffers.at bInd._Just) ((:[]) <$> bufAct)
159-
return . concat $ results
160-
161-
zoomer l act = do
162-
s <- get
163-
(r, s) <- get >>= runStateT (zoom l act)
164-
put s
165-
return r
155+
r <- forM bufRefs $ \(BufRef bInd) ->
156+
runAction (buffers.at bInd._Just) ((:[]) <$> bufAct)
157+
return $ concat r
166158

167159
-- | This lifts a 'Rasa.App.BufAction' to an 'Rasa.App.App' which
168160
-- performs the 'Rasa.App.BufAction' on every buffer and collects the return

rasa/src/Rasa/Internal/Buffer.hs

+2-4
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@ module Rasa.Internal.Buffer
2424
) where
2525

2626

27-
import Reflex
27+
import Eve
2828

2929
import qualified Yi.Rope as Y
3030
import Control.Lens hiding (matching)
31-
import Control.Monad.State
3231
import qualified Data.Map as M
3332
import qualified Data.IntMap as IM
34-
import Data.Maybe
3533
import Data.List
3634
import Data.Default
3735

@@ -83,7 +81,7 @@ instance Show Buffer where
8381
where
8482
extText = intercalate "\n" $ show <$> b^.exts.to M.toList
8583

86-
type BufAction a = StateT Buffer App a
84+
type BufAction a = Action Buffer a
8785

8886
newtype Buffers = Buffers
8987
{ _buffers' :: IM.IntMap Buffer

rasa/src/Rasa/Internal/Events.hs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{-# language ExistentialQuantification #-}
22
module Rasa.Internal.Events
3-
( Init(..)
4-
, AfterInit(..)
5-
, BeforeEvent(..)
6-
, BeforeRender(..)
3+
( BeforeRender(..)
74
, OnRender(..)
85
, AfterRender(..)
9-
, Exit(..)
106
, BufAdded(..)
117
, Keypress(..)
128
, Mod(..)
@@ -18,16 +14,6 @@ import Rasa.Internal.Range
1814
import Rasa.Internal.Buffer
1915
import qualified Yi.Rope as Y
2016

21-
-- | This event is dispatched exactly once when the editor starts up.
22-
data Init = Init deriving (Show, Eq, Typeable)
23-
24-
-- | This event is dispatched exactly once when the editor starts up after onInit has occurred.
25-
data AfterInit = AfterInit deriving (Show, Eq, Typeable)
26-
27-
-- | This event is dispatched immediately before dispatching any events from
28-
-- asyncronous event listeners (like 'Keypress's)
29-
data BeforeEvent = BeforeEvent deriving (Show, Eq, Typeable)
30-
3117
-- | This event is dispatched immediately before dispatching
3218
-- the 'OnRender' event.
3319
data BeforeRender = BeforeRender deriving (Show, Eq, Typeable)
@@ -38,10 +24,6 @@ data OnRender = OnRender deriving (Show, Eq, Typeable)
3824
-- | This event is dispatched immediately after dispatching 'OnRender'.
3925
data AfterRender = AfterRender deriving (Show, Eq, Typeable)
4026

41-
-- | This event is dispatched before exiting the editor, listen for this to do
42-
-- any clean-up (saving files, etc.)
43-
data Exit = Exit deriving (Show, Eq, Typeable)
44-
4527
-- | This event is dispatched after adding a new buffer. The contained BufRef refers to the new buffer.
4628
data BufAdded = BufAdded BufRef deriving (Show, Eq, Typeable)
4729

rasa/src/Rasa/Internal/Listeners.hs

+1-8
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,10 @@ module Rasa.Internal.Listeners
2424
, dispatchKeypress
2525
) where
2626

27-
import Reflex
28-
import Rasa.Internal.Buffer
27+
import Eve
2928
import Rasa.Internal.Events
3029

31-
import Control.Lens
3230
import Control.Monad
33-
import Control.Monad.State
34-
import Data.Default
35-
import Data.Typeable
36-
import Data.Maybe
37-
import qualified Data.Map as M
3831

3932
-- | Trigger an 'App' on a 'Keypress'
4033
onKeypress :: (Keypress -> App result) -> App ListenerId

rasa/src/Rasa/Internal/Styles.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Rasa.Internal.Styles
1313
, getStyles
1414
) where
1515

16-
import Reflex
16+
import Eve
1717
import Rasa.Internal.Range
1818
import Rasa.Internal.Buffer
1919
import Rasa.Internal.BufActions

rasa/src/Rasa/Internal/Utility.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Rasa.Internal.Utility
1111
, styleText
1212
) where
1313

14-
import Reflex
14+
import Eve
1515
import Rasa.Internal.Styles
1616
import Rasa.Internal.BufActions
1717
import Rasa.Internal.Buffer

rasa/src/Rasa/Testing.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module Rasa.Testing (
22
-- testBufAction
33
) where
44

5-
-- import Reflex
5+
-- import Eve
66
-- import Rasa.Internal.Interpreters
77
-- import Rasa.Internal.Buffer
88

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ packages:
1818
- ./rasa-ext-vim
1919
- ./rasa-example-config
2020
- ./text-lens
21-
- ../reflex
2221

2322
extra-deps:
23+
- eve-0.1.0
2424
- vty-5.14
2525
- recursion-schemes-5.0.1
2626

0 commit comments

Comments
 (0)