Ticket #2652 (closed feature request: fixed)

Opened 4 years ago

Last modified 3 years ago

fancier prompts for ghci

Reported by: jsnx Owned by: igloo
Priority: normal Milestone: 6.10 branch
Component: GHCi Version: 6.8.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

It'd be nice to put newlines in a GHCi prompt using standard escape sequences.

It is really unnecessary to support anything more than %s as a formatting directive.

Attachments

rubbish Download (1.2 KB) - added by jsnx 4 years ago.
this is the diff mentioned in comment 3 (turns out the diff is not extractable in this version of trac)

Change History

  Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.10 branch

  Changed 4 years ago by igloo

  • component changed from Compiler to GHCi

  Changed 4 years ago by jsnx

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

  • compiler/ghci/InteractiveUI.hs

    0 1  
    14471447setPrompt value = do 
    14481448  st <- getGHCiState 
    14491449  if null value 
    1450       then io $ hPutStrLn stderr $ "syntax: :set prompt <prompt>, currently \"" ++ prompt st ++ "\"" 
    1451       else setGHCiState st{ prompt = remQuotes value } 
     1450      then io $ hPutStrLn stderr $ 
     1451        "syntax: :set prompt <prompt>, currently \"" ++ prompt st ++ "\"" 
     1452      else setGHCiState st{ prompt = read . handleQuotes $ value } 
    14521453  where 
    1453      remQuotes ('\"':xs) | not (null xs) && last xs == '\"' = init xs 
    1454      remQuotes x = x 
     1454     -- the prompt can be input with quote marks and string escaping, or 
     1455     -- with plain character escaping. 
     1456     handleQuotes s | length s > 2 && last s == '"' && head s == '"' = s 
     1457                    | otherwise = wrap . escapeQuotes $ s 
     1458     wrap = ("\"" ++) . (++ "\"") 
     1459     escapeQuotes ('\\':'"':r) = '\\' : '"' : escapeQuotes r 
     1460     escapeQuotes ('"':r) = '\\' : '"' : escapeQuotes r 
     1461     escapeQuotes (c:r) = c : escapeQuotes r 
     1462     escapeQuotes [ ] = [ ] 
    14551463 
    14561464setOptions wds = 
    14571465   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
 -}  

Changed 4 years ago by jsnx

this is the diff mentioned in comment 3 (turns out the diff is not extractable in this version of trac)

  Changed 4 years ago by igloo

  • owner set to igloo

follow-up: ↓ 6   Changed 4 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Thanks for the patch! I've applied a slightly different version: Prompt strings starting with " are treated as Haskell strings; otherwise they are treated as literal strings.

in reply to: ↑ 5   Changed 3 years ago by jsnx

  • status changed from closed to reopened
  • resolution fixed deleted

Replying to igloo:

Thanks for the patch! I've applied a slightly different version: Prompt strings starting with " are treated as Haskell strings; otherwise they are treated as literal strings.

Is this going to be in 6.12? I've noticed it's not included in 6.10.

  Changed 3 years ago by igloo

Yes, this patch is only in the HEAD (which will become 6.12):

Fri Oct 31 14:52:27 GMT 2008  Ian Lynagh <igloo@earth.li>
  * :set prompt now understand Haskell String syntax; trace #2652

  Changed 3 years ago by igloo

  • status changed from reopened to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.