vty-ui-0.4: A user interface composition library for Vty




This module provides functionality for rendering Strings as Widgets, including functionality to make structural and/or visual changes at rendering time. To get started, turn your ordinary String into a Widget with simpleText; if you want access to the Text for formatting purposes, use prepareText followed by textWidget.



data Text Source

Text represents a String that can be manipulated with Formatters at rendering time.

type Formatter = DisplayRegion -> Text -> TextSource

A formatter makes changes to text at rendering time.

It'd be nice if formatters were just :: Text -> Text, but some formatting use cases involve knowing the size of the rendering area, which is not known until render time (e.g., text wrapping). Thus, a formatter takes a DisplayRegion and runs at render time.

Text Preparation

prepareText :: Attr -> String -> TextSource

Prepare a string for rendering and assign it the specified default attribute.

Constructing Widgets

simpleText :: Attr -> String -> WidgetSource

Construct a Widget directly from an attribute and a String. This is recommended if you don't need to use a Formatter.

textWidget :: Formatter -> Text -> WidgetSource

Construct a text widget formatted with the specified formatters. the formatters will be applied in the order given here, so be aware of how the formatters will modify the text (and affect each other).


(&.&) :: Formatter -> Formatter -> FormatterSource

Formatter composition: a &.& b applies a followed by b.

highlight :: Regex -> Attr -> FormatterSource

A highlight formatter takes a regular expression used to scan the text and an attribute to assign to matches. Highlighters only scan non-whitespace tokens in the text stream.

wrap :: FormatterSource

A formatter for wrapping text into the available space. This formatter will insert line breaks where appropriate so if you want to use other structure-sensitive formatters, run this formatter last.