module IDE.Command.Print (
print
, PrintError (..)
) where
import System.Exit
import Prelude hiding (print)
import IDE.Core.Types
import IDE.Core.State
import IDE.Utils.Tool (readProcessWithExitCode)
import Data.Text (Text)
import qualified Data.Text as T (pack)
data PrintError = PrintError {
exitCode :: Int
, stderr :: Text
, printCmd :: FilePath
} deriving (Read,Show)
#if defined (windows_HOST_OS)
printCommand = "print"
#else
printCommand = "lpr"
#endif
print :: FilePath -> IO (Either PrintError Text)
print fileName = do
(ec, out, err) <- readProcessWithExitCode printCommand [fileName] ""
case ec of
ExitSuccess -> return $ Right (T.pack out)
ExitFailure i -> return $ Left $ PrintError i (T.pack err) printCommand