dzen-utils-0.1.1: Utilities for creating inputs for dzen.

Portabilitysemi-portable (uses MPTC and type families)
Stabilityexperimental
Maintainerfelipe.lessa@gmail.com
Safe HaskellSafe-Infered

System.Dzen.Bars

Contents

Description

Drawing of progress bars (sometimes called progress gauges), like dbar and gdbar utilities work but a little more powerful (in fact, we can simulate both utilities, see dbar and gdbar).

An example of text progress bar that can be drawn:

 96% [==================> ]

Synopsis

Simple interface

Mimicking dbar

dbarSource

Arguments

:: (Num a, Enum a, Ord a, Show a) 
=> Bool

If True, write the percentage on the left.

-> Width

Width of the bar interior.

-> (a, a)

Minimum and maximum values.

-> a

Actual value.

-> DString 

Mimics the dbar utility. Uses the dbar_style.

cdbar :: (Num a, Enum a, Ord a, Show a) => Bool -> Width -> (a, a) -> Printer aSource

Mimics the dbar utility while getting the input dinamically.

Mimicking gdbar

gdbarSource

Arguments

:: (Num a, Enum a, Ord a, Show a) 
=> Bool

If True, write the percentage on the left.

-> (Width, Height)

Size of the whole bar (excluding text).

-> Maybe DColour

Filled colour (see grpFilled).

-> Maybe DColour

Background/border colour (see grpBackground and grpBorder).

-> Bool

True to mimic -o option (outline).

-> (a, a)

Minimum and maximum values.

-> a

Actual value.

-> DString 

Mimics the gdbar utility. Uses the gdbar_style.

cgdbar :: (Num a, Enum a, Ord a, Show a) => Bool -> (Width, Height) -> Maybe DColour -> Maybe DColour -> Bool -> (a, a) -> Printer aSource

Mimics the gdbar utility while getting the input dinamically.

Generic interface

bar :: (Num a, Enum a, Ord a, Show a) => BarText -> BarType -> (a, a) -> a -> DStringSource

Draws a bar and optionally some text describing some quantity in relation to some range. For example,

 bar (AtLeft Percentage) (Text "[" "=" (Just ">") " " "]" 20) (-10,10) i

produces the bars

 "  2% [                    ]"    where i = -9.6
 "  2% [>                   ]"    where i = -9.5
 " 50% [=========>          ]"    where i = 0
 " 96% [==================> ]"    where i = 9.4
 " 99% [===================>]"    where i = 9.99
 "100% [====================]"    where i = 10

Note that the text is always padded to four characters. If the first bar above had AtRight Percentage the result would be

 "[                    ] 2%  "

so the padding always inserts the spaces on the outside.

cbar :: (Num a, Enum a, Ord a, Show a) => BarText -> BarType -> (a, a) -> Printer aSource

bar wrapped with simple so that the value is taken from an input.

data BarType Source

The type of the bar to be drawn.

Constructors

Text

Draws a text bar. Note, however, that the DStrings below can be anything, not just text. For example, they may have colours (fg), shapes (rects and circs) or icons, you may even simulate both Filled and Hollow using just Text (although performance would be suboptimal).

Fields

txtOpen :: !DString

Text written at the start.

txtFilled :: !DString

Text written for each filled square.

txtMiddle :: !(Maybe DString)

Text written for the last filled square. If Nothing, the same as the filled square is used, but more fairly than if you used the same value for filled and middle chars.

txtBackground :: !DString

Text written for the unfilled squares.

txtClose :: !DString

Text written at the end.

txtWidth :: !Width

How many squares there should be (i.e. does not count the open and close parts).

Filled

Draws a filled graphical bar, like gdbar would.

Fields

grpFilled :: !(Maybe DColour)

Same as grpFilled above.

Colour used for filled squares, or Nothing to use the default foreground colour.

grpBackground :: !(Maybe DColour)

Same as grpBackground above.

Colour used for the unfilled squares, or Nothing to use the default background colour.

grpSize :: !(Width, Height)

Size of the whole bar (including border).

Size of the whole bar.

Hollow

Draws a filled graphical bar with a surrounding border.

Fields

grpFilled :: !(Maybe DColour)

Same as grpFilled above.

Colour used for filled squares, or Nothing to use the default foreground colour.

grpBackground :: !(Maybe DColour)

Same as grpBackground above.

Colour used for the unfilled squares, or Nothing to use the default background colour.

grpBorder :: !(Maybe DColour)

Colour of the border, or Nothing to use the default foreground colour.

grpSize :: !(Width, Height)

Size of the whole bar (including border).

Size of the whole bar.

Instances

data BarTextType Source

The type of text to be written.

Constructors

Percentage 
Absolute 

data BarText Source

How to draw the bar text. AtLeft and AtRight are used to specify if the text is at the left or the right of the bar, and None means that no text will be written.

Styles of the simple interfaces

dbar_style :: Char -> Width -> BarTypeSource

The style produced by the dbar utility.

gdbar_style :: (Width, Height) -> Maybe DColour -> Maybe DColour -> Bool -> BarTypeSource

The style of gdbar (or something very close).