13h9bw
Last Updated: May 11, 2017
·
7.286K
· nobbz
1a4ff0766a653c62e0dab34bacda9873

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

Say Thanks
Respond

5 Responses
Add your response

13919
10001428 1377193235891137 473057529 n

nice!!, thank you for sharing this.

over 1 year ago ·
16302
1032204 100x100

Good. thnx.

over 1 year ago ·
27745

Thank you!

over 1 year ago ·
27747

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| \"")

:color

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

over 1 year ago ·
27748

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
:color
over 1 year ago ·