https://github.com/yamadapc/haskell-ascii-progress
A simple Haskell progress bar for the console. Heavily borrows from TJ Holowaychuk's Node.JS project
https://github.com/yamadapc/haskell-ascii-progress
Last synced: 2 months ago
JSON representation
A simple Haskell progress bar for the console. Heavily borrows from TJ Holowaychuk's Node.JS project
- Host: GitHub
- URL: https://github.com/yamadapc/haskell-ascii-progress
- Owner: yamadapc
- License: mit
- Created: 2015-01-21T05:50:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-10T17:56:48.000Z (about 8 years ago)
- Last Synced: 2025-03-01T20:48:35.585Z (3 months ago)
- Language: Haskell
- Size: 290 KB
- Stars: 64
- Watchers: 8
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ascii-progress
==============
[](http://hackage.haskell.org/package/ascii-progress)
[](https://travis-ci.org/yamadapc/haskell-ascii-progress)
[](http://stackage.org/lts-8/package/ascii-progress)
[](http://stackage.org/nightly/package/ascii-progress)- - -
A simple Haskell progress bar for the console. Heavily borrows from TJ
Holowaychuk's Node.JS project [progress](https://github.com/tj/node-progress).
[**Packages Using `ascii-progress`**](http://packdeps.haskellers.com/reverse/ascii-progress)
- [`codex`](http://hackage.haskell.org/package/codex)
- [`xdcc`](http://hackage.haskell.org/package/xdcc)## Basic Usage
```haskell
import Control.Concurrent (threadDelay)
import Control.Monad (unless)
import System.Console.AsciiProgress (Options(..), displayConsoleRegions,
isComplete, def, newProgressBar, tick)main :: IO ()
main = displayConsoleRegions $ do
pg <- newProgressBar def { pgWidth = 50 }
loop pg
where
loop pg = do
b <- isComplete pg
unless b $ do
threadDelay $ 200 * 1000
tick pg
loop pg
```[Full documentation on hackage](http://hackage.haskell.org/package/ascii-progress)
## Multiple progress bar support
Though still rudimentary, there's support for running multiple concurrent
progress bars. The [`multi-example`](/bin/MultiExample.hs) shows off this
feature:
## Examples
The [bin](/bin) directory contains the example above and a more complex example
which uses `http-conduit` to download an image from imgur, printing the
progress using the package.To build the examples, just configure and compile with `-fexamples`:
```
git clone https://github.com/yamadapc/haskell-ascii-progress
cabal install -j --only-dep -fexamples
cabal configure -fexamples
cabal run example
# ...
cabal run download-example
```## Options
`ascii-progress` uses an `Options` data type for configuring the progress bar.
Available options are:
### `pgFormat :: String`
A format `String` for the progress bar. The following placeholders are
supported:
- `":eta"` (ETA displayed in seconds)
- `":current"` (current tick)
- `":total"` (total number of ticks)
- `":percent"` (percentage completed)
- `":elapsed"` (elapsed time in seconds)
- `":bar"` (the actual progress bar)#### Example
```haskell
main = do
pg <- newProgressBar def { pgFormat = ":current/:total [:bar]" }
-- ...
```### `pgCompletedChar :: Char`
The character used on the completed part of the barThere's an example which mimicks the NPM3 progress-bar. It looks like:
```
Working ╢████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
```### `pgPendingChar :: Char`
The character used on the completed part of the bar### `pgTotal :: Int`
The total amount of ticks for the bar to be completed### `pgWidth :: Int`
The progress bar's total width in columns### `pgOnCompletion :: Maybe String`
What to output when the progress bar is done. The same format placeholders used
in `pgFormat` may be used.### `pgGetProgressStr :: Options -> Stats -> String`
If all else fails, you can provide a function which determines how a
progress-bar is rendered.## Installing
This package is published to hackage as
[`ascii-progress`](http://hackage.haskell.org/package/ascii-progress), so you
can install it with:```
cabal install ascii-progress
```It's also part of stackage.
## License
This code is licensed under the MIT license for Pedro Tacla Yamada. For more
information please refer to the [LICENSE](/LICENSE) file.