editor-open 0.3.0.0 → 0.4.0.0
raw patch · 5 files changed
+113/−76 lines, 5 filesnew-component:exe:editor-open-test_yaml_file_conduitPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Text.Editor: bracketConduit :: Template -> Producer (ResourceT IO) ByteString -> Consumer ByteString (ResourceT IO) b -> ResourceT IO (ExitCode, b)
Files
- README +45/−0
- README.md +0/−42
- editor-open.cabal +18/−3
- src/Text/Editor.hs +0/−31
- tests/test_yaml_file_conduit.hs +50/−0
+ README view
@@ -0,0 +1,45 @@+editor-open+===========++You know when you run `git commit`, and an editor pops open so you can enter a+commit message? This is a Haskell library that does that.++This library isn't very portable. It relies on the `$EDITOR` environment+variable. The concept only exists on *nix systems.++Installing+----------++If you're using this library, I assume you're familiar with the basic+infrastructure of Haskell programs. If not, check out bitemyapp's guide+to learning Haskell: <https://github.com/bitemyapp/learnhaskell>.++Just add `editor-open` to the `build-depends:` field in your project's `.cabal`+file.++Alternatively, you can just do a one-off installation with:++ cabal install editor-open++Contact+-------++* Email: `peter@harpending.org` +* IRC: `pharpend` on FreeNode and OFTC++Copyright+---------++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.
− README.md
@@ -1,42 +0,0 @@-# editor-open--You know when you run `git commit`, and an editor pops open so you can enter a-commit message? This is a Haskell library that does that.--This library isn't very portable. It relies on the `$EDITOR` environment-variable. The concept only exists on *nix systems.--# Installing--If you're using this library, I assume you're familiar with the basic-infrastructure of Haskell programs. If not, check out-[Bitemyapp's guide](https://github.com/bitemyapp/learnhaskell).--Just add `editor-open` to the `build-depends:` field in your project's `.cabal`-file.--Alternatively, you can just do a one-off installation with:--```-cabal install editor-open-```--# Contact--* Email: `peter@harpending.org` -* IRC: `pharpend` on FreeNode and OFTC--# Copyright--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.
editor-open.cabal view
@@ -1,5 +1,5 @@ name: editor-open-version: 0.3.0.0+version: 0.4.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@@ -18,7 +18,8 @@ cabal-version: >=1.10 bug-reports: https://github.com/pharpend/editor-open/issues/new extra-source-files: - README.md+ LICENSE+ README data-files: res/*.json res/*.yaml@@ -58,6 +59,20 @@ -- other-modules: -- other-extensions: +executable editor-open-test_yaml_file_conduit+ 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: + source-repository head type: git location: https://github.com/pharpend/editor-open.git@@ -65,4 +80,4 @@ source-repository this type: git location: https://github.com/pharpend/editor-open.git- tag: 0.3.0.0+ tag: 0.4.0.0
src/Text/Editor.hs view
@@ -43,37 +43,6 @@ import System.Process import System.Posix --- |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, along with the exit code from the editor.--- --- 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 at the bottom of the module. Be warned that those functions--- are not very performant.-bracketConduit :: Template- -> Producer (ResourceT IO) ByteString- -> Consumer ByteString (ResourceT IO) b- -> ResourceT IO (ExitCode,b)-bracketConduit template producer consumer =- do userEditor_ <-- liftIO (userEditorDefault _default_editor)- systemTempDirectory <- liftIO getTemporaryDirectory- (filePath,handle) <-- liftIO (openBinaryTempFile systemTempDirectory template)- connect producer (sinkHandle handle)- liftIO (hClose handle)- result <-- sourceProcessWithConsumer (proc userEditor_ [filePath])- consumer- liftIO (removeFile filePath)- return result- -- == File-type extensions == -- -- If you use one of the extensions below, you'll likely enable syntax
+ tests/test_yaml_file_conduit.hs view
@@ -0,0 +1,50 @@+-- 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"+ (exitCode,result) <-+ runResourceT+ (bracketConduit plainTemplate+ (toProducer (sourceFile schemaFP))+ (toConsumer sinkLbs))+ case exitCode of+ ExitSuccess -> connect (sourceLbs result) (sinkHandle stdout)+ ExitFailure i ->+ fail (mappend "Editor process failed with exit code " (show i))