@@ -7,16 +7,16 @@ import Html exposing (..)
7import Html.Attributes exposing (..)
7import Html.Attributes exposing (..)
8import String
8import String
9import Json.Decode as D
9import Json.Decode as D
10+import Elm.Error as Error
16−main : Program D.Value Model ()
18 Browser.fullscreen
18 Browser.fullscreen
19− { init = \env -> (D.decodeValue decodeExit env.flags, Cmd.none)
19+ { init = \env -> (D.decodeValue Error.decoder env.flags, Cmd.none)
20 , update = \_ exit -> (exit, Cmd.none)
20 , update = \_ exit -> (exit, Cmd.none)
21 , view = view
21 , view = view
22 , subscriptions = \_ -> Sub.none
22 , subscriptions = \_ -> Sub.none
@@ -25,26 +25,10 @@ main =
38−decodeExit : D.Decoder Exit
47−view : Model -> Browser.View msg
31+view : Result D.Error Error.Error -> Browser.View msg
48view result =
32view result =
49 { title = "Problem!"
33 { title = "Problem!"
@@ -52,13 +36,13 @@ view result =
52 Err err ->
36 Err err ->
53 [ text (D.errorToString err) ]
37 [ text (D.errorToString err) ]
55− Ok exit ->
39+ Ok error ->
56− [ viewExit exit ]
40+ [ viewError error ]
60−viewExit : Exit -> Html msg
44+viewError : Error.Error -> Html msg
61−viewExit exit =
45+viewError error =
63 [ style "width" "100%"
47 [ style "width" "100%"
64 , style "min-height" "100%"
48 , style "min-height" "100%"
@@ -71,10 +55,114 @@ viewExit exit =
73 [ style "display" "block"
57 [ style "display" "block"
74− , style "white-space" "pre"
58+ , style "white-space" "pre-wrap"
75 , style "background-color" "rgb(39, 40, 34)"
59 , style "background-color" "rgb(39, 40, 34)"
76 , style "padding" "2em"
60 , style "padding" "2em"
78− [ text "TODO"
62+ (viewErrorHelp error)
66+viewErrorHelp : Error.Error -> List (Html msg)
69+ Error.GeneralProblem { path, title, message } ->
72+ Error.ModuleProblems badModules ->
73+ List.map viewBadModule badModules
76+viewBadModule : Error.BadModule -> Html msg
77+viewBadModule { path, name, problems } =
78+ span [] (List.map (viewProblem path) problems)
81+viewProblem : String -> Error.Problem -> Html msg
82+viewProblem filePath problem =
85+ 76 - String.length problem.title
88+ "-- " ++ problem.title ++ " " ++ String.padLeft leftover '-' (" " ++ filePath) ++ "\n\n"
91+ ( span [ style "color" "cyan" ] [ text header ]
92+ :: viewMessage problem.message
100+viewMessage : List Error.Chunk -> List (Html msg)
110+ Error.Unstyled string ->
113+ Error.Styled style string ->
114+ span (styleToAttrs style) [ text string ]
116+ htmlChunk :: viewMessage others
119+styleToAttrs : Error.Style -> List (Attribute msg)
120+styleToAttrs { bold, underline, color } =
121+ addBold bold <| addUnderline underline <| addColor color []
124+addBold : Bool -> List (Attribute msg) -> List (Attribute msg)
127+ style "font-weight" "bold" :: attrs
132+addUnderline : Bool -> List (Attribute msg) -> List (Attribute msg)
133+addUnderline bool attrs =
135+ style "text-decoration" "underline" :: attrs
140+addColor : Maybe Error.Color -> List (Attribute msg) -> List (Attribute msg)
141+addColor maybeColor attrs =
147+ style "color" (colorToCss color) :: attrs
150+colorToCss : Error.Color -> String
155+ Error.Magenta -> "magenta"
156+ Error.MAGENTA -> "magenta"
157+ Error.Yellow -> "yellow"
158+ Error.YELLOW -> "yellow"
159+ Error.Green -> "green"
160+ Error.GREEN -> "green"
161+ Error.Cyan -> "cyan"
162+ Error.CYAN -> "cyan"
163+ Error.Blue -> "blue"
164+ Error.BLUE -> "blue"
165+ Error.White -> "white"
166+ Error.WHITE -> "white"
167+ Error.Black -> "black"
168+ Error.BLACK -> "black"