X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fghci%2FInteractiveUI.hs;fp=compiler%2Fghci%2FInteractiveUI.hs;h=e385f6bb4659552ffe37033dfba6879a4e52897b;hp=a2108bb0b97c845a66c810a92e738866a118fe49;hb=758baa7c72043c44c91c0ba4f1fb7910cd7aa520;hpb=ec70c0a7512cd18ad08d23d69a8eea645fc8f2cf diff --git a/compiler/ghci/InteractiveUI.hs b/compiler/ghci/InteractiveUI.hs index a2108bb..e385f6b 100644 --- a/compiler/ghci/InteractiveUI.hs +++ b/compiler/ghci/InteractiveUI.hs @@ -293,7 +293,7 @@ findEditor = do interactiveUI :: [(FilePath, Maybe Phase)] -> Maybe [String] -> Ghc () -interactiveUI srcs maybe_exprs = do +interactiveUI srcs maybe_exprs = withTerminalReset $ do -- HACK! If we happen to get into an infinite loop (eg the user -- types 'let x=x in x' at the prompt), then the thread will block -- on a blackhole, and become unreachable during GC. The GC will @@ -382,6 +382,22 @@ withGhcAppData right left = do Right dir -> right dir _ -> left +-- libedit doesn't always restore the terminal settings correctly (as of at +-- least 07/12/2008); see trac #2691. Work around this by manually resetting +-- the terminal outselves. +withTerminalReset :: Ghc () -> Ghc () +#ifdef mingw32_HOST_OS +withTerminalReset = id +#else +withTerminalReset f = do + isTTY <- liftIO $ hIsTerminalDevice stdout + if not isTTY + then f + else do + oldAttrs <- liftIO $ getTerminalAttributes stdOutput + f + liftIO $ setTerminalAttributes stdOutput oldAttrs Immediately +#endif runGHCi :: [(FilePath, Maybe Phase)] -> Maybe [String] -> GHCi () runGHCi paths maybe_exprs = do