1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit.Help
21import qualified Data.List as List
22import qualified Data.Text as Text
23import GHC.IO.Handle (hIsTerminalDevice)
24import System.IO (Handle, hPutStr, stderr, stdout)
25import qualified Text.PrettyPrint.ANSI.Leijen as P
26import Text.PrettyPrint.ANSI.Leijen ((<>),(<+>))
28import qualified Elm.Compiler as Compiler
29import qualified Elm.Package as Pkg
30import qualified Json.Encode as Encode
31import qualified Reporting.Exit.Compile as Compile
39 = CompilerReport Compile.Exit [Compile.Exit]
42 , _path :: Maybe FilePath
47report :: String -> Maybe FilePath -> String -> [P.Doc] -> Report
48report title path startString others =
49 Report title path $ stack (reflow startString:others)
52docReport :: String -> Maybe FilePath -> P.Doc -> [P.Doc] -> Report
53docReport title path startDoc others =
54 Report title path $ stack (startDoc:others)
57jsonReport :: String -> Maybe FilePath -> P.Doc -> Report
62compilerReport :: Compile.Exit -> [Compile.Exit] -> Report
71reportToDoc :: Report -> P.Doc
74 CompilerReport e es ->
77 Report title maybePath message ->
80 replicate (max 1 (80 - n)) '-'
85 makeDashes (4 + length title)
88 makeDashes (5 + length title + length path) ++ " " ++ path
92 "--" <+> P.text title <+> P.text errorBarEnd
94 stack [errorBar, message, ""]
101reportToJson :: Report -> Encode.Value
102reportToJson report_ =
104 CompilerReport e es ->
106 [ ("type", Encode.text "compile-errors")
107 , ("errors", Encode.list Compile.toJson (e:es))
110 Report title maybePath message ->
113 P.displayS (P.renderPretty 1 80 message) ""
116 [ ("type", Encode.text "error")
117 , ("path", maybe Encode.null (Encode.text . Text.pack) maybePath)
118 , ("title", Encode.text (Text.pack title))
119 , ("message", Encode.text (Text.pack messageString))
127hintLink :: String -> String
129 "<https://github.com/elm-lang/elm-compiler/blob/"
130 ++ Pkg.versionToString Compiler.version
131 ++ "/hints/" ++ hintName ++ ".md>"
138stack :: [P.Doc] -> P.Doc
142 error "Do not use `stack` on empty lists."
145 List.foldl' verticalAppend doc docs
148verticalAppend :: P.Doc -> P.Doc -> P.Doc
150 a <> P.hardline <> P.hardline <> b
153reflow :: String -> P.Doc
155 P.fillSep (map P.text (words paragraph))
158note :: String -> P.Doc
161 (P.underline "Note" <> ":") : map P.text (words details)
168toString :: P.Doc -> String
170 P.displayS (P.renderPretty 1 80 (P.plain doc)) ""
173toStdout :: P.Doc -> IO ()
178toStderr :: P.Doc -> IO ()
183toHandle :: Handle -> P.Doc -> IO ()
185 do isTerminal <- hIsTerminalDevice handle
187 then P.displayIO handle (P.renderPretty 1 80 doc)
188 else hPutStr handle (toString doc)
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