diff options
author | Joey Hess <joeyh@joeyh.name> | 2017-04-13 17:28:02 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2017-04-13 17:28:02 -0400 |
commit | de2aa41f0ecdea914c44601c4c015d5913f7b6bf (patch) | |
tree | a9b009f57c8f281fb4f0204b10f077c129c994d2 | |
parent | 75a2a5432c284161411779a02a6f0b02f7328970 (diff) | |
download | debug-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.
-rw-r--r-- | Pty.hs | 9 | ||||
-rw-r--r-- | TODO | 1 |
2 files changed, 5 insertions, 5 deletions
@@ -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 @@ -1,4 +1,3 @@ -* control-d does not exit debug-me * Uncommenting the networkDelay in sendPtyOutput exposes a bug in the Activity chain construction. * potential DOS where developer sends Activity Entered that all |