Data.Progress.Meter

MissingH-1.1.1.0: Large utility library

Portability | portable
Stability | provisional
Maintainer | John Goerzen <jgoerzen@complete.org>

Data.Progress.Meter

Contents

- Types
- Creation and Configuration
- Rendering and Output

Description

Tool for maintaining a status bar, supporting multiple simultaneous tasks, as a layer atop Data.Progress.Tracker.

Written by John Goerzen, jgoerzen@complete.org

Synopsis

- type ProgressMeter = MVar ProgressMeterR
- simpleNewMeter :: Progress -> IO ProgressMeter
- newMeter :: Progress -> String -> Int -> ([Integer] -> [String]) -> IO ProgressMeter
- setComponents :: ProgressMeter -> [Progress] -> IO ()
- addComponent :: ProgressMeter -> Progress -> IO ()
- removeComponent :: ProgressMeter -> String -> IO ()
- setWidth :: ProgressMeter -> Int -> IO ()
- renderMeter :: ProgressMeter -> IO String
- displayMeter :: Handle -> ProgressMeter -> IO ()
- clearMeter :: Handle -> ProgressMeter -> IO ()
- writeMeterString :: Handle -> ProgressMeter -> String -> IO ()
- autoDisplayMeter :: ProgressMeter -> Int -> (ProgressMeter -> IO ()) -> IO ThreadId
- killAutoDisplayMeter :: ProgressMeter -> ThreadId -> IO ()

# Types

type ProgressMeter = MVar ProgressMeterR

# Creation and Configuration

simpleNewMeter :: Progress -> IO ProgressMeter

Set up a new status bar using defaults:

- The given tracker
- Width 80
- Data.Quantity.renderNums binaryOpts 1
- Unit inticator `B`

newMeter

Arguments

:: Progress | The top-level `Progress`
-> String | Unit indicator string
-> Int | Width of the terminal -- usually 80
-> ([Integer] -> [String]) | A function to render sizes
-> IO ProgressMeter |

Set up a new status bar.

setComponents :: ProgressMeter -> [Progress] -> IO ()

Adjust the list of components of this `ProgressMeter`.

addComponent :: ProgressMeter -> Progress -> IO ()

Add a new component to the list of components.

removeComponent :: ProgressMeter -> String -> IO ()

Remove a component by name.

setWidth :: ProgressMeter -> Int -> IO ()

Adjusts the width of this `ProgressMeter`.

# Rendering and Output

renderMeter :: ProgressMeter -> IO String

Render the current status.

displayMeter :: Handle -> ProgressMeter -> IO ()

Like renderMeter, but prints it to the screen instead of returning it.

This function will output CR, then the meter.

Pass stdout as the handle for regular display to the screen.

clearMeter :: Handle -> ProgressMeter -> IO ()

Clears the meter -- outputs CR, spaces equal to the width - 1, then another CR.

Pass stdout as the handle for regular display to the screen.

writeMeterString :: Handle -> ProgressMeter -> String -> IO ()

Clears the meter, writes the given string, then restores the meter. The string is assumed to contain a trailing newline.

Pass stdout as the handle for regular display to the screen.

autoDisplayMeter

Arguments

:: ProgressMeter | The meter to display
-> Int | Update interval in seconds
-> (ProgressMeter -> IO ()) | Function to display it
-> IO ThreadId | Resulting thread id

Starts a thread that updates the meter every n seconds by calling the specified function. Note: `displayMeter stdout` is an ideal function here.

Save this threadID and use it later to call `stopAutoDisplayMeter`.

killAutoDisplayMeter :: ProgressMeter -> ThreadId -> IO ()

Stops the specified meter from displaying.

You should probably call `clearMeter` after a call to this.