1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Render.Code
7import Control.Applicative ((<|>))
8import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), hardline, dullred, empty, text)
10import qualified Reporting.Region as R
13(|>) :: a -> (a -> b) -> b
18(<==>) :: Doc -> Doc -> Doc
23render :: Maybe R.Region -> R.Region -> String -> Doc
24render maybeSubRegion region@(R.Region start end) source =
26 (R.Position startLine startColumn) = start
27 (R.Position endLine endColumn) = end
31 |> drop (startLine - 1)
32 |> take (endLine - startLine + 1)
39 singleLineRegion startLine sourceLine $
40 case maybeSubRegion of
42 (0, startColumn, endColumn, length sourceLine)
44 Just (R.Region s e) ->
45 (startColumn, R.column s, R.column e, endColumn)
50 replicate (startColumn - 1) ' '
51 ++ drop (startColumn - 1) firstLine
54 take (endColumn) (last rest)
56 focusedRelevantLines =
57 filteredFirstLine : init rest ++ [filteredLastLine]
63 maybeSubRegion <|> Just region
67 (addLineNumber subregion lineNumbersWidth)
68 [startLine .. endLine]
71 foldr (<==>) empty numberedLines
74addLineNumber :: Maybe R.Region -> Int -> Int -> String -> Doc
75addLineNumber maybeSubRegion width n line =
78 if n < 0 then " " else show n
81 replicate (width - length number) ' ' ++ number ++ "│"
83 spacer (R.Region start end) =
84 if R.line start <= n && n <= R.line end then
90 <> maybe (text " ") spacer maybeSubRegion
94singleLineRegion :: Int -> String -> (Int, Int, Int, Int) -> Doc
95singleLineRegion lineNum sourceLine (start, innerStart, innerEnd, end) =
101 text (replicate (innerStart + width + 1) ' ')
103 dullred (text (replicate (max 1 (innerEnd - innerStart)) '^'))
108 |> take (end - start + 1)
109 |> (++) (replicate (start - 1) ' ')
111 addLineNumber Nothing width lineNum trimmedSourceLine
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list