使用这个方法可以得到漂亮的 GHCI 颜色,我没有得到任何颜色。但是,我的终端是启用了 256 色的 urxvt,并且 TERM 是xterm-256color
。知道我可能错过了什么吗?
我的 ~/.ghci 内容如下:
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 "λ "
提示符应如下所示:
答案1
您需要 GHCI 版本 >= 7.6.1 才能使用该-interactive-print
选项。
Reddit:GHCi 中的漂亮输出(评论中的 HOWTO)
我正在美化我的 GHCi,并在 GHC 7.6 (-interactive-print) 中发现了一个新标志
里程碑:7.6.1
答案2
您需要:set -XNoMonomorphismRestriction
先放置let myPrint = ...
,并使用 GHCi 7.6.3 进行测试。
或者,不带 -XNoMonomorphismRestriction:
let myPrint :: (Show a) => a -> IO (); myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow
完整的 .ghci(对原始 Reddit 帖子中的解决方案进行了轻微修改):http://pastebin.com/ry9JyDd9