From de2aa41f0ecdea914c44601c4c015d5913f7b6bf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 13 Apr 2017 17:28:02 -0400 Subject: 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. --- Pty.hs | 9 +++++---- TODO | 1 - 2 files changed, 5 insertions(+), 5 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 diff --git a/TODO b/TODO index 1371748..58c6347 100644 --- a/TODO +++ b/TODO @@ -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 -- cgit v1.2.3