on master help sign in
Merge pull request #1746 from soimort/fix-colourisePrompt

Indicate the end of each escape sequence in the prompt string

commitc87ea77598aa51e1ff5d9baddc9cd92c54c2251f authorEdwin Brady <edwin.brady@gmail.com> dateMon 24 Nov 2014, 11:21 (12 years ago) parent02b6087ef1bd24
1 file changed+12−1
src/Idris/Colours.hs+12−1
src/Idris/Colours.hs+12−1
@@ -52,6 +52,17 @@ colourise (IdrisColour c v u b i) str = setSGRCode sgr ++ str ++ setSGRCode [Res
5252 fg Nothing = []
5353 fg (Just c) = [SetColor Foreground (if v then Vivid else Dull) c]
5454
55+-- | Set the colour of a string using POSIX escape codes, with trailing '\STX' denoting the end
56+-- (required by Haskeline in the prompt string)
57+colouriseWithSTX :: IdrisColour -> String -> String
58+colouriseWithSTX (IdrisColour c v u b i) str = setSGRCode sgr ++ "\STX" ++ str ++ setSGRCode [Reset] ++ "\STX"
59+ where sgr = fg c ++
60+ (if u then [SetUnderlining SingleUnderline] else []) ++
61+ (if b then [SetConsoleIntensity BoldIntensity] else []) ++
62+ (if i then [SetItalicized True] else [])
63+ fg Nothing = []
64+ fg (Just c) = [SetColor Foreground (if v then Vivid else Dull) c]
65+
5566colouriseKwd :: ColourTheme -> String -> String
5667colouriseKwd t = colourise (keywordColour t)
5768
@@ -71,7 +82,7 @@ colouriseData :: ColourTheme -> String -> String
7182colouriseData t = colourise (dataColour t)
7283
7384colourisePrompt :: ColourTheme -> String -> String
74−colourisePrompt t = colourise (promptColour t)
85+colourisePrompt t = colouriseWithSTX (promptColour t)
7586
7687colouriseKeyword :: ColourTheme -> String -> String
7788colouriseKeyword t = colourise (keywordColour t)