Move example to src-bin; Clean up cabal file

This commit is contained in:
Ali Abrar 2018-02-26 22:47:07 -05:00
parent 5ede61939f
commit a3abdfbd7c
4 changed files with 74 additions and 32 deletions

30
LICENSE Normal file
View File

@ -0,0 +1,30 @@
Copyright (c) 2018, Ali Abrar
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Ali Abrar nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,24 +1,17 @@
-- Initial reflex-vty.cabal generated by cabal init. For further
-- documentation, see http: //haskell.org/cabal/users-guide/
name: reflex-vty
version: 0.1.0.0
-- synopsis:
-- description:
synopsis: Reflex FRP host for vty applications
description: Host library for Reflex-based FRP applications
license: BSD3
license-file: LICENSE
author: Ali Abrar
maintainer: aliabrar@gmail.com
-- copyright:
-- category:
author: Obsidian Systems LLC
maintainer: maintainer@obsidian.systems
category: FRP
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
exposed-modules: Reflex.Vty
-- other-modules:
-- other-extensions:
build-depends:
base,
dependent-sum,
@ -31,3 +24,14 @@ library
vty
hs-source-dirs: src
default-language: Haskell2010
executable example
hs-source-dirs: src-bin
main-is: example.hs
build-depends:
base,
reflex,
reflex-vty,
time,
vty
default-language: Haskell2010

28
src-bin/example.hs Normal file
View File

@ -0,0 +1,28 @@
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
import Control.Monad.IO.Class
import Data.Time
import qualified Graphics.Vty as V
import Reflex
import Reflex.Vty
guest :: forall t m. VtyApp t m
guest e = do
now <- liftIO getCurrentTime
ticks <- fmap show <$> tickLossy 1 now
let shutdown = fforMaybe e $ \case
V.EvKey V.KEsc _ -> Just ()
_ -> Nothing
picture <- hold (V.picForImage $ V.string mempty "Initial") $ V.picForImage . V.string mempty <$>
leftmost [show <$> e, show <$> ticks]
return $ VtyResult
{ _vtyResult_picture = picture
, _vtyResult_refresh = never
, _vtyResult_shutdown = shutdown
}
main :: IO ()
main = host guest

View File

@ -19,7 +19,6 @@ import Data.Dependent.Sum (DSum ((:=>)))
import Data.IORef (IORef)
import Data.IORef (readIORef)
import Data.Maybe (catMaybes)
import Data.Time (getCurrentTime)
import Reflex
import Reflex.Host.Class
@ -63,7 +62,6 @@ host vtyGuest = runSpiderHost $ do
let updateVty = sample (_vtyResult_picture r) >>= liftIO . V.update vty
mPostBuildTrigger <- readRef pbTriggerRef
forM_ mPostBuildTrigger $ \postBuildTrigger ->
fire [postBuildTrigger :=> Identity ()] $ return ()
@ -90,21 +88,6 @@ host vtyGuest = runSpiderHost $ do
updateVty
loop
guest :: forall t m. VtyApp t m
guest e = do
now <- liftIO getCurrentTime
ticks <- fmap show <$> tickLossy 1 now
let shutdown = fforMaybe e $ \case
V.EvKey V.KEsc _ -> Just ()
_ -> Nothing
picture <- hold (V.picForImage $ V.string mempty "Initial") $ V.picForImage . V.string mempty <$>
leftmost [show <$> e, show <$> ticks]
return $ VtyResult
{ _vtyResult_picture = picture
, _vtyResult_refresh = never
, _vtyResult_shutdown = shutdown
}
-- TODO Some part of this is probably general enough to belong in reflex
fireEventTriggerRefs
:: (Monad (ReadPhase m), MonadIO m)
@ -120,6 +103,3 @@ fireEventTriggerRefs (FireCommand fire) ers rcb = do
a <- fire es rcb
liftIO $ forM_ ers $ \(_ :=> TriggerInvocation _ cb) -> cb
return a
main :: IO ()
main = host guest