Search code examples
haskellpromptghci

Setting the ghci prompt with colors


I try to use terminal colors within my ghci prompt.

So when I open ghci and try to:

Prelude> :set prompt '\[\033[1haskell > \033[0m\]'
'\[\033[1\]haskell> \[\033[0m\] '

I know that these codes are interpreted by bash with echo and the -e flag. But how can I do this within ghci?


Solution

  • According to https://wiki.haskell.org/GHCi_in_colour, you can use

    :set prompt "\ESC[33m\STXhaskell > \ESC[m\STX"
    

    A few notes of explanation:

    1. Only a double-quoted string is treated specially; single quotes are treated as part of the prompt.
    2. The double-quoted string follows Haskell practice.
    3. \STX corresponds to the \] of your bash prompt; it's not clear why GHCi does not require the equivalent of \[ as well. (Perhaps it does; I haven't played with this much.). See http://trac.haskell.org/haskeline/wiki/ControlSequencesInPrompt for an explanation.