summaryrefslogtreecommitdiffhomepage
path: root/Pty.hs
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2017-04-13 17:28:02 -0400
committerJoey Hess <joeyh@joeyh.name>2017-04-13 17:28:02 -0400
commitde2aa41f0ecdea914c44601c4c015d5913f7b6bf (patch)
treea9b009f57c8f281fb4f0204b10f077c129c994d2 /Pty.hs
parent75a2a5432c284161411779a02a6f0b02f7328970 (diff)
downloaddebug-me-de2aa41f0ecdea914c44601c4c015d5913f7b6bf.tar.gz
copy terminal attrs to the pty
This fixes the control-d issue, and many more besides. See https://github.com/merijn/posix-pty/issues/11 Also though, it means that if the user has set some unusual stty value, it gets copied into the pty. We want this in debug-me, because it ought to replicate the environment it's run in as well as possible. This commit was sponsored by Thomas Hochstein on Patreon.
Diffstat (limited to 'Pty.hs')
-rw-r--r--Pty.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/Pty.hs b/Pty.hs
index 39e48f0..3d62e96 100644
--- a/Pty.hs
+++ b/Pty.hs
@@ -1,7 +1,7 @@
module Pty (Pty, runWithPty, readPty, writePty) where
import System.Posix
-import System.Posix.Pty hiding (setTerminalAttributes, getTerminalAttributes)
+import System.Posix.Pty
import qualified System.Console.Terminal.Size as Console
import System.Posix.Signals.Exts
import System.Process
@@ -17,11 +17,12 @@ runWithPty :: String -> [String] -> ((Pty, ProcessHandle) -> IO a) -> IO a
runWithPty cmd params a = bracket setup cleanup go
where
setup = do
- as <- getTerminalAttributes stdInput
+ as <- System.Posix.getTerminalAttributes stdInput
sz <- Console.size
(p, ph) <- spawnWithPty Nothing True cmd params
(maybe 80 Console.width sz, maybe 25 Console.height sz)
_ <- installHandler windowChange (Catch (forwardresize p)) Nothing
+ System.Posix.Pty.setTerminalAttributes p as Immediately
-- This is similar to cfmakeraw(3).
let masteras = as
`withoutMode` IgnoreBreak
@@ -39,7 +40,7 @@ runWithPty cmd params a = bracket setup cleanup go
`withoutMode` KeyboardInterrupts
`withoutMode` ExtendedFunctions
`withoutMode` EnableParity
- setTerminalAttributes stdInput masteras Immediately
+ System.Posix.setTerminalAttributes stdInput masteras Immediately
return (p, ph, as)
cleanup (p, ph, as) = do
-- Needed in case the provided action throws an exception
@@ -47,7 +48,7 @@ runWithPty cmd params a = bracket setup cleanup go
terminateProcess ph
closePty p
_ <- installHandler windowChange Default Nothing
- setTerminalAttributes stdInput as Immediately
+ System.Posix.setTerminalAttributes stdInput as Immediately
go (p, ph, _) = a (p, ph)
forwardresize p = do
msz <- Console.size