hable-0.3.1: customizable pretty printer library for tables

Safe HaskellSafe



This module allows you to add colors to another style for Hable configuration.

To add a single color to the whole table, it's the most simple to use colored8Config.

If you'd like to color vertical lines independently from horizontal lines, use colored8Charset and don't forget to compose Colored8 to the hLineStyle and vLineStyle properties of your config appropriately.

If you'd like to decide yourself how to act at the points of the table where vertical and horizontal lines are cutting across, use genColored8charset.



data Color8 Source #

Represents the eight colors supported by most terminal emulators through ANSI escape codes.



data Colored8 style Source #

A wrapper for any other style, adding an option of a fore- as well as a background color to it. For the color fields, Nothing represents an unchanged/unmodified/unset color.



colored8Config :: Maybe Color8 -> Maybe Color8 -> Config style -> Config (Colored8 style) Source #

Add colors to a configuration.

The first argument may be a foreground color. If it's Nothing, the foreground won't be modified.

The second argument may be a background color. If it's Nothing, the background won't be modified.

The third argument is the configuration to be colored.

colored8Charset :: (BoxChar style -> String) -> BoxChar (Colored8 style) -> String Source #

Given a charset, returns another new one which supports colors through a Colored8 style.

An example which circles the colors of the horizontal lines using mod

>>> 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:

genColored8Charset :: (HAxis -> Colored8 style -> VAxis -> Colored8 style -> (Maybe Color8, Maybe Color8)) -> (BoxChar style -> String) -> BoxChar (Colored8 style) -> String Source #

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.

color8String :: Maybe Color8 -> Maybe Color8 -> String -> String Source #

Wraps a String into the ANSI escape codes of the given fore- and background colors.