pprecord-0.1.0.0: A library for pretty printing Records

Safe HaskellSafe
LanguageHaskell2010

Text.PrettyPrint.Records

Synopsis

Documentation

class FQuery a Source #

Accumulate Record accessors as [String] (in order of definition).

class VQuery a Source #

Accumulate Record values as [String] (in order of definition).

class (Typeable a, FQuery a, Show a) => RFmt a Source #

Reduce Record to Box given a Format

  Example:
      data List a = List { label :: String, val :: a, tail :: List a }
          | Nil deriving (Generic, Show)
      instance FQuery (List a)
      instance (Show a, Typeable a) => RFmt (List a)
      test = List "head" 3 $ List "mid" 4 $ List "tail" 5 $ Nil

      ghci> printBox $ format test dfltFmt
      label: "head"
      val: 3
      tail: label: "mid"
            val: 4
            tail: label: "tail"
                  val: 5
                  tail: Nil

format :: RFmt a => a -> Format a -> Box Source #

Format Record a record fully expanding the data structure if it is recursive

formatUntil :: RFmt a => Int -> a -> Format a -> Box Source #

Format Record a with up to n levels of recursivity

fields :: FQuery a => a -> [String] Source #

values :: VQuery a => a -> [String] Source #

simpleFmt :: (VQuery a, FQuery a) => (String -> String -> b) -> a -> [b] Source #

Given String representation of accessor and value return b

tableFmt :: TableFmt Source #

A table formatter which produces a top-down table

data Format a Source #

A Format is responsible for converting a Record into a formatted Box.

   Example:
       dfltFmt :: Format a
       dfltFmt = Format
           { arg = text
           , label = \a b -> text (a <> ":") + b
           , finally = vcat left }

Constructors

Format 

Fields

data TableFmt Source #

Constructors

TableFmt 

Fields

formatTable :: RFmt a => [a] -> TableFmt -> Box Source #

Format a list of RFmt instances as a table (no recursive expansion).

   Example:
       data Employee = E
          { eId :: Int
          , name :: String
          , email :: String } deriving (Generic, Show)
       instance FQuery Employee
       instance RFmt Employee
       e1 = E 3 "John" "johnbelcherfoobar.xyz"
       e1 = E 3 "John" "johnbelcherfoobar.xyz"
       e2 = E 17 "Maria" "Mariafoobarnet.net"
       e3 = E 1 "Stanley" "stanleytheceofoobar.org"
       e4 = E 2 "Kayla" "klabarfoo.com"
       e5 = E 4 "Sammy" "sammersfoobarfoo.bar"

       ghci> printBox $ formatTable [e1, e2, e3, e4, e5] tableFmt
       eId name      email
       3   "John"    "johnbelcherfoobar.xyz"
       17  "Maria"   "Mariafoobarnet.net"
       1   "Stanley" "stanleytheceofoobar.org"
       2   "Kayla"   "klabarfoo.com"
       4   "Sammy"   "sammersfoobar@foo.bar"