packages feed

editor-open 0.4.0.2 → 0.5.0.0

raw patch · 3 files changed

+104/−25 lines, 3 filesdep +conduitdep +conduit-extradep +resourcetdep ~basenew-component:exe:editor-open-test_yaml_file_conduitPVP ok

version bump matches the API change (PVP)

Dependencies added: conduit, conduit-extra, resourcet, transformers

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Text.Editor: bracketConduit :: Template -> Producer (ResourceT IO) ByteString -> Consumer ByteString (ResourceT IO) b -> ResourceT IO b

Files

editor-open.cabal view
@@ -1,5 +1,5 @@ name:                editor-open-version:             0.4.0.2+version:             0.5.0.0 synopsis:            Open the user's $EDITOR for text input. description:   You know when you run @git commit@, and an editor pops open so you can enter a@@ -7,6 +7,10 @@   .   This library isn't very portable. It relies on the @$EDITOR@ environment   variable. The concept only exists on *nix systems.+  .+  CHANGES+  .+  [0.5.0.0] Now use conduits on the backend. Support @base\<4.8@ homepage:            https://github.com/pharpend/editor-open license:             Apache-2.0 license-file:        LICENSE@@ -35,11 +39,15 @@     OverloadedStrings     RankNTypes   build-depends:-     base ==4.8.*+     base ==4.*    , bytestring+   , conduit >=1.2.3+   , conduit-extra    , directory    , process >=1.2+   , resourcet    , temporary+   , transformers    , unix   exposed-modules:          Text.Editor@@ -48,27 +56,26 @@   hs-source-dirs:      tests/   default-language:    Haskell2010   build-depends:-     base ==4.8.*+     base    , bytestring    , editor-open   main-is:             test_yaml_file.hs   -- other-modules:          -- other-extensions:     --- executable editor-open-test_yaml_file_conduit---   buildable: False---   hs-source-dirs:      tests/---   default-language:    Haskell2010---   build-depends:---      base ==4.8.*---    , bytestring---    , conduit >=1.2.3 && <1.3---    , conduit-extra---    , editor-open---    , resourcet---   main-is:             test_yaml_file_conduit.hs---   -- other-modules:       ---   -- other-extensions:    +executable editor-open-test_yaml_file_conduit+   hs-source-dirs:      tests/+   default-language:    Haskell2010+   build-depends:+      base+    , bytestring+    , conduit >=1.2.3+    , conduit-extra+    , editor-open+    , resourcet+   main-is:             test_yaml_file_conduit.hs+   -- other-modules:       +   -- other-extensions:      source-repository head    type: git@@ -77,4 +84,4 @@ source-repository this   type: git   location: https://github.com/pharpend/editor-open.git-  tag: 0.4.0.2+  tag: 0.5.0.0
src/Text/Editor.hs view
@@ -19,7 +19,7 @@ -- Copyright   : Copyright 2015 Peter Harpending -- License     : Apache-2.0 -- Maintainer  : Peter Harpending <peter@harpending.org>--- Stability   : experimental+-- Stability   : stable -- Portability : POSIX --  -- You know when you run @git commit@, and a little editor pops up?@@ -27,12 +27,14 @@  module Text.Editor where +import           Control.Monad.Trans.Resource+import           Control.Monad.IO.Class import qualified Data.ByteString as B import           Data.ByteString (ByteString) import           Data.ByteString.Char8 (unpack)+import           Data.Conduit+import           Data.Conduit.Binary import           Data.Monoid-import           System.Directory (getTemporaryDirectory, removeFile)-import           System.Exit (ExitCode) import           System.IO import           System.IO.Temp import           System.Process@@ -104,6 +106,31 @@   \theEditor ->     runSpecificEditor theEditor templ mempty +--- |This is the function you should use.+--- +--- 'bracketConduit' takes a 'Producer', to produce the contents of the+--- original file, and a 'Consumer' to consume them, and returns the+--- result of the consumer.+--- +--- If you don't know how to use conduits, see the+--- <http://www.stackage.org/package/conduit documentation> for the+--- conduit package.+--- +--- If you really don't want to use conduits, you can use the strict I/O+--- functions+bracketConduit :: Template +               -> Producer (ResourceT IO) ByteString+               -> Consumer ByteString (ResourceT IO) b+               -> ResourceT IO b+bracketConduit template source consumer =+    withSystemTempFile template $ \filePath hdl -> do+        editor <- liftIO $ userEditorDefault _default_editor+        connect source (sinkHandle hdl)+        liftIO $ spawnProcess editor [filePath] >>= waitForProcess+        -- Seek to the beginning of the file again+        liftIO $ hSeek hdl AbsoluteSeek 0+        connect (sourceHandle hdl) consumer+ -- == File-type extensions == --  -- If you use one of the extensions below, you'll likely enable syntax@@ -223,16 +250,16 @@ -- @$EDITOR@ variable doesn't exist. -- @ -- userEditorDefault def = userEditor >>= \case---                           Just e  -> pure e---                           Nothing -> pure def+--                           Just e  -> return e+--                           Nothing -> return def -- @ userEditorDefault :: String -- ^Default value if @$EDITOR@ is not found.                   -> IO String userEditorDefault def =   userEditor >>=   \case-    Just e -> pure e-    Nothing -> pure def+    Just e ->  return e+    Nothing -> return def   -- == Internal variables ==
+ tests/test_yaml_file_conduit.hs view
@@ -0,0 +1,45 @@+-- Copyright 2015 Peter Harpending+-- +-- Licensed under the Apache License, Version 2.0 (the "License"); you+-- may not use this file except in compliance with the License.  You+-- may obtain a copy of the License at+-- +--     http://www.apache.org/licenses/LICENSE-2.0+-- +-- Unless required by applicable law or agreed to in writing, software+-- distributed under the License is distributed on an "AS IS" BASIS,+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or+-- implied.  See the License for the specific language governing+-- permissions and limitations under the License.+++-- | +-- Module      : Main+-- Description : Test of editor-open+-- Copyright   : Copyright 2015 Peter Harpending+-- License     : Apache-2.0+-- Maintainer  : Peter Harpending <peter@harpending.org>+-- Stability   : experimental+-- Portability : POSIX+-- ++module Main where++import Control.Monad.Trans.Resource (runResourceT)+import qualified Data.ByteString.Lazy as B+import Data.Conduit (connect, toConsumer, toProducer)+import Data.Conduit.Binary+       (sinkHandle, sinkLbs, sourceFile, sourceLbs)+import Paths_editor_open (getDataFileName)+import System.Exit (ExitCode(..))+import System.IO (stdout)+import Text.Editor (bracketConduit, plainTemplate)++main :: IO ()+main = do+         schemaFP <- getDataFileName "res/bug-schema.yaml"+         result <- runResourceT+           (bracketConduit plainTemplate+                           (toProducer (sourceFile schemaFP))+                           (toConsumer sinkLbs))+         connect (sourceLbs result) (sinkHandle stdout)