-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | customizable pretty printer library for tables -- -- customizable pretty printer library for tables, e.g. using boxing -- characters @package hable @version 0.3.0 module Hable.BoxChar -- | Describes a styled box character. You can use any data type to -- represent a style as long as the charset of your -- Config supports it. -- -- Be careful with all these getter functions like bcVStyle as -- they are not complete. (E.g. bcHStyle (Bar ()) -- will fail with an exception error.) data BoxChar style -- | Represents a box character in the shape of |. Bar :: style -> BoxChar style [bcVStyle] :: BoxChar style -> style -- | Represents a box character in the shape of –. Dash :: style -> BoxChar style [bcHStyle] :: BoxChar style -> style -- | Represents any other box character. -- -- Imagine a 2x2 table. The bcVPos and bcHPos use the -- Align data type to describe the position of the angled box -- character this Angled constructor represents. -- -- E.g. Angled HLeft foo VBottom bar -- represents an L-like shaped box character as that's the shape -- of the character at the bottom-left edge of a 2x2 table. -- -- Another example: Angled HCenter HCenter -- describes a box character shaped like a plus +. Angled :: HAxis -> style -> VAxis -> style -> BoxChar style [bcHPos] :: BoxChar style -> HAxis [bcHStyle] :: BoxChar style -> style [bcVPos] :: BoxChar style -> VAxis [bcVStyle] :: BoxChar style -> style -- | Describe a value (e.g. direction or position) on the horizontal axis. data HAxis -- | Means either on the left (in context of BoxChar) or -- to the left (in context of hAlign). HLeft :: HAxis -- | Means either inbetween left and right (in context of -- BoxChar) or (horizontally) centered (in context of -- hAlign). HCenter :: HAxis -- | Means either on the right (in context of BoxChar) or -- to the right (in context of hAlign). HRight :: HAxis -- | Describe a value (e.g. direction or position) on the vertical axis. data VAxis -- | Means at the top. VTop :: VAxis -- | Means either inbetween top and bottom (in context of -- BoxChar) or (vertically) centered (in context of -- vAlign). VCenter :: VAxis -- | Means at the bottom. VBottom :: VAxis instance GHC.Enum.Enum Hable.BoxChar.VAxis instance GHC.Enum.Enum Hable.BoxChar.HAxis -- | This module might be useful to understand the Hable's indexing of -- vertical and horizontal lines and maybe also to debug them. -- -- It offers a style, called LineIndexStyle which is a simple type -- synonym for Integer. This style is used to print the last digit -- of vertical line index (see vLineIndexcharset) or horizontal -- line index (see hLineIndexCharset). module Hable.Style.LineIndex type LineIndexStyle = Integer -- | Usage example: -- --
-- >>> putStr (hable defaultConfig { charset = vLineIndexCharset, vLineStyle = const Just, hLineStyle = const Just } [["foo","bar"],["baz","qux"]])
-- 1-----2-----3
-- 1 foo 2 bar 3
-- 1-----2-----3
-- 1 baz 2 qux 3
-- 1-----2-----3
--
vLineIndexCharset :: BoxChar LineIndexStyle -> String
-- | Usage example:
--
--
-- >>> putStr (hable defaultConfig { charset = hLineIndexCharset, vLineStyle = const Just, hLineStyle = const Just } [["foo","bar"],["baz","qux"]])
-- 1111111111111
-- | foo | bar |
-- 2222222222222
-- | baz | qux |
-- 3333333333333
--
hLineIndexCharset :: BoxChar LineIndexStyle -> String
module Hable.Style.OrgMode
-- | A charset based on the syntax of Emacs' Org-Mode
-- spreadsheet. It uses +, - and | and ignores
-- any style.
--
-- An example output:
--
--
-- >>> putStr (hable myConfig { charset = orgModeCharset, hStyleAt = \_ _ -> Just (), vStyleAt = \_ _ -> Just () } myTable)
-- |----------------------+------------------------------------------------|
-- | Name | Hable |
-- |----------------------+------------------------------------------------|
-- | Synopsis | customizable pretty printer library for tables |
-- |----------------------+------------------------------------------------|
-- | License | Public Domain / Unlicense |
-- |----------------------+------------------------------------------------|
--
orgModeCharset :: BoxChar style -> String
type OrgModeStyle = ()
module Hable.Style.Unicode
-- | This module uses a style data type supporting normal, double and thick
-- lines.
data UnicodeStyle
Normal :: UnicodeStyle
Double :: UnicodeStyle
Thick :: UnicodeStyle
-- | charset. Unfortunately, there is not a Unicode box character
-- for all possible values of BoxChar Unicode.
-- In case of such an input, an error is thrown.
--
-- If you'd prefer an alternative behavior in that case, use
-- maybeUnicodeCharset.
--
-- An example output:
--
-- -- >>> putStr (hable myConfig myTable) -- ╒══════════════════════╤════════════════════════════════════════════════╕ -- │ Name │ Hable │ -- ╞══════════════════════╪════════════════════════════════════════════════╡ -- │ Synopsis │ customizable pretty printer library for tables │ -- │ License │ Public Domain / Unlicense │ -- └──────────────────────┴────────────────────────────────────────────────┘ --unicodeCharset :: BoxChar UnicodeStyle -> String -- | Maybe returns a character representing the given BoxChar with -- Unicode box characters. maybeUnicodeCharset :: BoxChar UnicodeStyle -> Maybe String instance GHC.Show.Show Hable.Style.Unicode.UnicodeStyle -- | This module offers the Config data type (constructor) to -- configure hable. -- -- For further configuration, you might also want to take a look at the -- various pre-defined styles of Hable. The default configuration uses -- Unicode, so you might want to take a look at OrgMode and -- Colored8, too. module Hable.Config -- | Hable Configuration. data Config style Config :: (Integer -> Integer -> Maybe style) -> (Integer -> Integer -> Maybe style) -> (Integer -> HAxis) -> (Integer -> VAxis) -> Integer -> (BoxChar style -> String) -> Config style -- |
-- >>> putStr (hable defaultConfig { charset = colored8Charset (charset defaultConfig), vLineStyle = _ _ -> Nothing, hLineStyle = m n -> fmap (Colored8 (Just (toEnum (fromInteger ((n mod 6) + 1)))) Nothing) $ vLineStyle defaultConfig m n } exampleTable)
--
--
-- Unfortunately, you wouldn't see the colors here, so there's a picture:
--
colored8Charset :: (BoxChar style -> String) -> BoxChar (Colored8 style) -> String
-- | A generalization of colored8Charset. Instead of simply using
-- choosing the vertical color components for Angled box
-- characters, you can pass your own function to decide which color to
-- choose in this case. E.g. you could write a function which uses a
-- completely different color.
--
-- All in all, the first argument of genColored8charset is a
-- function. Its arguments are the same as the arguments of the
-- Angled constructor.
genColored8Charset :: (HAxis -> Colored8 style -> VAxis -> Colored8 style -> (Maybe Color8, Maybe Color8)) -> (BoxChar style -> String) -> BoxChar (Colored8 style) -> String
-- | Wraps a String into the ANSI escape codes of the given fore-
-- and background colors.
color8String :: Maybe Color8 -> Maybe Color8 -> String -> String
instance GHC.Enum.Enum Hable.Style.Colored8.Color8
instance GHC.Classes.Eq Hable.Style.Colored8.Color8
-- | Pretty-print a table in a configurable way.
--
-- Using the default configuration, this program:
--
-- -- import Hable -- -- main :: IO () -- main = putStr (hable defaultConfig exampleTable) -- -- exampleTable = -- [ [ "one", "two", "three", Hable ] -- , [ "hellonworld", "loremnipsumndolornsit amet", "verryyyyyy llooong", "is"] -- , [ "super", "awesome", "freaking", "amazing" ] -- ] ---- -- will result in: -- --
-- ╔═══════╤══════════╤════════════════════╤═════════╗ -- ║ one │ two │ three │ Hable ║ -- ╟───────┼──────────┼────────────────────┼─────────╢ -- ║ hello │ lorem │ verryyyyyy llooong │ is ║ -- ║ world │ ipsum │ │ ║ -- ║ │ dolor │ │ ║ -- ║ │ sit amet │ │ ║ -- ╟───────┼──────────┼────────────────────┼─────────╢ -- ║ super │ awesome │ freaking │ amazing ║ -- ╚═══════╧══════════╧════════════════════╧═════════╝ ---- -- See Config for configuration. module Hable -- | Pretty-prints a row-wise given table using a given Hable -- Configuration. hable :: Config style -> [[String]] -> String -- | The default configuration uses Unicode box characters. defaultConfig :: Config UnicodeStyle