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

  • What version of `ghci` do you have? What happens if you replace the function with something that prints some strong? Is it executed? – Mikel Dec 07 '12 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"`. – Sardathrion - against SE abuse Dec 11 '12 at 08:01

2 Answers2

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

Mikel
  • 56,387
  • 13
  • 130
  • 149
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

Somebody
  • 11
  • 1