mirror of
https://github.com/github/semantic.git
synced 2025-01-01 19:55:34 +03:00
Factor out the caret padding.
This commit is contained in:
parent
66023c80de
commit
b83a38ecaa
@ -54,10 +54,11 @@ formatError includeSource colourize blob@Blob{..} Error{..}
|
|||||||
showExcerpt :: Colourize -> Span -> Blob -> ShowS
|
showExcerpt :: Colourize -> Span -> Blob -> ShowS
|
||||||
showExcerpt colourize Span{..} Blob{..}
|
showExcerpt colourize Span{..} Blob{..}
|
||||||
= showString (unpack context) . (if "\n" `isSuffixOf` context then id else showChar '\n')
|
= showString (unpack context) . (if "\n" `isSuffixOf` context then id else showChar '\n')
|
||||||
. showString (replicate (succ (posColumn spanStart + lineNumberDigits)) ' ') . withSGRCode colourize [SetColor Foreground Vivid Green] (showChar '^') . showChar '\n'
|
. showString (replicate (caretPaddingWidth + lineNumberDigits) ' ') . withSGRCode colourize [SetColor Foreground Vivid Green] (showChar '^') . showChar '\n'
|
||||||
where context = maybe "\n" (sourceBytes . sconcat) (nonEmpty [ fromUTF8 (pack (showLineNumber i)) <> fromUTF8 ": " <> l | (i, l) <- zip [1..] (sourceLines blobSource), inRange (posLine spanStart - 2, posLine spanStart) i ])
|
where context = maybe "\n" (sourceBytes . sconcat) (nonEmpty [ fromUTF8 (pack (showLineNumber i)) <> fromUTF8 ": " <> l | (i, l) <- zip [1..] (sourceLines blobSource), inRange (posLine spanStart - 2, posLine spanStart) i ])
|
||||||
showLineNumber n = let s = show n in replicate (lineNumberDigits - length s) ' ' <> s
|
showLineNumber n = let s = show n in replicate (lineNumberDigits - length s) ' ' <> s
|
||||||
lineNumberDigits = succ (floor (logBase 10 (fromIntegral (posLine spanStart) :: Double)))
|
lineNumberDigits = succ (floor (logBase 10 (fromIntegral (posLine spanStart) :: Double)))
|
||||||
|
caretPaddingWidth = succ (posColumn spanStart)
|
||||||
|
|
||||||
withSGRCode :: Colourize -> [SGR] -> ShowS -> ShowS
|
withSGRCode :: Colourize -> [SGR] -> ShowS -> ShowS
|
||||||
withSGRCode useColour code content =
|
withSGRCode useColour code content =
|
||||||
|
Loading…
Reference in New Issue
Block a user