@@ -0,0 +1,217 @@
1+port module Errors exposing (main)
6+import Html exposing (..)
7+import Html.Attributes exposing (..)
8+import Html.Events exposing (onClick)
10+import Json.Decode as D
11+import Elm.Error as Error
18+port jumpTo : Error.Region -> Cmd msg
27+ { init = \flags -> (D.decodeValue Error.decoder flags, Cmd.none)
28+ , update = \region result -> (result, jumpTo region)
30+ , subscriptions = \_ -> Sub.none
34+type alias Msg = Error.Region
41+view : Result D.Error Error.Error -> Browser.Document Msg
47+ [ text (D.errorToString err) ]
54+viewError : Error.Error -> Html Msg
57+ [ style "width" "calc(100% - 4em)"
58+ , style "min-height" "calc(100% - 4em)"
59+ , style "font-family" "monospace"
60+ , style "white-space" "pre-wrap"
61+ , style "background-color" "black"
62+ , style "color" "rgb(233,235,235)"
63+ , style "padding" "2em"
65+ (viewErrorHelp error)
68+viewErrorHelp : Error.Error -> List (Html Msg)
71+ Error.GeneralProblem { title, message } ->
72+ viewHeader title Nothing :: viewMessage message
74+ Error.ModuleProblems badModules ->
75+ viewBadModules badModules
82+viewHeader : String -> Maybe Error.Region -> Html Msg
83+viewHeader title maybeRegion =
86+ span [ style "color" "rgb(51,187,200)" ]
87+ [ text <| "-- " ++ title ++ " "
88+ , text <| String.repeat (76 - String.length title) "-"
93+ span [ style "color" "rgb(51,187,200)" ]
94+ [ text <| "-- " ++ title ++ " "
95+ , text <| String.repeat (60 - String.length title) "-"
98+ [ style "cursor" "pointer"
99+ , style "text-decoration" "underline"
102+ [ text "Jump To Problem"
112+viewBadModules : List Error.BadModule -> List (Html Msg)
113+viewBadModules badModules =
119+ [viewBadModule badModule]
122+ viewBadModule a :: viewSeparator a.name b.name :: viewBadModules (b :: cs)
125+viewBadModule : Error.BadModule -> Html Msg
126+viewBadModule { problems } =
127+ span [] (List.map viewProblem problems)
130+viewProblem : Error.Problem -> Html Msg
131+viewProblem problem =
132+ span [] (viewHeader problem.title (Just problem.region) :: viewMessage problem.message)
135+viewSeparator : String -> String -> Html msg
136+viewSeparator before after =
137+ span [ style "color" "rgb(211,56,211)" ]
139+ String.padLeft 80 ' ' (before ++ " ↑ ") ++ "\n" ++
140+ "====o======================================================================o====\n" ++
141+ " ↓ " ++ after ++ "\n\n\n"
149+viewMessage : List Error.Chunk -> List (Html msg)
159+ Error.Unstyled string ->
162+ Error.Styled style string ->
163+ span (styleToAttrs style) [ text string ]
165+ htmlChunk :: viewMessage others
168+styleToAttrs : Error.Style -> List (Attribute msg)
169+styleToAttrs { bold, underline, color } =
170+ addBold bold <| addUnderline underline <| addColor color []
173+addBold : Bool -> List (Attribute msg) -> List (Attribute msg)
176+ style "font-weight" "bold" :: attrs
181+addUnderline : Bool -> List (Attribute msg) -> List (Attribute msg)
182+addUnderline bool attrs =
184+ style "text-decoration" "underline" :: attrs
189+addColor : Maybe Error.Color -> List (Attribute msg) -> List (Attribute msg)
190+addColor maybeColor attrs =
196+ style "color" (colorToCss color) :: attrs
199+colorToCss : Error.Color -> String
202+ Error.Red -> "rgb(194,54,33)"
203+ Error.RED -> "rgb(252,57,31)"
204+ Error.Magenta -> "rgb(211,56,211)"
205+ Error.MAGENTA -> "rgb(249,53,248)"
206+ Error.Yellow -> "rgb(173,173,39)"
207+ Error.YELLOW -> "rgb(234,236,35)"
208+ Error.Green -> "rgb(37,188,36)"
209+ Error.GREEN -> "rgb(49,231,34)"
210+ Error.Cyan -> "rgb(51,187,200)"
211+ Error.CYAN -> "rgb(20,240,240)"
212+ Error.Blue -> "rgb(73,46,225)"
213+ Error.BLUE -> "rgb(88,51,255)"
214+ Error.White -> "rgb(203,204,205)"
215+ Error.WHITE -> "rgb(233,235,235)"
216+ Error.Black -> "rgb(0,0,0)"
217+ Error.BLACK -> "rgb(129,131,131)"