vty-ui-1.0.1: An interactive terminal user interface library for Vty

Graphics.Vty.Widgets.Text

Contents

Description

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 plainText; if you want access to the Text for formatting purposes, use textWidget.

Synopsis

Documentation

data Text Source

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

Instances

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.

setText :: MonadIO m => Widget FormattedText -> String -> m ()Source

Set the text value of a FormattedText widget.

prepareText :: String -> TextSource

Prepare a string for rendering.

Constructing Widgets

plainText :: MonadIO m => String -> m (Widget FormattedText)Source

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

textWidget :: MonadIO m => Formatter -> String -> m (Widget FormattedText)Source

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).

Formatting

(&.&) :: 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.