@@ -56,6 +56,7 @@ import qualified Text.PrettyPrint.ANSI.Leijen as P
5656import qualified Data.Index as Index
5757import qualified Elm.Package as Pkg
5858import qualified Elm.Version as V
59+import Json.Encode ((==>))
5960import qualified Json.Encode as E
6061import qualified Json.String as Json
6162
@@ -305,10 +306,8 @@ data Color
305306 | WHITE
306307
307308
308−toJsonHelp :: Style -> [a] -> P.SimpleDoc -> [E.Value]
309+toJsonHelp :: Style -> [String] -> P.SimpleDoc -> [E.Value]
309310toJsonHelp style revChunks simpleDoc =
310− error "TODO generate json on errors" style revChunks simpleDoc sgrToStyle encodeColor
311−{-
312311 case simpleDoc of
313312 P.SFail ->
314313 error $
@@ -319,23 +318,18 @@ toJsonHelp style revChunks simpleDoc =
319318 [ encodeChunks style revChunks ]
320319
321320 P.SChar char rest ->
322− toJsonHelp style (TB.singleton char : revChunks) rest
321+ toJsonHelp style ([char] : revChunks) rest
323322
324323 P.SText _ string rest ->
325− toJsonHelp style (TB.fromString string : revChunks) rest
324+ toJsonHelp style (string : revChunks) rest
326325
327326 P.SLine indent rest ->
328− toJsonHelp style (spaces indent : "\n" : revChunks) rest
327+ toJsonHelp style (replicate indent ' ' : "\n" : revChunks) rest
329328
330329 P.SSGR sgrs rest ->
331330 encodeChunks style revChunks : toJsonHelp (sgrToStyle sgrs style) [] rest
332331
333332
334−spaces :: Int -> TB.Builder
335−spaces n =
336− TB.fromText (Text.replicate n " ")
337−-}
338−
339333sgrToStyle :: [Ansi.SGR] -> Style -> Style
340334sgrToStyle sgrs style@(Style bold underline color) =
341335 case sgrs of
@@ -396,11 +390,11 @@ toColor layer intensity color =
396390 Ansi.White -> pick White WHITE
397391 Ansi.Black -> pick Black BLACK
398392
399−{-
400−encodeChunks :: Style -> [TB.Builder] -> E.Value
393+
394+encodeChunks :: Style -> [String] -> E.Value
401395encodeChunks (Style bold underline color) revChunks =
402396 let
403− !str = Utf8.concat (reverse revChunks)
397+ str = Json.fromChars (concat (reverse revChunks))
404398 in
405399 case color of
406400 Nothing | not bold && not underline ->
@@ -408,12 +402,12 @@ encodeChunks (Style bold underline color) revChunks =
408402
409403 _ ->
410404 E.object
411− [ ("bold", E.bool bold)
412− , ("underline", E.bool underline)
413− , ("color", maybe E.null encodeColor color)
414− , ("string", E.string str)
405+ [ "bold" ==> E.bool bold
406+ , "underline" ==> E.bool underline
407+ , "color" ==> maybe E.null encodeColor color
408+ , "string" ==> E.string str
415409 ]
416−-}
410+
417411
418412encodeColor :: Color -> E.Value
419413encodeColor color =