:set prompt now understand Haskell String syntax; trace #2652
[ghc-hetmet.git] / compiler / ghci / InteractiveUI.hs
index e385f6b..4db8900 100644 (file)
@@ -393,10 +393,9 @@ withTerminalReset f = do
     isTTY <- liftIO $ hIsTerminalDevice stdout
     if not isTTY
         then f
-        else do
-            oldAttrs <- liftIO $ getTerminalAttributes stdOutput
-            f
-            liftIO $ setTerminalAttributes stdOutput oldAttrs Immediately
+        else gbracket (liftIO $ getTerminalAttributes stdOutput)
+                (\attrs -> liftIO $ setTerminalAttributes stdOutput attrs Immediately)
+                (const f)
 #endif
 
 runGHCi :: [(FilePath, Maybe Phase)] -> Maybe [String] -> GHCi ()
@@ -1500,10 +1499,13 @@ setPrompt value = do
   st <- getGHCiState
   if null value
       then io $ hPutStrLn stderr $ "syntax: :set prompt <prompt>, currently \"" ++ prompt st ++ "\""
-      else setGHCiState st{ prompt = remQuotes value }
-  where
-     remQuotes ('\"':xs) | not (null xs) && last xs == '\"' = init xs
-     remQuotes x = x
+      else case value of
+           '\"' : _ -> case reads value of
+                       [(value', xs)] | all isSpace xs ->
+                           setGHCiState (st { prompt = value' })
+                       _ ->
+                           io $ hPutStrLn stderr "Can't parse prompt string. Use Haskell syntax."
+           _ -> setGHCiState (st { prompt = value })
 
 setOptions wds =
    do -- first, deal with the GHCi opts (+s, +t, etc.)