packages feed

polysemy-readline (empty) → 0.1.0.0

raw patch · 7 files changed

+200/−0 lines, 7 filesdep +basedep +exceptionsdep +haskelinesetup-changed

Dependencies added: base, exceptions, haskeline, polysemy, polysemy-plugin, polysemy-readline

Files

+ ChangeLog.md view
@@ -0,0 +1,4 @@+# Changelog for polysemy-readline++## 0.1.0.0 — June 24th 2021+- Release candidate for Hackage.
+ LICENSE view
@@ -0,0 +1,25 @@+BSD 2-Clause License++Copyright (c) 2021, Devin Lehmacher+All rights reserved.++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.++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.
+ README.md view
@@ -0,0 +1,14 @@+# polysemy-readline+[![GitHub Actions](https://github.com/lehmacdj/polysemy-readline/actions/workflows/ci.yml/badge.svg)](https://github.com/lehmacdj/polysemy-readline/actions/workflows/ci.yml)+[![Hackage](http://img.shields.io/hackage/v/polsyemy-readline.svg)](http://img.shields.io/hackage/v/polsyemy-readline.svg)++This package provides a [polysemy](https://github.com/polysemy-research/polysemy#readme) effect that provides most of the functionality of [haskeline](https://github.com/judah/haskeline#readme). See Haskeline's documentation for usage information.++## Contributions+Issues or PRs are welcome. In particular there are a number of things that I don't use frequently enough from Haskeline to justify working on or just haven't gotten around to implementing yet:+- interrupt handling: `withInterrupt`, `handleInterrupt`+- pure interpreter for using in tests+- additional interpreters matching the `run*` functions for `InputT`+- support for older versions of Haskeline (currently only 0.8.1+ is supported)+- version bumps for things that already compile but aren't allowed+PRs for any of these things would be greatly appreciated or I might get around to implementing them myself later 🙂.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ polysemy-readline.cabal view
@@ -0,0 +1,67 @@+cabal-version: 2.2++name:           polysemy-readline+synopsis:       Readline effect for polysemy.+version:        0.1.0.0+category:       User Interfaces, Effect+homepage:       https://github.com/lehmacdj/polysemy-readline#readme+bug-reports:    https://github.com/lehmacdj/polysemy-readline/issues+author:         Devin Lehmacher+maintainer:     Devin Lehmacher+copyright:      (c) 2021 Devin Lehmacher+license:        BSD-2-Clause+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md+description:+  This library provides a Readline effect for polysemy with a primary+  interpreter based on haskeline. Please see the README on GitHub at+  <https://github.com/lehmacdj/polysemy-readline#readme> for more details.++source-repository head+  type: git+  location: https://github.com/lehmacdj/polysemy-readline++common common-options+  ghc-options: -Wall+               -Wincomplete-uni-patterns+               -fplugin=Polysemy.Plugin+               -flate-specialise+               -fspecialise-aggressively+  build-depends:+      base >=4.12 && <4.15+    , exceptions >=0.10.4 && <0.11+    , haskeline >=0.8.1 && <0.9.0+    , polysemy >=1.5.0 && <1.6+    , polysemy-plugin >=0.3.0 && <0.4+  default-language: Haskell2010++common exe-options+  ghc-options: -threaded -rtsopts -with-rtsopts=-N++library+  import: common-options+  exposed-modules:+      Polysemy.Readline+  other-modules:+      Paths_polysemy_readline+  autogen-modules:+      Paths_polysemy_readline+  hs-source-dirs:+      src++test-suite polysemy-readline-test+  import: common-options+  import: exe-options+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_polysemy_readline+  autogen-modules:+      Paths_polysemy_readline+  hs-source-dirs:+      test+  build-depends: polysemy-readline+  default-language: Haskell2010
+ src/Polysemy/Readline.hs view
@@ -0,0 +1,86 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeOperators #-}++-- | This libraries provides a polysemy effect that provides interactive command+-- line usage.+module Polysemy.Readline+  ( -- * Effect and Actions+    Readline (..),+    getInputLine,+    getInputLineWithInitial,+    getInputChar,+    getPassword,+    waitForAnyKey,+    outputStr,+    outputStrLn,++    -- * Interpreters+    runReadline,+    interpretReadlineAsInputT,++    -- * Re-exports from @haskeline@+    H.Settings,+    H.defaultSettings,+  )+where++import Control.Monad.Catch+import Control.Monad.IO.Class+import Polysemy+import Polysemy.Embed+import qualified System.Console.Haskeline as H++-- | For documentation on actions see haskeline's functions with the same name+-- and similar type signatures.+data Readline (m :: * -> *) a where+  GetInputLine :: String -> Readline m (Maybe String)+  GetInputLineWithInitial :: String -> (String, String) -> Readline m (Maybe String)+  GetInputChar :: String -> Readline m (Maybe Char)+  GetPassword :: Maybe Char -> String -> Readline m (Maybe String)+  WaitForAnyKey :: String -> Readline m Bool+  OutputStr :: String -> Readline m ()++-- TODO(Devin): add these two values as well+-- WithInterrupt :: m a -> Readline m a+-- HandleInterrupt :: m a -> m a -> Readline m a++makeSem ''Readline++outputStrLn :: Member Readline r => String -> Sem r ()+outputStrLn str = outputStr (str <> "\n")++-- | The standard way to run a Readline effect. Should be sufficient for+-- most use cases. If you want to modify the Behavior or Prefs of InputT use+-- interpretReadlineAsInputT instead.+runReadline ::+  forall m r a.+  (MonadIO m, MonadMask m, Member (Embed m) r) =>+  H.Settings m ->+  Sem (Readline : r) a ->+  Sem r a+runReadline settings =+  runEmbedded (H.runInputT settings)+    . interpretReadlineAsInputT+    . raiseUnder @(Embed (H.InputT m))++-- | Interpret in terms of an embedded 'H.InputT' stack.+interpretReadlineAsInputT ::+  forall m r a.+  (MonadIO m, MonadMask m, Member (Embed (H.InputT m)) r) =>+  Sem (Readline : r) a ->+  Sem r a+interpretReadlineAsInputT = interpret $ \case+  GetInputLine prompt -> embed $ H.getInputLine prompt+  GetInputLineWithInitial prompt initial ->+    embed $ H.getInputLineWithInitial prompt initial+  GetInputChar prompt -> embed $ H.getInputChar prompt+  GetPassword maskChar prompt -> embed $ H.getPassword maskChar prompt+  WaitForAnyKey prompt -> embed $ H.waitForAnyKey prompt+  OutputStr str -> embed $ H.outputStr str
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"