File: ProgressBar.hs

package info (click to toggle)
haskell-test-framework 0.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 176 kB
  • sloc: haskell: 928; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 784 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module Test.Framework.Runners.Console.ProgressBar (
        Progress(..), progressBar
    ) where

import Text.PrettyPrint.ANSI.Leijen hiding (width)


data Progress = Progress Int Int

progressBar :: (Doc -> Doc) -> Int -> Progress -> Doc
progressBar color width (Progress count total) = char '[' <> progress_doc <> space_doc <> char ']'
  where
    -- The available width takes account of the enclosing brackets
    available_width = width - 2
    characters_per_tick = fromIntegral available_width / fromIntegral total :: Double
    progress_chars = round (characters_per_tick * fromIntegral count)
    space_chars = available_width - progress_chars
    progress_doc = color (text (reverse (take progress_chars ('>' : repeat '='))))
    space_doc = text (replicate space_chars ' ')