informatikr/aeson-pretty — pull request #8 by chrismwendt (2014-09-13 06:09:41+00:00)
Title: Feature/color

# Implementation

A function to convert a JSON `Value` to a list of color commands `[SGR]` from the `ansi-terminal` package has been added to both `Config` and `PState`.

`defConfig` still has the same behavior of no color (using `noColors`).

`encodePretty` still has the default behavior of no color (implemented as `encodePretty' defConfig`)

`encodePretty' colorConfig` colors the output by inserting color codes which are interpreted by the terminal.

# Example
``` Haskell
{-# LANGUAGE OverloadedStrings #-}

import Data.Aeson.Encode.Pretty
import Data.Aeson (Value(..), ToJSON(..), eitherDecode)
import qualified Data.Aeson.Encode as Aeson
import qualified Data.ByteString.Lazy as BS
import qualified Data.ByteString.Lazy.Char8 as BSC

someJSON :: BS.ByteString
someJSON = "[null,1337,true,\"hi\nthere\",{\"prop\":\"value\",\"p2\":false,\"p3\":3,\"p4\":\"hi\",\"p5\":null}]"

main :: IO ()
main = do
BSC.putStrLn $ either BSC.pack encodePretty (eitherDecode someJSON :: Either String Value)
BSC.putStrLn $ either BSC.pack (encodePretty' colorConfig) (eitherDecode someJSON :: Either String Value)
```

## Output to terminal

![image](https://cloud.githubusercontent.com/assets/1387653/4259705/f775f3a4-3b0b-11e4-83d9-248c5e1b7df9.png)

## Piped into Vim

![image](https://cloud.githubusercontent.com/assets/1387653/4259712/77e454f4-3b0c-11e4-87f8-7d38671f7876.png)