6

Using this method to get a pretty GHCI colours, I am not getting any colours whatsoever. However, my terminal is a urxvt with 256 colours enabled and TERM is xterm-256color. Any idea what I could have missed?

My ~/.ghci reads:

import qualified IPPrint
import qualified Language.Haskell.HsColour as HsColour
import qualified Language.Haskell.HsColour.Colourise as HsColour
import qualified Language.Haskell.HsColour.Output as HsColour

let myColourPrefs = HsColour.defaultColourPrefs { HsColour.conid = [HsColour.Foreground HsColour.Yellow, HsColour.Bold], HsColour.conop = [HsColour.Foreground HsColour.Yellow], HsColour.string = [HsColour.Foreground HsColour.Green], HsColour.char = [HsColour.Foreground HsColour.Cyan], HsColour.number = [HsColour.Foreground HsColour.Red, HsColour.Bold], HsColour.layout = [HsColour.Foreground HsColour.White], HsColour.keyglyph = [HsColour.Foreground HsColour.White] }

let myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow

:set -interactive-print=myPrint
:set -XNoMonomorphismRestriction
:set prompt "λ "

The prompt should look like this: haskell ghci colour prompt

2
  • What version of ghci do you have? What happens if you replace the function with something that prints some strong? Is it executed? Commented Dec 7, 2012 at 21:28
  • @Mikel: The Glorious Glasgow Haskell Compilation System, version 7.4.1 and replacing myPrint does not seem to call it at all -- I just changed it to let myPrint = putStrLn "ook". Commented Dec 11, 2012 at 8:01

2 Answers 2

2

You need GHCI version >= 7.6.1 for the -interactive-print option.

Reddit: Pretty Output in GHCi (HOWTO in comments)

I was prettying up my GHCi and found a new flag in GHC 7.6 (-interactive-print)

[GHC] #5461

Milestone: 7.6.1

1
  • Has anybody this working with recent ghci versions? Not working for me with 7.10.2 Commented Feb 15, 2016 at 10:40
1

You need to place :set -XNoMonomorphismRestriction before let myPrint = ..., tested using GHCi 7.6.3.

Alternatively, without -XNoMonomorphismRestriction:

let myPrint :: (Show a) => a -> IO (); myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow

Full .ghci(slight modification of the solution in the original Reddit post): http://pastebin.com/ry9JyDd9

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.