packages feed

termbox-banana (empty) → 0.1.0

raw patch · 6 files changed

+358/−0 lines, 6 filesdep +basedep +reactive-bananadep +stmsetup-changed

Dependencies added: base, reactive-banana, stm, termbox

Files

+ .travis.yml view
@@ -0,0 +1,94 @@+# This Travis job script has been generated by a script via+#+#   runghc make_travis_yml_2.hs 'cabal.project'+#+# For more information, see https://github.com/hvr/multi-ghc-travis+#+language: c+sudo: false++git:+  submodules: false  # whether to recursively clone submodules++cache:+  directories:+    - $HOME/.cabal/packages+    - $HOME/.cabal/store++before_cache:+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/build-reports.log+  # remove files that are regenerated by 'cabal update'+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/00-index.*+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/*.json+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.cache+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar+  - rm -fv $HOME/.cabal/packages/hackage.haskell.org/01-index.tar.idx++  - rm -rfv $HOME/.cabal/packages/head.hackage++matrix:+  include:+    - compiler: "ghc-8.0.2"+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.0.2], sources: [hvr-ghc]}}+    - compiler: "ghc-8.2.2"+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.2.2], sources: [hvr-ghc]}}+    - compiler: "ghc-8.4.3"+      addons: {apt: {packages: [ghc-ppa-tools,cabal-install-head,ghc-8.4.3], sources: [hvr-ghc]}}++before_install:+  - HC=${CC}+  - HCPKG=${HC/ghc/ghc-pkg}+  - unset CC+  - ROOTDIR=$(pwd)+  - mkdir -p $HOME/.local/bin+  - "PATH=/opt/ghc/bin:/opt/ghc-ppa-tools/bin:$HOME/local/bin:$PATH"+  - HCNUMVER=$(( $(${HC} --numeric-version|sed -E 's/([0-9]+)\.([0-9]+)\.([0-9]+).*/\1 * 10000 + \2 * 100 + \3/') ))+  - echo $HCNUMVER++install:+  - cabal --version+  - echo "$(${HC} --version) [$(${HC} --print-project-git-commit-id 2> /dev/null || echo '?')]"+  - BENCH=${BENCH---enable-benchmarks}+  - TEST=${TEST---enable-tests}+  - HADDOCK=${HADDOCK-true}+  - INSTALLED=${INSTALLED-true}+  - GHCHEAD=${GHCHEAD-false}+  - travis_retry cabal update -v+  - "sed -i.bak 's/^jobs:/-- jobs:/' ${HOME}/.cabal/config"+  - rm -fv cabal.project cabal.project.local+  - grep -Ev -- '^\s*--' ${HOME}/.cabal/config | grep -Ev '^\s*$'+  - "printf 'packages: \".\"\\n' > cabal.project"+  - cat cabal.project+  - if [ -f "./configure.ac" ]; then+      (cd "." && autoreconf -i);+    fi+  - rm -f cabal.project.freeze+  - cabal new-build -w ${HC} ${TEST} ${BENCH} --project-file="cabal.project" --dep -j2+  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks --project-file="cabal.project" --dep -j2+  - rm -rf .ghc.environment.* "."/dist+  - DISTDIR=$(mktemp -d /tmp/dist-test.XXXX)++# Here starts the actual work to be performed for the package under test;+# any command which exits with a non-zero exit code causes the build to fail.+script:+  # test that source-distributions can be generated+  - (cd "." && cabal sdist)+  - mv "."/dist/termbox-banana-*.tar.gz ${DISTDIR}/+  - cd ${DISTDIR} || false+  - find . -maxdepth 1 -name '*.tar.gz' -exec tar -xvf '{}' \;+  - "printf 'packages: termbox-banana-*/*.cabal\\n' > cabal.project"+  - cat cabal.project+  # this builds all libraries and executables (without tests/benchmarks)+  - cabal new-build -w ${HC} --disable-tests --disable-benchmarks all++  # Build with installed constraints for packages in global-db+  - if $INSTALLED; then echo cabal new-build -w ${HC} --disable-tests --disable-benchmarks $(${HCPKG} list --global --simple-output --names-only | sed 's/\([a-zA-Z0-9-]\{1,\}\) */--constraint="\1 installed" /g') all | sh; else echo "Not building with installed constraints"; fi++  # build & run tests, build benchmarks+  - cabal new-build -w ${HC} ${TEST} ${BENCH} all++  # cabal check+  - (cd termbox-banana-* && cabal check)++# REGENDATA ["cabal.project"]+# EOF
+ CHANGELOG.md view
@@ -0,0 +1,11 @@+# Changelog++All notable changes to this project will be documented in this file.++The format is based on [Keep a Changelog](http://keepachangelog.com/)+and this project adheres to the [Haskell Package Versioning Policy](https://pvp.haskell.org/).++## [0.1.0] - 2018-07-22++### Added+- Initial release
+ LICENSE view
@@ -0,0 +1,11 @@+Copyright 2018 Mitchell Rosen++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++2. 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.++3. Neither the name of the copyright holder nor the names of its 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 HOLDER 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Termbox/Banana.hs view
@@ -0,0 +1,189 @@+{-# language CPP                        #-}+{-# language GeneralizedNewtypeDeriving #-}+{-# language LambdaCase                 #-}+{-# language ScopedTypeVariables        #-}+{-# language TypeFamilies               #-}++module Termbox.Banana+  ( -- $intro++    TermboxEvent+  , main+  , Scene(..)+  , Cells+  , set+  , Cursor(..)+    -- * Re-exports+  , Termbox.black+  , Termbox.red+  , Termbox.green+  , Termbox.yellow+  , Termbox.blue+  , Termbox.magenta+  , Termbox.cyan+  , Termbox.white+  , Termbox.bold+  , Termbox.underline+  , Termbox.reverse+  , Termbox.Attr+  , Termbox.Cell(..)+  , Termbox.Event(..)+  , Termbox.InitError(..)+  , Termbox.InputMode(..)+  , Termbox.Key(..)+  , Termbox.Mouse(..)+  , Termbox.MouseMode(..)+  , Termbox.OutputMode(..)+  ) where++import Control.Concurrent.STM+import Data.Function (fix)+import Reactive.Banana+import Reactive.Banana.Frameworks++import qualified Termbox++-- $intro+-- This module is intended to be imported qualified.+--+-- @+-- import qualified Termbox.Banana as Termbox+-- @++-- | A @termbox@ event. This type alias exists only for Haddock readability;+-- in code, you are encouraged to use+--+-- * @Event@ for @reactive-banana@ events+-- * @Termbox.Event@ for @termbox@ events+--+-- @since 0.1.0+type TermboxEvent+  = Termbox.Event++-- | A scene to render; a grid of cells and a cursor.+--+-- @since 0.1.0+data Scene+  = Scene !Cells !Cursor++-- | A grid of cells. Create a 'Cells' with 'set' or 'mempty' and combine them+-- with ('<>').+--+-- @since 0.1.0+newtype Cells+  = Cells (IO ())+#if MIN_VERSION_base(4,10,0)+  deriving (Monoid, Semigroup)+#else+instance Monoid Cells where+  mempty = Cells (pure ())+  mappend = (<>)+instance Semigroup Cells where+  Cells x <> Cells y = Cells (x >> y)+#endif++-- | A cursor.+--+-- @since 0.1.0+data Cursor+  = Cursor !Int !Int -- ^ Column, then row+  | NoCursor++-- | Set a single cell's value.+--+-- @since 0.1.0+set :: (col ~ Int, row ~ Int) => col -> row -> Termbox.Cell -> Cells+set x y z =+  Cells (Termbox.set x y z)++type EventSource a+  = (AddHandler a, a -> IO ())++-- | Run a @termbox@ program with the specified input and output modes.+--+-- Given+--+-- * the terminal event stream and+-- * the time-varying terminal size,+--+-- return a time-varying+--+-- * scene to render, and+-- * a event stream of arbitrary values, only the first of which is relevant,+--   which ends the @termbox@ program and returns from the @main@ action.+--+-- @since 0.1.0+main+  :: (width ~ Int, height ~ Int)+  => Termbox.InputMode -- ^+  -> Termbox.OutputMode -- ^+  -> (  Event TermboxEvent+     -> Behavior (width, height)+     -> MomentIO (Behavior Scene, Event a))+  -> IO a+main imode omode run =+  Termbox.main $ do+    Termbox.setInputMode imode+    Termbox.setOutputMode omode++    doneVar :: TMVar a <-+      newEmptyTMVarIO++    (eventAddHandler, fireEvent) :: EventSource TermboxEvent <-+      newAddHandler++    network :: EventNetwork <-+      compile $ do+        eEvent :: Event TermboxEvent <-+          fromAddHandler eventAddHandler++        let+          eResize :: Event (Int, Int)+          eResize =+            filterJust+              ((\case+                Termbox.EventResize w h -> Just (w, h)+                _ -> Nothing)+              <$> eEvent)++        bSize :: Behavior (Int, Int) <- do+          flip stepper eResize =<<+            liftIO Termbox.size++        moment run eEvent bSize (atomically . putTMVar doneVar)++    actuate network++    fix $ \loop -> do+      Termbox.poll >>= fireEvent+      atomically (tryReadTMVar doneVar) >>=+        maybe loop pure++moment+  :: (  Event TermboxEvent+     -> Behavior (Int, Int)+     -> MomentIO (Behavior Scene, Event a))+  -> Event TermboxEvent+  -> Behavior (Int, Int)+  -> (a -> IO ())+  -> MomentIO ()+moment run eEvent bSize abort = do+  (bScene, eDone) :: (Behavior Scene, Event a) <-+    run eEvent bSize++  eScene :: Event (Future Scene) <-+    changes bScene++  let+    render :: Scene -> IO ()+    render (Scene (Cells cells) cursor) = do+      Termbox.clear mempty mempty+      cells+      case cursor of+        Cursor c r -> Termbox.setCursor c r+        NoCursor -> Termbox.hideCursor+      Termbox.flush++  liftIO . render =<< valueB bScene+  reactimate (abort <$> eDone)+  reactimate' ((fmap.fmap) render eScene)
+ termbox-banana.cabal view
@@ -0,0 +1,51 @@+cabal-version: 2.0++name: termbox-banana+version: 0.1.0+category: User Interfaces+description:+  A @reactive-banana@-based interface to writing @termbox@ programs.+synopsis: reactive-banana + termbox+author: Mitchell Rosen+maintainer: Mitchell Rosen <mitchellwrosen@gmail.com>+homepage: https://github.com/mitchellwrosen/termbox-banana+bug-reports: https://github.com/mitchellwrosen/termbox-banana/issues+copyright: (c) 2018, Mitchell Rosen+license: BSD3+license-file: LICENSE+build-type: Simple+tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.3++extra-source-files:+  .travis.yml+  CHANGELOG.md++library+  build-depends:+      base ^>= 4.9 || ^>= 4.10 || ^>= 4.11+    , reactive-banana ^>= 1.2+    , stm ^>= 2.4+    , termbox ^>= 0.1+  default-language:+    Haskell2010+  exposed-modules:+    Termbox.Banana+  ghc-options:+    -fprint-expanded-synonyms+    -fprint-explicit-foralls+    -fprint-explicit-kinds+    -fprint-unicode-syntax+    -Wall+    -Wcompat+    -Widentities+    -Wincomplete-record-updates+    -Wincomplete-uni-patterns+    -Wnoncanonical-monad-instances+    -Wnoncanonical-monadfail-instances+    -Wredundant-constraints+  if impl(ghc >= 8.4)+    ghc-options:+      -Wmissing-export-lists+      -Wpartial-fields+  hs-source-dirs:+    src