1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
10import Data.Aeson ((.=))
11import qualified Data.Aeson.Types as Json
13import qualified Reporting.Region as R
18 , _highlight :: Maybe R.Region
24simple :: String -> String -> String -> Report
25simple title pre post =
26 Report title Nothing pre post
29toString :: String -> R.Region -> Report -> String -> String
30toString location region (Report title highlight pre post) source =
32 [ messageBar title location
34 , grabRegion highlight region source ++ "\n"
35 , if null post then "\n" else post ++ "\n\n\n"
39toJson :: [Json.Pair] -> Report -> (Maybe R.Region, [Json.Pair])
40toJson extraFields (Report title subregion pre post) =
48 (subregion, fields ++ extraFields)
53messageBar :: String -> String -> String
54messageBar tag location =
55 let usedSpace = 4 + length tag + 1 + length location
58 ++ replicate (max 1 (80 - usedSpace)) '-'
59 ++ " " ++ location ++ "\n\n"
64grabRegion :: Maybe R.Region -> R.Region -> String -> String
65grabRegion maybeSubRegion (R.Region start end) source =
67 (R.Position startLine startColumn) = start
68 (R.Position endLine endColumn) = end
74 |> drop (startLine - 1)
75 |> take (endLine - startLine + 1)
82 singleLineRegion startLine sourceLine $
83 case maybeSubRegion of
85 (0, startColumn, endColumn, length sourceLine)
87 Just (R.Region s e) ->
88 (startColumn, R.column s, R.column e, endColumn)
93 replicate (startColumn - 1) ' '
94 ++ drop (startColumn - 1) firstLine
97 take (endColumn) (last rest)
99 focusedRelevantLines =
100 filteredFirstLine : init rest ++ [filteredLastLine]
103 length (show (endLine + 1))
107 (addLineNumber maybeSubRegion lineNumbersWidth)
108 [startLine - 1 .. endLine + 1]
109 ("" : focusedRelevantLines ++ [""])
111 unlines numberedLines
114addLineNumber :: Maybe R.Region -> Int -> Int -> String -> String
115addLineNumber maybeSubRegion width n line =
118 if n < 0 then " " else show n
120 spacer (R.Region start end) =
121 if R.line start <= n && n <= R.line end
125 replicate (width - length number) ' ' ++ number
126 ++ "|" ++ maybe " " spacer maybeSubRegion
130singleLineRegion :: Int -> String -> (Int, Int, Int, Int) -> String
131singleLineRegion lineNum sourceLine (start, innerStart, innerEnd, end) =
133 w = length (show (lineNum + 1))
136 addLineNumber Nothing w
139 replicate (innerStart - 1) ' '
140 ++ replicate (max 1 (innerEnd - innerStart)) '^'
147 |> take (end - start + 1)
148 |> (++) (replicate (start - 1) ' ')
151 [ number (lineNum-1) ""
152 , number lineNum trimmedSourceLine
153 , number (lineNum+1) underline
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