Skip to content

Commit

Permalink
Move stderr of stty to pipe
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bradrn committed Jul 11, 2019
1 parent d47596c commit e46d4e1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/System/Console/Terminal/Windows.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
Expand Down

0 comments on commit e46d4e1

Please sign in to comment.