on develop help sign in
Move example to src-bin; Clean up cabal file
commita3abdfbd7ccd7f1dbc1b596a991a9200b5af54ac authorAli Abrar <aliabrar@gmail.com> dateMon 26 Feb 2018, 22:47 (9 years ago) parent5ede619
4 files changed+74−32
LICENSE+30 reflex-vty.cabal+16−12 src-bin/example.hs+28 src/Reflex/Vty.hs−20
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−
41name: reflex-vty
52version: 0.1.0.0
6−-- synopsis:
7−-- description:
3+synopsis: Reflex FRP host for vty applications
4+description: Host library for Reflex-based FRP applications
85license: BSD3
96license-file: LICENSE
10−author: Ali Abrar
11−maintainer: aliabrar@gmail.com
12−-- copyright:
13−-- category:
7+author: Obsidian Systems LLC
8+maintainer: maintainer@obsidian.systems
9+category: FRP
1410build-type: Simple
15−extra-source-files: ChangeLog.md
1611cabal-version: >=1.10
1712
1813library
1914 exposed-modules: Reflex.Vty
20− -- other-modules:
21− -- other-extensions:
2215 build-depends:
2316 base,
2417 dependent-sum,
@@ -31,3 +24,14 @@ library
3124 vty
3225 hs-source-dirs: src
3326 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 ((:=>)))
1919import Data.IORef (IORef)
2020import Data.IORef (readIORef)
2121import Data.Maybe (catMaybes)
22−import Data.Time (getCurrentTime)
2322
2423import Reflex
2524import Reflex.Host.Class
@@ -63,7 +62,6 @@ host vtyGuest = runSpiderHost $ do
6362
6463 let updateVty = sample (_vtyResult_picture r) >>= liftIO . V.update vty
6564
66−
6765 mPostBuildTrigger <- readRef pbTriggerRef
6866 forM_ mPostBuildTrigger $ \postBuildTrigger ->
6967 fire [postBuildTrigger :=> Identity ()] $ return ()
@@ -90,21 +88,6 @@ host vtyGuest = runSpiderHost $ do
9088 updateVty
9189 loop
9290
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−
10891-- TODO Some part of this is probably general enough to belong in reflex
10992fireEventTriggerRefs
11093 :: (Monad (ReadPhase m), MonadIO m)
@@ -120,6 +103,3 @@ fireEventTriggerRefs (FireCommand fire) ers rcb = do
120103 a <- fire es rcb
121104 liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
122105 return a
123−
124−main :: IO ()
125−main = host guest