moduleLanguage.Haskell.HsColour.Colourise(moduleLanguage.Haskell.HsColour.ColourHighlight,ColourPrefs(..),readColourPrefs,defaultColourPrefs,colourise)whereimportLanguage.Haskell.HsColour.ColourHighlightimportLanguage.Haskell.HsColour.Classify(TokenType(..))importIO(hPutStrLn,stderr)importSystem(getEnv)importList-- | Colour preferences.dataColourPrefs=ColourPrefs{keyword,keyglyph,layout,comment,conid,varid,conop,varop,string,char,number,cpp,selection,variantselection,definition::[Highlight]}deriving(Eq,Show,Read)defaultColourPrefs=ColourPrefs{keyword=[ForegroundGreen,Underscore],keyglyph=[ForegroundRed],layout=[ForegroundCyan],comment=[ForegroundBlue,Italic],conid=[Normal],varid=[Normal],conop=[ForegroundRed,Bold],varop=[ForegroundCyan],string=[ForegroundMagenta],char=[ForegroundMagenta],number=[ForegroundMagenta],cpp=[ForegroundMagenta,Dim],selection=[Bold,ForegroundMagenta],variantselection=[Dim,ForegroundRed,Underscore],definition=[ForegroundBlue]}-- NOTE, should we give a warning message on a failed reading?parseColourPrefs::String->String->IOColourPrefsparseColourPrefsfilex=casereadsxof(res,_):_->returnres_->dohPutStrLnstderr("Could not parse colour prefs from "++file++": reverting to defaults")returndefaultColourPrefs-- | Read colour preferences from .hscolour file in the current directory, or failing that,-- from \$HOME\/.hscolour, and failing that, returns a default set of prefs.readColourPrefs::IOColourPrefsreadColourPrefs=catch(doval<-readFile".hscolour"parseColourPrefs".hscolour"val)(\_->catch(dohome<-getEnv"HOME"val<-readFile(home++"/.hscolour")parseColourPrefs(home++"/.hscolour")val)(\_->returndefaultColourPrefs))-- | Convert token classification to colour highlights.colourise::ColourPrefs->TokenType->[Highlight]colouriseprefSpace=[Normal]colouriseprefComment=commentprefcolouriseprefKeyword=keywordprefcolouriseprefKeyglyph=keyglyphprefcolouriseprefLayout=layoutprefcolouriseprefConid=conidprefcolouriseprefVarid=varidprefcolouriseprefConop=conopprefcolouriseprefVarop=varopprefcolouriseprefString=stringprefcolouriseprefChar=charprefcolouriseprefNumber=numberprefcolouriseprefCpp=cppprefcolouriseprefError=selectionprefcolouriseprefDefinition=definitionpref