on develop help sign in
Move example to src-bin; Clean up cabal file
a3abdfbAli Abrar
LICENSEnew file+30
@@ -0,0 +1,30 @@
1+Copyright (c) 2018, Ali Abrar
2+
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions are met:
7+
8+ * Redistributions of source code must retain the above copyright
9+ notice, this list of conditions and the following disclaimer.
10+
11+ * Redistributions in binary form must reproduce the above
12+ copyright notice, this list of conditions and the following
13+ disclaimer in the documentation and/or other materials provided
14+ with the distribution.
15+
16+ * Neither the name of Ali Abrar nor the names of other
17+ contributors may be used to endorse or promote products derived
18+ from this software without specific prior written permission.
19+
20+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
reflex-vty.cabal+16−12
@@ -1,24 +1,17 @@
1−-- Initial reflex-vty.cabal generated by cabal init. For further
2−-- documentation, see http: //haskell.org/cabal/users-guide/
3−
4name: reflex-vty
1name: reflex-vty
5version: 0.1.0.0
2version: 0.1.0.0
6−-- synopsis:
3+synopsis: Reflex FRP host for vty applications
7−-- description:
4+description: Host library for Reflex-based FRP applications
8license: BSD3
5license: BSD3
9license-file: LICENSE
6license-file: LICENSE
10−author: Ali Abrar
7+author: Obsidian Systems LLC
11−maintainer: aliabrar@gmail.com
8+maintainer: maintainer@obsidian.systems
12−-- copyright:
13−-- category:
9+category: FRP
14build-type: Simple
10build-type: Simple
15−extra-source-files: ChangeLog.md
16cabal-version: >=1.10
11cabal-version: >=1.10
17
12
18library
13library
19 exposed-modules: Reflex.Vty
14 exposed-modules: Reflex.Vty
20− -- other-modules:
21− -- other-extensions:
22 build-depends:
15 build-depends:
23 base,
16 base,
24 dependent-sum,
17 dependent-sum,
@@ -31,3 +24,14 @@ library
31 vty
24 vty
32 hs-source-dirs: src
25 hs-source-dirs: src
33 default-language: Haskell2010
26 default-language: Haskell2010
27+
28+executable example
29+ hs-source-dirs: src-bin
30+ main-is: example.hs
31+ build-depends:
32+ base,
33+ reflex,
34+ reflex-vty,
35+ time,
36+ vty
37+ default-language: Haskell2010
src-bin/example.hsnew file+28
@@ -0,0 +1,28 @@
1+{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE GADTs #-}
3+{-# LANGUAGE LambdaCase #-}
4+{-# LANGUAGE RankNTypes #-}
5+
6+import Control.Monad.IO.Class
7+import Data.Time
8+import qualified Graphics.Vty as V
9+import Reflex
10+import Reflex.Vty
11+
12+guest :: forall t m. VtyApp t m
13+guest e = do
14+ now <- liftIO getCurrentTime
15+ ticks <- fmap show <$> tickLossy 1 now
16+ let shutdown = fforMaybe e $ \case
17+ V.EvKey V.KEsc _ -> Just ()
18+ _ -> Nothing
19+ picture <- hold (V.picForImage $ V.string mempty "Initial") $ V.picForImage . V.string mempty <$>
20+ leftmost [show <$> e, show <$> ticks]
21+ return $ VtyResult
22+ { _vtyResult_picture = picture
23+ , _vtyResult_refresh = never
24+ , _vtyResult_shutdown = shutdown
25+ }
26+
27+main :: IO ()
28+main = host guest
src/Reflex/Vty.hs−20
@@ -19,7 +19,6 @@ import Data.Dependent.Sum (DSum ((:=>)))
19import Data.IORef (IORef)
19import Data.IORef (IORef)
20import Data.IORef (readIORef)
20import Data.IORef (readIORef)
21import Data.Maybe (catMaybes)
21import Data.Maybe (catMaybes)
22−import Data.Time (getCurrentTime)
23
22
24import Reflex
23import Reflex
25import Reflex.Host.Class
24import Reflex.Host.Class
@@ -63,7 +62,6 @@ host vtyGuest = runSpiderHost $ do
63
62
64 let updateVty = sample (_vtyResult_picture r) >>= liftIO . V.update vty
63 let updateVty = sample (_vtyResult_picture r) >>= liftIO . V.update vty
65
64
66−
67 mPostBuildTrigger <- readRef pbTriggerRef
65 mPostBuildTrigger <- readRef pbTriggerRef
68 forM_ mPostBuildTrigger $ \postBuildTrigger ->
66 forM_ mPostBuildTrigger $ \postBuildTrigger ->
69 fire [postBuildTrigger :=> Identity ()] $ return ()
67 fire [postBuildTrigger :=> Identity ()] $ return ()
@@ -90,21 +88,6 @@ host vtyGuest = runSpiderHost $ do
90 updateVty
88 updateVty
91 loop
89 loop
92
90
93−guest :: forall t m. VtyApp t m
94−guest e = do
95− now <- liftIO getCurrentTime
96− ticks <- fmap show <$> tickLossy 1 now
97− let shutdown = fforMaybe e $ \case
98− V.EvKey V.KEsc _ -> Just ()
99− _ -> Nothing
100− picture <- hold (V.picForImage $ V.string mempty "Initial") $ V.picForImage . V.string mempty <$>
101− leftmost [show <$> e, show <$> ticks]
102− return $ VtyResult
103− { _vtyResult_picture = picture
104− , _vtyResult_refresh = never
105− , _vtyResult_shutdown = shutdown
106− }
107−
108-- TODO Some part of this is probably general enough to belong in reflex
91-- TODO Some part of this is probably general enough to belong in reflex
109fireEventTriggerRefs
92fireEventTriggerRefs
110 :: (Monad (ReadPhase m), MonadIO m)
93 :: (Monad (ReadPhase m), MonadIO m)
@@ -120,6 +103,3 @@ fireEventTriggerRefs (FireCommand fire) ers rcb = do
120 a <- fire es rcb
103 a <- fire es rcb
121 liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
104 liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
122 return a
105 return a
123−
124−main :: IO ()
125−main = host guest