module Main where import Types import Hash import Pty import Control.Concurrent.Async import System.IO import System.Process import System.Exit import qualified Data.ByteString as B main :: IO () main = do exitstatus <- go putStrLn "" putStrLn ">>> debug-me is exiting..." exitWith exitstatus where go = withChildPty $ \p -> do (Nothing, Nothing, Nothing, ph) <- createProcess $ onPty p (proc "bash" []) let Master h = ptyMaster p hSetBuffering stdin NoBuffering hSetBuffering h NoBuffering ithread <- async (forward stdin h ph) othread <- async (forward h stdout ph) exitstatus <- waitForProcess ph cancel ithread cancel othread return exitstatus forward :: Handle -> Handle -> ProcessHandle -> IO () forward from to ph = do b <- B.hGetSome from 1024 if b == B.empty then do terminateProcess ph return () else do B.hPut to b hFlush to forward from to ph