1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
10import Data.Aeson ((.=))
11import qualified Data.Aeson.Types as Json
13import Elm.Utils ((|>))
14import qualified Reporting.Region as R
19 , _highlight :: Maybe R.Region
25simple :: String -> String -> String -> Report
26simple title pre post =
27 Report title Nothing pre post
30toString :: String -> R.Region -> Report -> String -> String
31toString location region (Report title highlight pre post) source =
33 [ messageBar title location
35 , grabRegion highlight region source ++ "\n"
36 , if null post then "\n" else post ++ "\n\n\n"
40toJson :: [Json.Pair] -> Report -> (Maybe R.Region, [Json.Pair])
41toJson extraFields (Report title subregion pre post) =
49 (subregion, fields ++ extraFields)
54messageBar :: String -> String -> String
55messageBar tag location =
56 let usedSpace = 4 + length tag + 1 + length location
59 ++ replicate (max 1 (80 - usedSpace)) '-'
60 ++ " " ++ location ++ "\n\n"
65grabRegion :: Maybe R.Region -> R.Region -> String -> String
66grabRegion maybeSubRegion (R.Region start end) source =
68 (R.Position startLine startColumn) = start
69 (R.Position endLine endColumn) = end
73 |> drop (startLine - 1)
74 |> take (endLine - startLine + 1)
81 singleLineRegion startLine sourceLine $
82 case maybeSubRegion of
84 (0, startColumn, endColumn, length sourceLine)
86 Just (R.Region s e) ->
87 (startColumn, R.column s, R.column e, endColumn)
92 replicate (startColumn - 1) ' '
93 ++ drop (startColumn - 1) firstLine
96 take (endColumn) (last rest)
98 focusedRelevantLines =
99 filteredFirstLine : init rest ++ [filteredLastLine]
102 length (show (endLine + 1))
106 (addLineNumber maybeSubRegion lineNumbersWidth)
107 [startLine - 1 .. endLine + 1]
108 ("" : focusedRelevantLines ++ [""])
110 unlines numberedLines
113addLineNumber :: Maybe R.Region -> Int -> Int -> String -> String
114addLineNumber maybeSubRegion width n line =
117 if n < 0 then " " else show n
119 spacer (R.Region start end) =
120 if R.line start <= n && n <= R.line end
124 replicate (width - length number) ' ' ++ number
125 ++ "|" ++ maybe " " spacer maybeSubRegion
129singleLineRegion :: Int -> String -> (Int, Int, Int, Int) -> String
130singleLineRegion lineNum sourceLine (start, innerStart, innerEnd, end) =
132 w = length (show (lineNum + 1))
135 addLineNumber Nothing w
138 replicate (innerStart - 1) ' '
139 ++ replicate (max 1 (innerEnd - innerStart)) '^'
144 |> take (end - start + 1)
145 |> (++) (replicate (start - 1) ' ')
148 [ number (lineNum-1) ""
149 , number lineNum trimmedSourceLine
150 , 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