diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-11 15:31:50 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-11 15:31:50 -0400 |
commit | 58e71d656c3cfb6862647cdf215676b529a00c93 (patch) | |
tree | 0b5abf34bb448eaa4242ef5aeb1aae3de7f193ac /debug-me.hs | |
parent | bf71e5f4d875806e8f2623d95545c8b7a7c2d8f4 (diff) | |
download | debug-me-58e71d656c3cfb6862647cdf215676b529a00c93.tar.gz |
debug-me is able to run a shell in a slave pty
Lots of terminal mode fun. Has a few warts still, but it works well
enough to be comfortable, and even vim works ok.
This commit was sponsored by John Peloquin on Patreon.
Diffstat (limited to 'debug-me.hs')
-rw-r--r-- | debug-me.hs | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/debug-me.hs b/debug-me.hs index 553343a..6103545 100644 --- a/debug-me.hs +++ b/debug-me.hs @@ -2,5 +2,42 @@ module Main where import Types import Hash +import Pty -main = print "hi" +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 |