Last Updated: June 03, 2016
· nobbz

Colored GHCi prompt with λ and modules on separate lines

When you take a look at other developers GHCi prompt you can often see a simple prompt like the following:


This is achieved by simply putting the following snippet into ~/.ghci:

:set prompt "\ESC[34mλ> \ESC[m"

Where the \ESC[34m is ANSI-code for a blue foreground color and the simple \ESC[m reverts everything into the defaults.

But since I want to know which modules are loaded into GHCi and which of them are interpreted and which are compiled, I extended the above prompt:

:set prompt "\ESC[1;34m%s\n\ESC[0;34mλ> \ESC[m"

\ESC[1;34m%s\n produces a first line which lists the loaded modules in bold blue, whereas \ESC[0;34mλ> \ESC[m sets the prompt like above, but removes the bold-attribute.

With this new prompt you have everything… There are colors to quickly recognize the last time the prompt was displayed, you have the cool λ that every “real” haskell-programmer must have, and you know which modules are loaded at any given time, and since they are colored you can distinguish the line from other output easily (it helps you to find last prompt also!).

More about ANSI-escape sequences

5 Responses
Add your response

10001428 1377193235891137 473057529 n

nice!!, thank you for sharing this.

over 1 year ago ·
1032204 100x100

Good. thnx.

over 1 year ago ·

Thank you!

11 months ago ·

I wrote little wrapper
You can use it like this

:def color (_ -> return (":set -interactive-print=FunnyPrint.funnyPrint\n:set prompt " ++ FunnyPrint.prompt "λ " "%s" " > " ++ "\n:set prompt2 " ++ FunnyPrint.prompt2 "λ " "" "| "))
:def nocolor (_ -> return ":set -interactive-print=print\n:set prompt \"%s> \"\n:set prompt2 \"%s| \"")


But with newline it don't work. Would be grateful if you may suggest, why.

11 months ago ·

Update: cozy multiline version:

Put next to your ~/.ghc/ghci.conf

-- OverloadedStrings is often useful.
:set -XOverloadedStrings

-- Scoped type variables is often useful so we can specify the types
-- of variables (for example, in lambda expressions).
:set -XScopedTypeVariables

-- useful for import from specified package
:set -XPackageImports

-- Force load dependencies
:set -package funnyprint

-- Show the types of evaluated expressions
:set +t

-- And stats
:set +s

-- Enable multi-line expressions with :{ and :}
:set +m

-- Make the prompt a little more colorful.
-- And pretty-printing values

:def color (\_ -> return (":set -interactive-print=FunnyPrint.funnyPrint\n:set prompt \"" ++ FunnyPrint.prompt "λ " "%s" " ¬\\nλ > " ++ "\"" ++ "\n:set prompt2 \"" ++ FunnyPrint.prompt2 "λ" "" " | " ++ "\""))
:def nocolor (\_ -> return ":set -interactive-print=print\n:set prompt \"%s> \"\n:set prompt2 \"%s| \"")

-- turn fun on
11 months ago ·
Awesome Job

2dab4ece 1845 11e7 83a6 9990ac8546db
Software Developer
Amsterdam, Netherlands
Full Time