hable-0.3.1: customizable pretty printer library for tables

Safe HaskellSafe
LanguageHaskell2010

Hable

Description

Hable pretty-prints a table in a configurable way. See Config for details on configuration. This is just an introduction.

Default Configuration and Basic Example

import Hable

main :: IO ()
main = putStr (hable defaultConfig) table

table =
    [ [ "Hello", "World!", "Nice to meet you!", ":)" ]
    , [ "This cell\nhas two\nnewlines.", "Nice!", "And the next cell is empty:", ""]
    , [ "Lorem", "Ipsum", "Dolor", "Sit Amet." ]
    , [ "Foo", "Bar", "Baz", "Qux" ]
    , [ "Hable", "is", "super", "amazing!" ]
    ]

will result in:

╔═══════════╤════════╤═════════════════════════════╤═══════════╗
║ Hello     │ World! │ Nice to meet you!           │ :)        ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║ This cell │ Nice!  │ And the next cell is empty: │           ║
║ has two   │        │                             │           ║
║ newlines. │        │                             │           ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║ Lorem     │ Ipsum  │ Dolor                       │ Sit Amet. ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║ Foo       │ Bar    │ Baz                         │ Qux       ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║ Hable     │ is     │ super                       │ amazing!  ║
╚═══════════╧════════╧═════════════════════════════╧═══════════╝

Line Styles

>>> putStr (hable defaultConfig { hLineStyle = \_ _ -> Nothing }) table
║ Hello     │ World! │ Nice to meet you!           │ :)        ║
║ This cell │ Nice!  │ And the next cell is empty: │           ║
║ has two   │        │                             │           ║
║ newlines. │        │                             │           ║
║ Lorem     │ Ipsum  │ Dolor                       │ Sit Amet. ║
║ Foo       │ Bar    │ Baz                         │ Qux       ║
║ Hable     │ is     │ super                       │ amazing!  ║
>>> putStr (hable defaultConfig { vLineStyle = \_ _ -> Nothing } table)
═══════════════════════════════════════════════════════════
 Hello      World!  Nice to meet you!            :)        
───────────────────────────────────────────────────────────
 This cell  Nice!   And the next cell is empty:            
 has two                                                   
 newlines.                                                 
───────────────────────────────────────────────────────────
 Lorem      Ipsum   Dolor                        Sit Amet. 
───────────────────────────────────────────────────────────
 Foo        Bar     Baz                          Qux       
───────────────────────────────────────────────────────────
 Hable      is      super                        amazing!  
═══════════════════════════════════════════════════════════
>>> putStr (hable defaultConfig { hLineStyle = \m n -> if n `elem` [1,2,m] then Just Thick else Nothing, vLineStyle = \_ _ -> Just Normal } table)
┍━━━━━━━━━━━┯━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┑
│ Hello     │ World! │ Nice to meet you!           │ :)        │
┝━━━━━━━━━━━┿━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━┥
│ This cell │ Nice!  │ And the next cell is empty: │           │
│ has two   │        │                             │           │
│ newlines. │        │                             │           │
│ Lorem     │ Ipsum  │ Dolor                       │ Sit Amet. │
│ Foo       │ Bar    │ Baz                         │ Qux       │
│ Hable     │ is     │ super                       │ amazing!  │
┕━━━━━━━━━━━┷━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┙
>>> putStr (hable defaultConfig { charset = orgModeCharset, hLineStyle = \_ _ -> Just (), vLineStyle = \_ _ -> Just () } table)
|-----------+--------+-----------------------------+-----------|
| Hello     | World! | Nice to meet you!           | :)        |
|-----------+--------+-----------------------------+-----------|
| This cell | Nice!  | And the next cell is empty: |           |
| has two   |        |                             |           |
| newlines. |        |                             |           |
|-----------+--------+-----------------------------+-----------|
| Lorem     | Ipsum  | Dolor                       | Sit Amet. |
|-----------+--------+-----------------------------+-----------|
| Foo       | Bar    | Baz                         | Qux       |
|-----------+--------+-----------------------------+-----------|
| Hable     | is     | super                       | amazing!  |
|-----------+--------+-----------------------------+-----------|
>>> putStr (hable (colored8Config (Just Green) Nothing defaultConfig) table)

>>> putStr (hable defaultConfig { charset = colored8Charset (charset defaultConfig), vLineStyle = \m n -> Nothing, hLineStyle = \m n -> fmap (Colored8 (Just (toEnum (fromInteger ((n `mod` 6) + 1)))) Nothing) $ vLineStyle defaultConfig m n} table)

>>> putStr (hable defaultConfig { hAlign = const HRight, vAlign = const VBottom} table)
╔═══════════╤════════╤═════════════════════════════╤═══════════╗
║     Hello │ World! │           Nice to meet you! │        :) ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║ This cell │        │                             │           ║
║   has two │        │                             │           ║
║ newlines. │  Nice! │ And the next cell is empty: │           ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║     Lorem │  Ipsum │                       Dolor │ Sit Amet. ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║       Foo │    Bar │                         Baz │       Qux ║
╟───────────┼────────┼─────────────────────────────┼───────────╢
║     Hable │     is │                       super │  amazing! ║
╚═══════════╧════════╧═════════════════════════════╧═══════════╝
>>> putStr (hable defaultConfig { hPadding = 5, hLineStyle = \_ _ -> Nothing, hAlign = const HCenter, vAlign = const VCenter} table)
║       Hello       │     World!     │          Nice to meet you!          │         :)        ║
║     This cell     │                │                                     │                   ║
║      has two      │      Nice!     │     And the next cell is empty:     │                   ║
║     newlines.     │                │                                     │                   ║
║       Lorem       │      Ipsum     │                Dolor                │     Sit Amet.     ║
║        Foo        │       Bar      │                 Baz                 │        Qux        ║
║       Hable       │       is       │                super                │      amazing!     ║

Synopsis

Documentation

hable Source #

Arguments

:: Config style

Hable Configuration

-> [[String]]

Row-wise table to be pretty-printed

-> String

Pretty-printed table

Pretty-prints a row-wise given table using a given Hable Configuration.

defaultConfig :: Config UnicodeStyle Source #

The default configuration uses Unicode box characters.