How to set GHCi prompt to display modules separated by a custom separator?

Viewed 162
1 Answers

You can use prompt-function instead of prompt to run more advanced Haskell functions for the prompt. Here's an example ghci.conf for your second prompt:

:{
prompter :: [String] -> Int -> IO String
prompter modules line = return $
    concat [ "\ESC[33m\STX["
           , Data.List.intercalate ", " modules
           , "]\ESC[38;5;86m\STX \x03BB > \ESC[0m\STX"
           ]
:}

:set prompt-function prompter

Or, for numbers, you can utilize zipWith:

:{
prompter :: [String] -> Int -> IO String
prompter modules line = return $
    concat [ "\ESC[33m\STX["
           -- this is the only line that changed
           , Data.List.intercalate ", " $ zipWith (\n m -> concat [show n, ".", m]) [1..] modules
           , "]\ESC[38;5;86m\STX \x03BB > \ESC[0m\STX"
           ]
:}

:set prompt-function prompter

I'll leave it as an exercise to write the continuation line, but it's very similar and just involves prompt-cont-function.

Related