Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data ProgressBar s
- newProgressBar :: Style s -> Double -> Progress s -> IO (ProgressBar s)
- hNewProgressBar :: Handle -> Style s -> Double -> Progress s -> IO (ProgressBar s)
- renderProgressBar :: Style s -> Progress s -> Timing -> Text
- updateProgress :: forall s. ProgressBar s -> (Progress s -> Progress s) -> IO ()
- incProgress :: ProgressBar s -> Int -> IO ()
- data Style s = Style {
- styleOpen :: !Text
- styleClose :: !Text
- styleDone :: !Char
- styleCurrent :: !Char
- styleTodo :: !Char
- stylePrefix :: Label s
- stylePostfix :: Label s
- styleWidth :: !ProgressBarWidth
- styleEscapeOpen :: EscapeCode s
- styleEscapeClose :: EscapeCode s
- styleEscapeDone :: EscapeCode s
- styleEscapeCurrent :: EscapeCode s
- styleEscapeTodo :: EscapeCode s
- styleEscapePrefix :: EscapeCode s
- styleEscapePostfix :: EscapeCode s
- type EscapeCode s = Progress s -> Text
- defStyle :: Style s
- data ProgressBarWidth
- = ConstantWidth !Int
- | TerminalWidth !Int
- data Progress s = Progress {
- progressDone :: !Int
- progressTodo :: !Int
- progressCustom :: !s
- newtype Label s = Label {}
- data Timing = Timing {}
- msg :: Text -> Label s
- percentage :: Label s
- exact :: Label s
- elapsedTime :: (NominalDiffTime -> Text) -> Label s
- remainingTime :: (NominalDiffTime -> Text) -> Text -> Label s
- totalTime :: (NominalDiffTime -> Text) -> Text -> Label s
- renderDuration :: NominalDiffTime -> Text
Progress bars
data ProgressBar s Source #
Instances
NFData s => NFData (ProgressBar s) Source # | |
Defined in System.ProgressBar rnf :: ProgressBar s -> () # |
:: Style s | |
-> Double | Maximum refresh rate in Hertz. |
-> Progress s | Initial progress. |
-> IO (ProgressBar s) |
renderProgressBar :: Style s -> Progress s -> Timing -> Text Source #
Renders a progress bar
>>>
renderProgressBar (msg "Working") percentage 40 30 100
"Working [=======>.................] 30%"
Not that this function can not use TerminalWidth
because it
doesn't use IO
. Use progressBar
or hProgressBar
to get
automatic width.
updateProgress :: forall s. ProgressBar s -> (Progress s -> Progress s) -> IO () Source #
incProgress :: ProgressBar s -> Int -> IO () Source #
Options
Options that determine the textual representation of a progress bar.
The textual representation of a progress bar follows the following template:
<prefix><open><done><current><todo><close><postfix>
Where <done> and <todo> are repeated as often as necessary.
Consider the following progress bar
"Working [=======>.................] 30%"
This bar can be specified using the following style:
Style
{styleOpen
= "[" ,styleClose
= "]" ,styleDone
= '=' ,styleCurrent
= '>' ,styleTodo
= '.' ,stylePrefix
=msg
"Working" ,stylePostfix
=percentage
,styleWidth
=ConstantWidth
40 ,styleEscapeOpen
= constempty
,styleEscapeClose
= constempty
,styleEscapeDone
= constempty
,styleEscapeCurrent
= constempty
,styleEscapeTodo
= constempty
,styleEscapePrefix
= constempty
,styleEscapePostfix
= constempty
}
Style | |
|
Instances
type EscapeCode s Source #
An escape code is a sequence of bytes which the terminal looks for and interprets as commands, not as character codes.
It is vital that the output of this function, when send to the terminal, does not result in characters being drawn.
A default style.
You can override some fields of the default instead of specifying
all the fields of a Style
record.
The default does not use any escape sequences.
data ProgressBarWidth Source #
Width of progress bar in characters.
ConstantWidth !Int | A constant width. |
TerminalWidth !Int | Use the entire width of the terminal. Identical to |
Instances
Generic ProgressBarWidth Source # | |
Defined in System.ProgressBar type Rep ProgressBarWidth :: Type -> Type # from :: ProgressBarWidth -> Rep ProgressBarWidth x # to :: Rep ProgressBarWidth x -> ProgressBarWidth # | |
NFData ProgressBarWidth Source # | |
Defined in System.ProgressBar rnf :: ProgressBarWidth -> () # | |
type Rep ProgressBarWidth Source # | |
Defined in System.ProgressBar type Rep ProgressBarWidth = D1 (MetaData "ProgressBarWidth" "System.ProgressBar" "terminal-progress-bar-0.4-H9t2Dsxknd2KARr34CJQVF" False) (C1 (MetaCons "ConstantWidth" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int)) :+: C1 (MetaCons "TerminalWidth" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Int))) |
Progress
State of a progress bar.
Progress | |
|
Labels
A label that can be pre- or postfixed to a progress bar.
Timing | |
|
percentage :: Label s Source #
A label which displays the progress as a percentage.
>>>
runLabel $ percentage (Progress 30 100 ()) someTiming
" 30%"
Note: if no work is to be done (todo == 0) the percentage will always be 100%.
A label which displays the progress as a fraction of the total amount of work.
Equal width property - the length of the resulting label is a function of the total amount of work:
>>>
runLabel $ exact (Progress 30 100 ()) someTiming
" 30/100"
elapsedTime :: (NominalDiffTime -> Text) -> Label s Source #
A label which displays the amount of time that has elapsed.
Time starts when a progress bar is created.
The user must supply a function which actually renders the amount
of time that has elapsed. You can use renderDuration
or
formatTime
from time >= 1.9.
:: (NominalDiffTime -> Text) | |
-> Text | Alternative message when remaining time can't be calculated (yet). |
-> Label s |
Displays the estimated remaining time until all work is done.
Tells you how much longer some task will take.
This label uses a really simple estimation algorithm. It assumes progress is linear. To prevent nonsense results it won't estimate remaining time until at least 1 second of work has been done.
When it refuses to estimate the remaining time it will show an alternative message instead.
The user must supply a function which actually renders the amount
of time that has elapsed. You can use renderDuration
or
formatTime
from time >= 1.9.
:: (NominalDiffTime -> Text) | |
-> Text | Alternative message when total time can't be calculated (yet). |
-> Label s |
Displays the estimated total time a task will take.
This label uses a really simple estimation algorithm. It assumes progress is linear. To prevent nonsense results it won't estimate the total time until at least 1 second of work has been done.
When it refuses to estimate the total time it will show an alternative message instead.
The user must supply a function which actually renders the total
amount of time that a task will take. You can use renderDuration
or formatTime
from time >= 1.9.
renderDuration :: NominalDiffTime -> Text Source #
Show amount of time.
renderDuration (fromInteger 42)
42
renderDuration (fromInteger $ 5 * 60 + 42)
05:42
renderDuration (fromInteger $ 8 * 60 * 60 + 5 * 60 + 42)
08:05:42
Use the time >= 1.9 package to get a formatTime function which
accepts NominalDiffTime
.