@@ -12,12 +12,12 @@ For license and copyright information, see the file LICENSE
12
12
Copyright : Copyright (C) 2006-2011 John Goerzen
13
13
SPDX-License-Identifier: BSD-3-Clause
14
14
15
- Stability : provisional
15
+ Stability : stable
16
16
Portability: portable
17
17
18
18
Tools for tracking the status of a long operation.
19
19
20
- Written by John Goerzen, jgoerzen\@complete.org
20
+ Written by John Goerzen, jgoerzen\@complete.org
21
21
22
22
See also "Data.Progress.Meter" -}
23
23
@@ -66,7 +66,7 @@ a large task is composed of several individual tasks which may also be
66
66
long-running. Downloading many large files over the Internet is a common
67
67
example of this.
68
68
69
- Any given ProgressTracker can be told about one or more parent trackers.
69
+ Any given ProgressTracker can be told about one or more parent trackers.
70
70
When the child tracker's status is updated, the parent tracker's status is
71
71
also updated in the same manner. Therefore, the progress on each individual
72
72
component, as well as the overall progress, can all be kept in sync
@@ -95,7 +95,7 @@ Here is an example use:
95
95
-- TYPES
96
96
----------------------------------------------------------------------
97
97
98
- {- | A function that, when called, yields the current time.
98
+ {- | A function that, when called, yields the current time.
99
99
The default is 'defaultTimeSource'. -}
100
100
type ProgressTimeSource = IO Integer
101
101
@@ -112,7 +112,7 @@ callback is running, so the callback will not be able to make changes to it. -}
112
112
type ProgressCallback = ProgressStatus -> ProgressStatus -> IO ()
113
113
114
114
{- | The main progress status record. -}
115
- data ProgressStatus =
115
+ data ProgressStatus =
116
116
ProgressStatus { completedUnits :: Integer ,
117
117
totalUnits :: Integer ,
118
118
startTime :: Integer ,
@@ -129,7 +129,7 @@ data ProgressRecord =
129
129
newtype Progress = Progress (MVar ProgressRecord )
130
130
131
131
class ProgressStatuses a b where
132
- {- | Lets you examine the 'ProgressStatus' that is contained
132
+ {- | Lets you examine the 'ProgressStatus' that is contained
133
133
within a 'Progress' object. You can simply pass
134
134
a 'Progress' object and a function to 'withStatus', and
135
135
'withStatus' will lock the 'Progress' object (blocking any
@@ -184,7 +184,7 @@ newProgress name total =
184
184
timeSource = defaultTimeSource})
185
185
[]
186
186
187
- {- | Create a new 'Progress' object initialized with the given status and
187
+ {- | Create a new 'Progress' object initialized with the given status and
188
188
callbacks.
189
189
No adjustment to the 'startTime' will be made. If you
190
190
want to use the system clock, you can initialize 'startTime' with
@@ -200,7 +200,7 @@ newProgress' news newcb =
200
200
{- | Adds an new callback to an existing 'Progress'. The callback will be
201
201
called whenever the object's status is updated, except by the call to finishP.
202
202
203
- Please note that the Progress object will be locked while the callback is
203
+ Please note that the Progress object will be locked while the callback is
204
204
running, so the callback will not be able to make any modifications to it.
205
205
-}
206
206
addCallback :: Progress -> ProgressCallback -> IO ()
@@ -227,42 +227,42 @@ any adjustment in totalUnits to the parents, whose callbacks /will/ be
227
227
called.
228
228
229
229
This ensures that the total expected counts on the parent are always correct.
230
- Without doing this, if, say, a transfer ended earlier than expected, ETA
230
+ Without doing this, if, say, a transfer ended earlier than expected, ETA
231
231
values on the parent would be off since it would be expecting more data than
232
232
actually arrived. -}
233
233
finishP :: Progress -> IO ()
234
234
finishP (Progress mp) =
235
235
modifyMVar_ mp modfunc
236
236
where modfunc :: ProgressRecord -> IO ProgressRecord
237
237
modfunc oldpr =
238
- do let adjustment = (completedUnits . status $ oldpr)
238
+ do let adjustment = (completedUnits . status $ oldpr)
239
239
- (totalUnits . status $ oldpr)
240
240
callParents oldpr (\ x -> incrTotal x adjustment)
241
- return $ oldpr {status = (status oldpr)
241
+ return $ oldpr {status = (status oldpr)
242
242
{totalUnits = completedUnits . status $ oldpr}}
243
243
244
244
----------------------------------------------------------------------
245
245
-- Updating
246
246
----------------------------------------------------------------------
247
247
{- | Increment the completed unit count in the 'Progress' object
248
248
by the amount given. If the value as given exceeds the total, then
249
- the total will also be raised to match this value so that the
249
+ the total will also be raised to match this value so that the
250
250
completed count never exceeds the total.
251
251
252
252
You can decrease the completed unit count by supplying a negative number
253
253
here. -}
254
254
incrP :: Progress -> Integer -> IO ()
255
255
incrP po count = modStatus po statusfunc
256
- where statusfunc s =
256
+ where statusfunc s =
257
257
s {completedUnits = newcu s,
258
258
totalUnits = if newcu s > totalUnits s
259
259
then newcu s
260
260
else totalUnits s}
261
- newcu s = completedUnits s + count
261
+ newcu s = completedUnits s + count
262
262
263
263
{- | Like 'incrP', but never modify the total. -}
264
264
incrP' :: Progress -> Integer -> IO ()
265
- incrP' po count =
265
+ incrP' po count =
266
266
modStatus po (\ s -> s {completedUnits = completedUnits s + count})
267
267
268
268
{- | Set the completed unit count in the 'Progress' object to the specified
@@ -283,10 +283,10 @@ setP' :: Progress -> Integer -> IO ()
283
283
setP' po count = modStatus po (\ s -> s {completedUnits = count})
284
284
285
285
{- | Increment the total unit count in the 'Progress' object by the amount
286
- given. This would rarely be needed, but could be needed in some special cases
286
+ given. This would rarely be needed, but could be needed in some special cases
287
287
when the total number of units is not known in advance. -}
288
288
incrTotal :: Progress -> Integer -> IO ()
289
- incrTotal po count =
289
+ incrTotal po count =
290
290
modStatus po (\ s -> s {totalUnits = totalUnits s + count})
291
291
292
292
{- | Set the total unit count in the 'Progress' object to the specified
@@ -318,26 +318,26 @@ that it can take either a 'Progress' or a 'ProgressStatus' object, and returns
318
318
a number that is valid as any Fractional type, such as a Double, Float, or
319
319
Rational. -}
320
320
getSpeed :: (ProgressStatuses a (IO b ), Fractional b ) => a -> IO b
321
- getSpeed po = withStatus po $ \ status ->
321
+ getSpeed po = withStatus po $ \ status ->
322
322
do t <- timeSource status
323
323
let elapsed = t - (startTime status)
324
324
return $ if elapsed == 0
325
325
then fromRational 0
326
326
else fromRational ((completedUnits status) % elapsed)
327
327
328
- {- | Returns the estimated time remaining, in standard time units.
328
+ {- | Returns the estimated time remaining, in standard time units.
329
329
330
330
Returns 0 whenever 'getSpeed' would return 0.
331
331
332
332
See the comments under 'getSpeed' for information about this function's type
333
333
and result. -}
334
334
getETR :: (ProgressStatuses a (IO Integer ),
335
335
ProgressStatuses a (IO Rational )) => a -> IO Integer
336
- getETR po =
336
+ getETR po =
337
337
do speed <- ((getSpeed po):: IO Rational )
338
338
if speed == 0
339
339
then return 0
340
- else
340
+ else
341
341
-- FIXME: potential for a race condition here, but it should
342
342
-- be negligible
343
343
withStatus po $ \ status ->
@@ -376,7 +376,7 @@ modStatus :: Progress -> (ProgressStatus -> ProgressStatus) -> IO ()
376
376
modStatus (Progress mp) func =
377
377
modifyMVar_ mp modfunc
378
378
where modfunc :: ProgressRecord -> IO ProgressRecord
379
- modfunc oldpr =
379
+ modfunc oldpr =
380
380
do let newpr = oldpr {status = func (status oldpr)}
381
381
mapM_ (\ x -> x (status oldpr) (status newpr))
382
382
(callbacks oldpr)
@@ -394,4 +394,3 @@ modStatus (Progress mp) func =
394
394
395
395
callParents :: ProgressRecord -> (Progress -> IO () ) -> IO ()
396
396
callParents pr func = mapM_ func (parents pr)
397
-
0 commit comments