mirror of
https://github.com/github/semantic.git
synced 2024-12-21 05:41:54 +03:00
Add some combinators for working with SGR codes.
This commit is contained in:
parent
8ab1c25f30
commit
aca843ed3f
@ -167,7 +167,7 @@ data ErrorCause symbol
|
||||
-- | Pretty-print an Error with reference to the source where it occurred.
|
||||
showError :: Show symbol => Source.Source -> Error symbol -> ShowS
|
||||
showError source Error{..}
|
||||
= showSourcePos errorPos . showString ": " . showString (setSGRCode [SetColor Foreground Vivid Red]) . showString "error" . showString (setSGRCode []) . showString ": " . showExpectation . showChar '\n'
|
||||
= showSourcePos errorPos . showString ": " . withSGRCode [SetColor Foreground Vivid Red] "error" . showString ": " . showExpectation . showChar '\n'
|
||||
. showString context -- actualLines results include line endings, so no newline here
|
||||
. showString (replicate (succ (Info.column errorPos + lineNumberDigits)) ' ') . showChar '^' . showChar '\n'
|
||||
. showString (prettyCallStack callStack) . showChar '\n'
|
||||
@ -179,6 +179,8 @@ showError source Error{..}
|
||||
context = maybe "\n" (toS . Source.sourceText . sconcat) (nonEmpty [ Source.Source (toS (showLineNumber i)) <> Source.Source ": " <> l | (i, l) <- zip [1..] (Source.actualLines source), inRange (Info.line errorPos - 2, Info.line errorPos) i ])
|
||||
showLineNumber n = let s = show n in replicate (lineNumberDigits - length s) ' ' <> s
|
||||
lineNumberDigits = succ (floor (logBase 10 (fromIntegral (Info.line errorPos) :: Double)))
|
||||
showSGRCode = showString . setSGRCode
|
||||
withSGRCode code string = showSGRCode code . showString string . showSGRCode []
|
||||
|
||||
showSymbols :: Show symbol => [symbol] -> ShowS
|
||||
showSymbols [] = showString "end of input nodes"
|
||||
|
Loading…
Reference in New Issue
Block a user