packages feed

haskeline 0.6.0.1 → 0.6.1

raw patch · 5 files changed

+79/−20 lines, 5 filesdep ~basedep ~unix

Dependency ranges changed: base, unix

Files

System/Console/Haskeline.hs view
@@ -75,8 +75,7 @@ import Control.Monad import Data.Char(isPrint) import qualified Data.ByteString.Char8 as B--+import System.IO.Error (isEOFError)   -- | A useful default.  In particular:@@ -254,7 +253,12 @@                 f ---------- -{- | Reads one character of input, without waiting for a newline.+{- | Reads one character of input.  Ignores non-printable characters.++If stdin is a terminal, the character will be read without waiting for a newline.++If stdin is not a terminal, a newline will be read if it is immediately+available after the input character. -} getInputChar :: MonadException m => String -- ^ The input prompt                     -> InputT m (Maybe Char)@@ -269,10 +273,37 @@ simpleFileChar :: MonadIO m => String -> RunTerm -> m (Maybe Char) simpleFileChar prefix rterm = liftIO $ do     putStrOut rterm prefix-    atEOF <- hIsEOF stdin-    if atEOF-        then return Nothing-        else liftM Just $ getLocaleChar rterm+    c <- getPrintableChar+    maybeReadNewline+    return c+  where+    getPrintableChar = returnOnEOF Nothing $ do+                c <- getLocaleChar rterm+                if isPrint c+                    then return (Just c)+                    else getPrintableChar++-- If another character is immediately available, and it is a newline, consume it.+--+-- Note that in ghc-6.8.3 and earlier, hReady returns False at an EOF,+-- whereas in ghc-6.10.1 and later it throws an exception.  (GHC trac #1063).+-- This code handles both of those cases.+--+-- Also note that on Windows with ghc<6.10, hReady may not behave correctly (#1198)+-- The net result is that this might cause+-- But this function will generally only be used when reading buffered input+-- (since stdin isn't a terminal), so it should probably be OK.+maybeReadNewline :: IO ()+maybeReadNewline = returnOnEOF () $ do+    ready <- hReady stdin+    when ready $ do+        c <- hLookAhead stdin+        when (c == '\n') $ getChar >> return ()++returnOnEOF :: a -> IO a -> IO a+returnOnEOF x = handle $ \e -> if isEOFError e+                                then return x+                                else throwIO e  -- TODO: it might be possible to unify this function with getInputCmdLine, -- maybe by calling repeatTillFinish here...
System/Console/Haskeline/Backend/IConv.hsc view
@@ -10,13 +10,18 @@ import Foreign.C import Foreign import Data.ByteString (ByteString, useAsCStringLen, append)+-- TODO: Base or Internal, depending on whether base>=3.+#ifdef OLD_BASE+import Data.ByteString.Base (createAndTrim')+#else import Data.ByteString.Internal (createAndTrim')+#endif import qualified Data.ByteString as B import qualified Data.ByteString.UTF8 as UTF8  #include <locale.h> #include <langinfo.h>-#include <iconv.h>+#include "h_iconv.h"  openEncoder :: String -> IO (String -> IO ByteString) openEncoder codeset = do@@ -68,7 +73,8 @@ type IConvT = ForeignPtr () type IConvTPtr = Ptr () -foreign import ccall iconv_open :: CString -> CString -> IO IConvTPtr+foreign import ccall "h_iconv_open" iconv_open+    :: CString -> CString -> IO IConvTPtr  iconvOpen :: String -> String -> IO IConvT iconvOpen destName srcName = withCString destName $ \dest ->@@ -79,9 +85,9 @@                                     else newForeignPtr iconv_close res  -- really this returns a CInt, but it's easiest to just ignore that, I think.-foreign import ccall "&" iconv_close :: FunPtr (IConvTPtr -> IO ())+foreign import ccall "& h_iconv_close" iconv_close :: FunPtr (IConvTPtr -> IO ()) -foreign import ccall "iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize+foreign import ccall "h_iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize                             -> Ptr CString -> Ptr CSize -> IO CSize  data Result = Successful
System/Console/Haskeline/Backend/Posix.hsc view
@@ -41,7 +41,7 @@ ------------------- -- Window size -foreign import ccall ioctl :: CInt -> CULong -> Ptr a -> IO CInt+foreign import ccall ioctl :: FD -> CULong -> Ptr a -> IO CInt  posixLayouts :: Handle -> [IO (Maybe Layout)] posixLayouts h = [ioctlLayout h, envLayout]
+ cbits/h_iconv.c view
@@ -0,0 +1,15 @@+#include "h_iconv.h"++// Wrapper functions, since iconv_open et al are macros in libiconv.+iconv_t h_iconv_open(const char *tocode, const char *fromcode) {+    return iconv_open(tocode, fromcode);+}++void h_iconv_close(iconv_t cd) {+    iconv_close(cd);+}++size_t h_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft,+                char **outbuf, size_t *outbytesleft) {+    return iconv(cd, inbuf, inbytesleft, outbuf, outbytesleft);+}
haskeline.cabal view
@@ -1,6 +1,6 @@ Name:           haskeline Cabal-Version:  >=1.6-Version:        0.6.0.1+Version:        0.6.1 Category:       User Interfaces License:        BSD3 License-File:   LICENSE@@ -29,13 +29,18 @@     Description: Use the terminfo package for POSIX consoles.     Default: True +flag libiconv+    Description: Explicitly link against the libiconv library.+    Default: False+ Library     if flag(old-base)-        Build-depends: base < 3+        Build-depends: base == 2.*+        cpp-options:    -DOLD_BASE     else-        Build-depends: base>=3 && <5 , containers>=0.1, directory>=1.0+        Build-depends: base>=3 && <5 , containers>=0.1, directory>=1.0,+                        bytestring==0.9.*     Build-depends:  filepath==1.1.*, mtl==1.1.*,-                    bytestring==0.9.*,                     utf8-string==0.3.* && >=0.3.1.1,                     extensible-exceptions==0.1.* && >=0.1.1.0     Extensions:     ForeignFunctionInterface, RankNTypes, FlexibleInstances,@@ -44,7 +49,7 @@                 ScopedTypeVariables, GeneralizedNewtypeDeriving                 MultiParamTypeClasses, OverlappingInstances                 PatternSignatures, CPP, DeriveDataTypeable,-                PatternGuards, StandaloneDeriving+                PatternGuards     Exposed-Modules:                 System.Console.Haskeline                 System.Console.Haskeline.Completion@@ -76,14 +81,16 @@         install-includes: win_console.h         cpp-options: -DMINGW     } else {-        Build-depends: unix>=2.2 && < 2.4-                        -- unix-2.3 doesn't build on ghc-6.8.1+        Build-depends: unix>=2.1 && < 2.4+                        -- unix-2.3 doesn't build on ghc-6.8.1 or earlier         -- temporary hack: some OSes provide iconv in (g)libc, and         -- some provide it as a separate libiconv.  It would be         -- better if we could detect this automatically, though.-        if os(darwin) || os(freebsd) {+        if os(darwin) || os(freebsd) || flag(libiconv){             Extra-libraries: iconv         }+        c-sources: cbits/h_iconv.c+        includes: h_iconv.h         Other-modules:                  System.Console.Haskeline.Backend.Posix                 System.Console.Haskeline.Backend.IConv