packages feed

Shellac-editline (empty) → 0.9

raw patch · 4 files changed

+130/−0 lines, 4 filesdep +Shellacdep +basedep +editlinesetup-changed

Dependencies added: Shellac, base, editline, haskell98

Files

+ LICENSE view
@@ -0,0 +1,23 @@+Copyright 2008, Robert Dockins.+All Rights Reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++- Redistribution of source code must retain the above copyright notice,+this list of conditions and the following disclamer.++- Redistribution in binary form must reproduce the above copyright notice,+this list of conditions and the following disclamer in the documentation+and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR THE 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,3 @@+#!/usr/bin/env runhaskell+import Distribution.Simple+main = defaultMain
+ Shellac-editline.cabal view
@@ -0,0 +1,27 @@+Name:           Shellac-editline+Version:        0.9+Cabal-version:  >= 1.2+Build-type:     Simple+Author:         Robert Dockins+License:        BSD3+License-File:   LICENSE+Maintainer:     robdockins AT fastmail DOT fm+Category:       User Interfaces+Stability:      Beta+Homepage:       http://www.cs.princeton.edu/~rdockins/shellac/home/+Synopsis:       Editline backend module for Shellac+Description:+   This package provides a Shellac backend based on the editline+   library.  editline provides a subset of the functionality+   provided by the GNU readline library.  However, it is licenced+   with a BSD-style license and is therefore suitable for some situations+   where GNU readline is not.  This backend features all the line+   editing capabilities provided by editline.+Hs-Source-Dirs:+   src+Build-Depends:+   base, haskell98,+   editline >= 0.2,+   Shellac >= 0.9+Exposed-modules:+   System.Console.Shell.Backend.Editline
+ src/System/Console/Shell/Backend/Editline.hs view
@@ -0,0 +1,77 @@+{-+ - + -  Copyright 2005-2008, Robert Dockins.+ -  + -}++{- | This module implements a Shellac backend based on the editline library.+     +     Both the code for this binding and the editline library itself are+     licenced under BSD-style licences.+-}+++module System.Console.Shell.Backend.Editline+( editlineBackend+) where++import System.IO            ( stdin, stdout, stderr, hFlush, hPutStr, hPutStrLn, hGetChar+                            , hSetBuffering, hGetBuffering+                            , BufferMode(..)+                            )++import qualified Control.Exception as Ex+import System.Console.Editline+import qualified System.Console.Editline.Readline as EL++import System.Console.Shell.Backend ++editlineBackend :: ShellBackend ()+editlineBackend = ShBackend+  { initBackend                      = return ()+  , shutdownBackend                  = \_ -> return ()+  , outputString                     = \_ -> editlineOutput+  , flushOutput                      = \_ -> hFlush stdout+  , getInput                         = \_ -> EL.readline+  , getSingleChar                    = \_ -> editlineGetSingleChar+  , addHistory                       = \_ -> EL.addHistory+  , getWordBreakChars                = \_ -> EL.getBasicWordBreakCharacters+  , setWordBreakChars                = \_ -> EL.setBasicWordBreakCharacters+  , onCancel                         = \_ -> hPutStrLn stdout "canceled..."+  , setAttemptedCompletionFunction   = \_ -> editlineCompletionFunction+  , setDefaultCompletionFunction     = \_ -> EL.setCompletionEntryFunction+  , completeFilename                 = \_ -> EL.filenameCompletionFunction+  , completeUsername                 = \_ -> EL.usernameCompletionFunction+  , clearHistoryState                = \_ -> EL.clearHistory+  , setMaxHistoryEntries             = \_ -> EL.stifleHistory+  , getMaxHistoryEntries             = \_ -> EL.historyMaxEntries+  , readHistory                      = \_ -> EL.readHistory+  , writeHistory                     = \_ -> EL.writeHistory+  }+++editlineCompletionFunction :: CompletionFunction -> IO ()+editlineCompletionFunction f = EL.setAttemptedCompletionFunction (Just complete)++ where complete word begin end = do+          buffer <- EL.getLineBuffer+          let before = take begin buffer+          let after  = drop end buffer++          f (before,word,after)+++editlineGetSingleChar :: String -> IO (Maybe Char)+editlineGetSingleChar prompt = do+   hPutStr stdout prompt+   hFlush stdout+   Ex.bracket (hGetBuffering stdin) (hSetBuffering stdin) $ \_ -> do+      hSetBuffering stdin NoBuffering+      c <- hGetChar stdin+      hPutStrLn stdout ""+      return (Just c)++editlineOutput :: BackendOutput -> IO ()+editlineOutput (RegularOutput str)  = hPutStr stdout str+editlineOutput (InfoOutput str)     = hPutStr stdout str+editlineOutput (ErrorOutput str)    = hPutStr stderr str