module Control.Shell.Handle (
IO.Handle, IO.IOMode (..),
IO.stdin, IO.stdout, IO.stderr,
hPutStr, hPutStrLn,
hGetLine, hGetContents,
hGetBytes, hPutBytes, hGetByteLine, hGetByteContents,
hFlush, hClose, withFile, withBinaryFile, openFile, openBinaryFile
) where
import qualified System.IO as IO
import qualified Data.ByteString as BS
import Control.Shell.Internal
hPutStr :: IO.Handle -> String -> Shell ()
hPutStr h s = liftIO $ IO.hPutStr h s
hPutStrLn :: IO.Handle -> String -> Shell ()
hPutStrLn h s = liftIO $ IO.hPutStrLn h s
hClose :: IO.Handle -> Shell ()
hClose = liftIO . IO.hClose
hFlush :: IO.Handle -> Shell ()
hFlush = liftIO . IO.hFlush
hGetLine :: IO.Handle -> Shell String
hGetLine = liftIO . IO.hGetLine
hGetContents :: IO.Handle -> Shell String
hGetContents = liftIO . IO.hGetContents
hGetBytes :: IO.Handle -> Int -> Shell BS.ByteString
hGetBytes h = liftIO . BS.hGet h
hGetByteLine :: IO.Handle -> Shell BS.ByteString
hGetByteLine = liftIO . BS.hGetLine
hGetByteContents :: IO.Handle -> Shell BS.ByteString
hGetByteContents = liftIO . BS.hGetContents
hPutBytes :: IO.Handle -> BS.ByteString -> Shell ()
hPutBytes h = liftIO . BS.hPutStr h
withFile :: FilePath -> IO.IOMode -> (IO.Handle -> Shell a) -> Shell a
withFile file mode f =
liftIO (IO.withFile file mode (shell . f)) >>= liftResult
withBinaryFile :: FilePath -> IO.IOMode -> (IO.Handle -> Shell a) -> Shell a
withBinaryFile file mode f =
liftIO (IO.withBinaryFile file mode (shell . f)) >>= liftResult
openFile :: FilePath -> IO.IOMode -> Shell IO.Handle
openFile file = liftIO . IO.openFile file
openBinaryFile :: FilePath -> IO.IOMode -> Shell IO.Handle
openBinaryFile file = liftIO . IO.openBinaryFile file
liftResult :: Either ExitReason a -> Shell a
liftResult (Right x) = return x
liftResult (Left Success) = exit
liftResult (Left (Failure err)) = fail err