{-| 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 'Hable.Style.Unicode', so you might want to take a look at 'Hable.Style.OrgMode' and 'Hable.Style.Colored8', too. -} -------------------------------------------------------------------------------- module Hable.Config ( Config(..) , defaultConfig ) where -------------------------------------------------------------------------------- import Data.List import Hable.BoxChar import Hable.Style.Unicode -------------------------------------------------------------------------------- -- | Hable Configuration. data Config style = Config { -- | -- = Horizontal line style. -- -- The first argument is the index of the last possible horizontal line -- (i.e. number of rows + 1). -- -- The second argument receives the index of any horizontal line. -- -- If 'Nothing' is returned, the horizontal line will be collapsed / hidden -- here. If 'Just' a style is returned, this style will be used for the -- horizontal parts of the box character ('BoxChar'). hLineStyle :: Integer -> Integer -> Maybe style -- | -- = Vertical line style. -- -- The first argument is the index of the last possible vertical line -- (i.e. number of rows + 1). -- -- The second argument receives the index of any vertical line. -- -- If 'Nothing' is returned, the vertical line will be collapsed / hidden -- here. If 'Just' a style is returned, this style will be used for the -- vertical parts of the box character ('BoxChar'). , vLineStyle :: Integer -> Integer -> Maybe style -- | -- = Horizontal Alignment. -- -- The argument is the index of any row. -- -- If 'HLeft' is returned, the content of the cells in this row will be -- aligned to the left. If 'HCenter' is returned, the content of the cells in -- this row will be centered. If 'HRight' is returned, the content of -- the cells in this row will be aligned to the right. , hAlign :: Integer -> HAxis -- | -- = Vertical Alignment in case of multi-line cells. -- -- The argument is the index of any column. -- -- If 'VTop' is returned, the content of the cells in this column will be -- aligned to the top. If 'VCenter' is returned, the content of the cells in -- this column will be centered. If 'VBottom' is returned, the content of -- the cells in this column will be aligned to the bottom. , vAlign :: Integer -> VAxis -- | -- = Horizontal padding. -- -- The number of spaces to be inserted between the cell content and the -- vertical lines on both the left and the right side of a cell. , hPadding :: Integer -- | -- = Charset. -- -- The argument is a styled box character 'BoxChar'. The style of it was -- calculated by 'hable' using the 'hLineStyle' and 'vLineStyle' properties -- of your configuration. -- -- Returns a character (as string) to be used for the lines. , charset :: BoxChar style -> String } -------------------------------------------------------------------------------- -- | The default configuration uses Unicode box characters. defaultConfig :: Config UnicodeStyle defaultConfig = Config { hLineStyle = xLineStyle (Just Normal) , vLineStyle = xLineStyle (Just Normal) , hAlign = const HLeft , vAlign = const VTop , hPadding = 1 , charset = unicodeCharset } where xLineStyle alternative max now | now == 1 || now == max = Just Double | otherwise = alternative