-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A library for pretty printing Records -- -- A pretty-printing library which is accumulates record accessors as -- Strings, and fields as Strings or formatted boxes. Functions are -- included to output lists of records as a table, or apply a format to -- individual records. @package pprecord @version 0.2.0.0 -- | Type classes in this module are intended to be derived with -- DeriveGeneric. module Text.PrettyPrint.Records -- | Accumulate Record accessors as [String] (in order of definition). class FQuery a -- | Accumulate Record values as [String] (in order of definition). class VQuery a -- | 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
--
class (Typeable a, FQuery a, Show a) => RFmt a
-- | Identical to VQuery except no instance for sum types (a
-- necessary restriction for printing tables).
class TFmt a
-- | Format Record a record fully expanding the data structure if it is
-- recursive.
format :: RFmt a => a -> Format a -> Box
-- | Format Record a with up to n levels of recursivity.
formatUntil :: RFmt a => Int -> a -> Format a -> Box
-- | See FQuery.
fields :: FQuery a => a -> [String]
-- | See VQuery.
values :: VQuery a => a -> [String]
dfltFmt :: Format a
-- | Given String representation of accessor and value return b.
simpleFmt :: (VQuery a, FQuery a) => (String -> String -> b) -> a -> [b]
-- | A table formatter which produces a top-down table.
tableFmt :: TableFmt
-- | 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 }
--
data Format a
Format :: (String -> Box) -> (String -> Box -> Box) -> ([Box] -> Box) -> Format a
-- | Converts Record fields to Boxes
[arg] :: Format a -> String -> Box
-- | Merge accessor with field
[label] :: Format a -> String -> Box -> Box
-- | Finally reduce list of boxes
[finally] :: Format a -> [Box] -> Box
data TableFmt
TableFmt :: (String -> Box) -> (String -> [Box] -> Box) -> ([Box] -> Box) -> TableFmt
-- | Converts Record fields to Boxes.
[argT] :: TableFmt -> String -> Box
-- | Merge accessor with field.
[labelT] :: TableFmt -> String -> [Box] -> Box
-- | Finally reduce list of boxes.
[finallyT] :: TableFmt -> [Box] -> Box
-- | Format a list of (FQuery, TFmt) instances as a table.
--
--
-- Example:
-- data Employee = E
-- { eId :: Int
-- , name :: String
-- , email :: String } deriving (Generic, Show)
-- instance FQuery Employee
-- instance TFmt 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"
--
formatTable :: (TFmt a, FQuery a) => [a] -> TableFmt -> Box
instance Text.PrettyPrint.Records.TFmt' f => Text.PrettyPrint.Records.TFmt' (GHC.Generics.M1 t c f)
instance (Text.PrettyPrint.Records.TFmt' f, Text.PrettyPrint.Records.TFmt' g) => Text.PrettyPrint.Records.TFmt' (f GHC.Generics.:*: g)
instance GHC.Show.Show c => Text.PrettyPrint.Records.TFmt' (GHC.Generics.Rec0 c)
instance Text.PrettyPrint.Records.TFmt' GHC.Generics.U1
instance Text.PrettyPrint.Records.TFmt' GHC.Generics.V1
instance Text.PrettyPrint.Records.RFmt' f => Text.PrettyPrint.Records.RFmt' (GHC.Generics.M1 t c f)
instance (Text.PrettyPrint.Records.RFmt' f, Text.PrettyPrint.Records.RFmt' g) => Text.PrettyPrint.Records.RFmt' (f GHC.Generics.:+: g)
instance (Text.PrettyPrint.Records.RFmt' f, Text.PrettyPrint.Records.RFmt' g) => Text.PrettyPrint.Records.RFmt' (f GHC.Generics.:*: g)
instance (Data.Typeable.Internal.Typeable c, GHC.Show.Show c) => Text.PrettyPrint.Records.RFmt' (GHC.Generics.Rec0 c)
instance Text.PrettyPrint.Records.RFmt' GHC.Generics.U1
instance Text.PrettyPrint.Records.RFmt' GHC.Generics.V1
instance Text.PrettyPrint.Records.VQuery' f => Text.PrettyPrint.Records.VQuery' (GHC.Generics.M1 t c f)
instance (Text.PrettyPrint.Records.VQuery' f, Text.PrettyPrint.Records.VQuery' g) => Text.PrettyPrint.Records.VQuery' (f GHC.Generics.:+: g)
instance (Text.PrettyPrint.Records.VQuery' f, Text.PrettyPrint.Records.VQuery' g) => Text.PrettyPrint.Records.VQuery' (f GHC.Generics.:*: g)
instance GHC.Show.Show c => Text.PrettyPrint.Records.VQuery' (GHC.Generics.Rec0 c)
instance Text.PrettyPrint.Records.VQuery' GHC.Generics.U1
instance Text.PrettyPrint.Records.VQuery' GHC.Generics.V1
instance Text.PrettyPrint.Records.FQuery c => Text.PrettyPrint.Records.FQuery' (GHC.Generics.Rec0 c)
instance Text.PrettyPrint.Records.FQuery' GHC.Generics.V1
instance Text.PrettyPrint.Records.FQuery' GHC.Generics.U1
instance (Text.PrettyPrint.Records.FQuery' f, Text.PrettyPrint.Records.FQuery' g) => Text.PrettyPrint.Records.FQuery' (f GHC.Generics.:+: g)
instance (Text.PrettyPrint.Records.FQuery' f, Text.PrettyPrint.Records.FQuery' g) => Text.PrettyPrint.Records.FQuery' (f GHC.Generics.:*: g)
instance Text.PrettyPrint.Records.FQuery' f => Text.PrettyPrint.Records.FQuery' (GHC.Generics.D1 c f)
instance Text.PrettyPrint.Records.FQuery' f => Text.PrettyPrint.Records.FQuery' (GHC.Generics.C1 c f)
instance GHC.Generics.Selector s => Text.PrettyPrint.Records.FQuery' (GHC.Generics.S1 s f)