#2652: fancier prompts for ghci
------------------------------+---------------------------------------------
 Reporter:  jsnx              |          Owner:                  
     Type:  feature request   |         Status:  new             
 Priority:  normal            |      Milestone:  6.10 branch     
Component:  GHCi              |        Version:  6.8.3           
 Severity:  normal            |     Resolution:                  
 Keywords:                    |     Difficulty:  Unknown         
 Testcase:                    |   Architecture:  Unknown/Multiple
       Os:  Unknown/Multiple  |  
------------------------------+---------------------------------------------
Comment (by jsnx):

 I've integrated this with GHC 6.8.3 sources. There's not much to it.

 {{{
 #!diff
 --- 0/compiler/ghci/InteractiveUI.hs    2008-06-16 10:27:16.000000000
 -0700
 +++ 1/compiler/ghci/InteractiveUI.hs    2008-10-28 02:57:03.000000000
 -0700
 @@ -1447,11 +1447,19 @@
  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 }
 +      then io $ hPutStrLn stderr $
 +        "syntax: :set prompt <prompt>, currently \"" ++ prompt st ++ "\""
 +      else setGHCiState st{ prompt = read . handleQuotes $ value }
    where
 -     remQuotes ('\"':xs) | not (null xs) && last xs == '\"' = init xs
 -     remQuotes x = x
 +     -- the prompt can be input with quote marks and string escaping, or
 +     -- with plain character escaping.
 +     handleQuotes s | length s > 2 && last s == '"' && head s == '"' = s
 +                    | otherwise = wrap . escapeQuotes $ s
 +     wrap = ("\"" ++) . (++ "\"")
 +     escapeQuotes ('\\':'"':r) = '\\' : '"' : escapeQuotes r
 +     escapeQuotes ('"':r) = '\\' : '"' : escapeQuotes r
 +     escapeQuotes (c:r) = c : escapeQuotes r
 +     escapeQuotes [ ] = [ ]

  setOptions wds =
     do -- first, deal with the GHCi opts (+s, +t, etc.)

 }}}

 With quotes, it uses string escapes and retains spaces:

 {{{
 Prelude> :set prompt "{-  %s\n -} "
 {-  Prelude
  -}
 }}}

 Without quotes, it uses only character escapes:

 {{{
 Prelude> :set prompt {-\SP\SP%s\n\SP-}\SP
 {-  Prelude
  -}
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2652#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to