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

Safe HaskellNone

Penny.Cabin.Chunk

Contents

Description

Handles colors and special effects for text. Internally this module uses the Haskell terminfo library, which links against the UNIX library of the same name, so it should work with a wide variety of UNIX terminals. This module is a layer between terminfo and the rest of Penny, allowing the Chunk internals to be swapped out and replaced. (I know this because this module previously used a home-grown implementation written based on the Xterm configuration; that implementation was swapped out and replaced with terminfo with minimal disruption.)

However, terminfo is a UNIX thing, so at this time Penny probably would not work on a Windows based system.

There is an ansi-terminal library on Hackage, which does support Windows. One problem with that though is that ansi-terminal does not appear to support more than 8 colors; Chunk supports 256 colors, which is very helpful for Penny.

Synopsis

Colors

data Term Source

Which terminal definition to use.

Constructors

Dumb

Using this terminal should always succeed. This suppresses all colors. Uesful if output is not going to a TTY, or if you just do not like colors.

TermName String

Use the terminal with this given name. You might get this from the TERM environment variable, or set it explicitly. A runtime error will result if the terminfo database does not have a definition for this terminal. If this terminal supports 256 colors, then 256 colors are used. If this terminal supports less than 256 colors, but at least 8 colors, then 8 colors are used. Otherwise, no colors are used.

Instances

autoTerm :: Runtime -> TermSource

Determines which Term to use based on whether standard output is a terminal. Uses Dumb if standard output is not a terminal; otherwise, uses the TERM environment variable.

termFromEnv :: Runtime -> TermSource

Determines which Term to use based on the TERM environment variable, regardless of whether standard output is a terminal. Uses Dumb if TERM is not set.

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, attributes like whether it is bold or underlined, etc. The chunk knows what foreground and background colors and what attributes to use for both an 8 color terminal and a 256 color terminal. To change these attributes and colors, you must make 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 printChunks.

Instances

chunk :: TextSpec -> Text -> ChunkSource

Makes new Chunks.

newtype Width Source

How wide the text of a chunk is.

Constructors

Width 

Fields

unWidth :: Int
 

printChunks :: Term -> [Chunk] -> IO ()Source

Sends a list of chunks to standard output for printing. Sets up the terminal (this only needs to be done once.) Lazily processes the list of Chunk.

Effects

newtype Bold Source

Constructors

Bold 

Fields

unBold :: Bool
 

Instances

newtype Underline Source

Constructors

Underline 

Fields

unUnderline :: Bool
 

newtype Flash Source

Constructors

Flash 

Fields

unFlash :: Bool
 

Instances

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.

Instances

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