penny-lib-0.4.0.0: Extensible double-entry accounting system - library

Safe HaskellSafe-Infered

Penny.Cabin.Chunk

Contents

Description

Handles colors and special effects for text. This module was written using the control sequences documented for xterm in ctlseqs.txt, which is included in the xterm source code (on Debian GNU/Linux systems, it is at /usr/share/doc/xterm/ctlseqs.txt.gz). The code in here should also work for any terminal which recognizes ISO 6429 escape sequences (also known as ANSI escape sequences), but only for 8 colors. This module also generates sequences for 256 color xterms; though this works fine with xterm, it might not work on other terminals (I believe it works for other terminals commonly found on Linux systems, such as gnome-terminal and Konsole, but I have not tested these terminals as I do not use them.) Perhaps it also works on Windows or Mac OS X systems and their terminals, though I have not tested them (in particular, Windows could be problematic as not all Windows terminals support ISO 6429.)

In theory there are more portable ways to generate color codes, such as through curses (or is it ncurses?) but support for ISO 6429 is widespread enough that I am prepared to say that if your terminal does not support it, too bad; just use the colorless mode.

Synopsis

Colors

data Colors Source

How many colors to actually show.

Constructors

Colors0 
Colors8 
Colors256 

Instances

data Background8 Source

Background color in an 8 color setting.

data Background256 Source

Background color in a 256 color setting.

data Foreground8 Source

Foreground color in an 8 color setting.

data Foreground256 Source

Foreground color in a 256 color setting.

Chunks

data Chunk Source

A chunk is some textual data coupled with a description of what color the text is. The chunk knows what colors to use for both foreground color and background color, in both an 8 color terminal and a 256 color terminal. The chunk has only one set of color descriptions. To change colors, you must use a new chunk.

There is no way to combine chunks. To print large numbers of chunks, lazily build a list of them and then print them using chunksToText.

newtype Width Source

How wide the text of a chunk is.

Constructors

Width 

Fields

unWidth :: Int
 

chunksToText :: Colors -> [Chunk] -> TextSource

Transforms chunks to a lazy Text. This function runs lazily and in constant time and space.

Effects

newtype Bold Source

Constructors

Bold 

Fields

unBold :: Bool
 

newtype Underline Source

Constructors

Underline 

Fields

unUnderline :: Bool
 

newtype Flash Source

Constructors

Flash 

Fields

unFlash :: Bool
 

newtype Inverse Source

Constructors

Inverse 

Fields

unInverse :: Bool
 

Style and TextSpec

A style is a bundle of attributes that describes text attributes, such as its color and whether it is bold.

data StyleCommon Source

Style elements that apply in both 8 and 256 color terminals. However, the elements are described separately for 8 and 256 color terminals, so that the text appearance can change depending on how many colors a terminal has.

Constructors

StyleCommon 

data Style8 Source

Describes text appearance (foreground and background colors, as well as other attributes such as bold) for an 8 color terminal.

data Style256 Source

Describes text appearance (foreground and background colors, as well as other attributes such as bold) for a 256 color terminal.

defaultStyleCommon :: StyleCommonSource

Has all bold, flash, underline, and inverse turned off.

defaultStyle8 :: Style8Source

Uses the default terminal colors (which will vary depending on the terminal).

defaultStyle256 :: Style256Source

Uses the default terminal colors (which will vary depending on the terminal).

data TextSpec Source

The TextSpec bundles together the styles for the 8 and 256 color terminals, so that the text can be portrayed on any terminal.

Constructors

TextSpec 

defaultTextSpec :: TextSpecSource

A TextSpec with the default colors on 8 and 256 color terminals, with all attributes turned off.

Specific colors

8 color foreground colors

8 color background colors

256 color foreground colors

256 color background colors