例如,在控制台中将-1显示为1:
当选择文本时,可以看到它实际上是-1:
.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 :: (Show a) => a -> IO (); myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow
:set -interactive-print=myPrint
:set prompt "\ESC[33m\STXλ> \ESC[m\STX"
:set prompt-cont " | "
:set +m
更新
关注http://teh.id.au/posts/2017/02/13/interactive-print/index.html后,结果会更好但仍可以改进:
import Text.Show.Pretty (ppShow)
import Language.Haskell.HsColour
import Language.Haskell.HsColour.Colourise
let colorPrint = putStrLn . hscolour TTY defaultColourPrefs False False "" False . ppShow
:set -interactive-print=colorPrint
更新
问题在于前缀为负数的短划线被错误分类为注释。
答案 0 :(得分:1)
因为没有一种简单的方法可以将补丁提交到实际问题中,所以我将注释颜色设置为与数字相同,以便可读:
HsColour.comment = [HsColour.Foreground HsColour.Red, HsColour.Bold]
.ghci
:load ~/.ghci.hs
:set -interactive-print=myPrint
:set prompt "\ESC[33m\STXλ> \ESC[m\STX"
:set prompt-cont " | "
:set +m
.ghci.hs
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
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]
, HsColour.comment = [HsColour.Foreground HsColour.Red, HsColour.Bold] }
myPrint :: (Show a) => a -> IO ()
myPrint = putStrLn . HsColour.hscolour (HsColour.TTYg HsColour.XTerm256Compatible) myColourPrefs False False "" False . IPPrint.pshow