blob: 7d3de079701e2c0c2be6eee2336da231eb96aebf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
###############################################################################
#
# Package: NaturalDocs::StatusMessage
#
###############################################################################
#
# A package to handle status message updates. Automatically handles <NaturalDocs::Settings->IsQuiet()>.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL
use strict;
use integer;
package NaturalDocs::StatusMessage;
#
# var: message
# The message to display.
#
my $message;
#
# var: total
# The number of items to work through.
#
my $total;
#
# var: completed
# The number of items completed.
#
my $completed;
#
# var: lastMessageTime
# The time the last message was posted.
#
my $lastMessageTime;
#
# constant: TIME_BETWEEN_UPDATES
# The number of seconds that should occur between updates.
#
use constant TIME_BETWEEN_UPDATES => 10;
#
# Function: Start
#
# Starts the status message.
#
# Parameters:
#
# message - The message to post.
# total - The number of items that are going to be worked through.
#
sub Start #(message, total)
{
my $self = shift;
if (!NaturalDocs::Settings->IsQuiet())
{
($message, $total) = @_;
$completed = 0;
print $message . "\n";
$lastMessageTime = time();
};
};
#
# Function: CompletedItem
#
# Should be called every time an item is completed.
#
sub CompletedItem
{
my $self = shift;
if (!NaturalDocs::Settings->IsQuiet())
{
# We scale completed by 100 since we need to anyway to get the percentage.
$completed += 100;
if (time() >= $lastMessageTime + TIME_BETWEEN_UPDATES && $completed != $total * 100)
{
print $message . ' (' . ($completed / $total) . '%)' . "\n";
$lastMessageTime = time();
};
};
};
1;
|