From e46d4e1de10a3e670066d8aab3e8b5f816320f56 Mon Sep 17 00:00:00 2001 From: Brad Neimann Date: Thu, 11 Jul 2019 17:08:16 +1000 Subject: [PATCH] Move stderr of stty to pipe If stderr is left as its default value, any error messages arising from stty are output to the stderr of the program calling `size`, causing strange messages if stty fails. --- src/System/Console/Terminal/Windows.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/System/Console/Terminal/Windows.hs b/src/System/Console/Terminal/Windows.hs index 962afd7..b4fc4d2 100644 --- a/src/System/Console/Terminal/Windows.hs +++ b/src/System/Console/Terminal/Windows.hs @@ -4,6 +4,7 @@ module System.Console.Terminal.Windows(size) where import System.Console.Terminal.Common import Control.Monad +import Control.Exception (evaluate) import Data.Word import Foreign.Ptr import Foreign.Storable @@ -42,9 +43,12 @@ size = do let stty = (shell "stty size") { std_in = UseHandle stdin , std_out = CreatePipe + , std_err = CreatePipe } - (_, mbStdout, _, rStty) <- createProcess stty + (_, mbStdout, mbStderr, rStty) <- createProcess stty exStty <- waitForProcess rStty + -- Drain stderr by evaluating it fully + maybe (pure ()) ((void . evaluate . length) <=< hGetContents) mbStderr case exStty of ExitFailure _ -> return Nothing ExitSuccess ->