cli-0.2.0: CLI

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
PortabilityGood
Safe HaskellNone
LanguageHaskell2010

Console.Display

Contents

Description

Displaying utilities

Synopsis

Documentation

data TerminalDisplay Source #

Terminal display state

Basic

displayInit :: IO TerminalDisplay Source #

Create a new display

displayTextColor :: TerminalDisplay -> ColorComponent -> String -> IO () Source #

A simple utility that display a msg in color

displayLn :: TerminalDisplay -> ColorComponent -> String -> IO () Source #

A simple utility that display a msg in color and newline at the end.

Progress Bar

data ProgressBar Source #

A progress bar widget created and used within the progress function.

progress Source #

Arguments

:: TerminalDisplay

The terminal display to display the progress bar on.

-> Int

The number of items the progress bar represents.

-> (ProgressBar -> IO a)

The progression bar update function.

-> IO a

The results of the progress bar update function.

Create a new progress bar context from a terminal display, a number of items, and a progress update function.

The progress bar update function should perform the desired actions on each of the items, and call progressTick whenever an item is fully processed.

Each time the given update function calls progressTick the progress bar fills by one item until the given number of items is matched. Once the bar is filled it will not fill any further even if progressTick is called again.

The progress bar will disappear when the given update function completes running, even if the progress bar is not yet entirely filled.

For example, the following function will create a progress bar of 100 items, and complete one of the items every tenth of a second. Once all of the items are completed the progress bar is removed and a completion String is returned.

runProgressBar :: IO String
runProgressBar = do
    terminalDisplay <- displayInit
    progress terminalDisplay 100 (progressFunction 100)
  where
    progressFunction :: Int -> ProgressBar -> IO String
    progressFunction 0 _   = return "Completed!"
    progressFunction n bar = do
      threadDelay 100000
      progressTick bar
      progressFunction (n - 1) bar

progressTick :: ProgressBar -> IO () Source #

Ticks an element on the given progress bar. Should be used within a progress bar update function that is passed into progress.

progressFunction :: ProgressBar -> IO String
progressFunction bar = do
  threadDelay 100000
  progressTick bar
  threadDelay 200000
  progressTick bar
  return "Completed!"

Summary line

data Summary Source #

Summary

summary :: TerminalDisplay -> IO Summary Source #

Create a summary

summarySet :: Summary -> [OutputElem] -> IO () Source #

Set the summary

Attributes

type ColorComponent = Zn64 8 #

Simple color component on 8 color terminal (maximum compatibility)

data OutputElem Source #

Element to output text and attributes to the display

Constructors

Bg ColorComponent 
Fg ColorComponent 
T String 
LeftT (CountOf Char) String

Left-aligned text

RightT (CountOf Char) String

Right-aligned text

CenterT (CountOf Char) String

Centered text

JustifiedT (CountOf Char) String

Justified text

NA 
Instances
Eq OutputElem Source # 
Instance details

Defined in Console.Display

Show OutputElem Source # 
Instance details

Defined in Console.Display

justify :: Justify -> CountOf Char -> String -> String Source #

Boxes a string to a given size using the given justification.

If the size of the given string is greater than or equal to the given boxing size, then the original string is returned.

Examples

Expand

Basic usage:

>>> justify JustifyRight 35 "Lorem ipsum dolor sit amet"
"Lorem ipsum dolor sit amet         "
>>> justify JustifyLeft 35 "Lorem ipsum dolor sit amet"
"         Lorem ipsum dolor sit amet"
>>> justify JustifyCenter 35 "Lorem ipsum dolor sit amet"
"    Lorem ipsum dolor sit amet     "
>>> justify JustifyJustified 35 "Lorem ipsum dolor sit amet"
"Lorem    ipsum   dolor   sit   amet"

Apply a justified justification to a one word string, resulting in a string of the given length with the word at the left followed by the remaining space.

>>> justify JustifyJustified 10 "Hello."
"Hello.    "

Attempt to box a string that is larger than the given box, yielding the original string.

>>> justify JustifyRight 5 "Hello, World!"
"Hello, World!"

Table

data Justify Source #

A justification of text.

Constructors

JustifyLeft

Left align text

JustifyRight

Right align text

JustifyCenter

Center text

JustifyJustified

Text fills the whole line width

data Table Source #

Table widget

data Column Source #

Column for a table

columnNew :: CountOf Char -> String -> Column Source #

Create a new column setting the right default parameters

tableCreate :: [Column] -> Table Source #

Create a new table

tableHeaders :: TerminalDisplay -> Table -> IO () Source #

Show the table headers

tableAppend :: TerminalDisplay -> Table -> [String] -> IO () Source #

Append a row to the table.

if the number of elements is greater than the amount of column the table has been configured with, the extra elements are dropped.