License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <[email protected]> |
Stability | experimental |
Portability | Good |
Safe Haskell | None |
Language | Haskell2010 |
Console.Display
Description
Displaying utilities
Synopsis
- data TerminalDisplay
- displayInit :: IO TerminalDisplay
- display :: TerminalDisplay -> [OutputElem] -> IO ()
- displayTextColor :: TerminalDisplay -> ColorComponent -> String -> IO ()
- displayLn :: TerminalDisplay -> ColorComponent -> String -> IO ()
- data ProgressBar
- progress :: TerminalDisplay -> Int -> (ProgressBar -> IO a) -> IO a
- progressTick :: ProgressBar -> IO ()
- data Summary
- summary :: TerminalDisplay -> IO Summary
- summarySet :: Summary -> [OutputElem] -> IO ()
- type ColorComponent = Zn64 8
- data OutputElem
- termText :: String -> String
- justify :: Justify -> CountOf Char -> String -> String
- data Justify
- data Table
- data Column
- columnNew :: CountOf Char -> String -> Column
- tableCreate :: [Column] -> Table
- tableHeaders :: TerminalDisplay -> Table -> IO ()
- tableAppend :: TerminalDisplay -> Table -> [String] -> IO ()
Documentation
data TerminalDisplay Source #
Terminal display state
Basic
displayInit :: IO TerminalDisplay Source #
Create a new display
display :: TerminalDisplay -> [OutputElem] -> IO () Source #
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.
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
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 # | |
Defined in Console.Display | |
Show OutputElem Source # | |
Defined in Console.Display Methods showsPrec :: Int -> OutputElem -> ShowS # show :: OutputElem -> String # showList :: [OutputElem] -> ShowS # |
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
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
A justification of text.
Constructors
JustifyLeft | Left align text |
JustifyRight | Right align text |
JustifyCenter | Center text |
JustifyJustified | Text fills the whole line width |
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.