Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 234
hgiesel Avatar asked Jul 08 '16 18:07

hgiesel


2 Answers

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.
like image 132
chepner Avatar answered Nov 11 '22 05:11

chepner


Haskell character escape codes are in decimal:

Prelude> :set prompt "\027[31mhaskell>\027[0m "

Putting the same directive in your .ghci file should also work.

like image 20
ErikR Avatar answered Nov 11 '22 03:11

ErikR