diff options
Diffstat (limited to 'src/viewerpercent.cpp')
-rw-r--r-- | src/viewerpercent.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/viewerpercent.cpp b/src/viewerpercent.cpp new file mode 100644 index 0000000..289c900 --- /dev/null +++ b/src/viewerpercent.cpp | |||
@@ -0,0 +1,114 @@ | |||
1 | #include "viewerpercent.h" | ||
2 | #include "perform.h" | ||
3 | #include "plugger.h" | ||
4 | |||
5 | PluginInterface2( percent, ViewerPercent, Viewer, "Mike Buland", 0, 1 ); | ||
6 | |||
7 | ViewerPercent::ViewerPercent() : | ||
8 | nWidth( 15 ) | ||
9 | { | ||
10 | } | ||
11 | |||
12 | ViewerPercent::~ViewerPercent() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | void ViewerPercent::beginAction( const std::string &sName, int nCommands ) | ||
17 | { | ||
18 | nTotalCommands = nCommands; | ||
19 | nCurCommand = 0; | ||
20 | } | ||
21 | |||
22 | void ViewerPercent::endAction() | ||
23 | { | ||
24 | } | ||
25 | |||
26 | void ViewerPercent::beginCommand( Action::eAction nAct, const std::string &sTarget ) | ||
27 | { | ||
28 | this->sTarget = sTarget; | ||
29 | nCurCommand++; | ||
30 | } | ||
31 | |||
32 | void ViewerPercent::endCommand() | ||
33 | { | ||
34 | printf("\n"); | ||
35 | } | ||
36 | |||
37 | void ViewerPercent::beginPerforms( int nCount ) | ||
38 | { | ||
39 | nTotalPerforms = nCount; | ||
40 | nCurPerform = 0; | ||
41 | nLastLen = 0; | ||
42 | } | ||
43 | |||
44 | void ViewerPercent::endPerforms() | ||
45 | { | ||
46 | int nLen = printf("\r[%2d/%-2d] %s [", | ||
47 | nCurCommand, nTotalCommands, | ||
48 | sTarget.c_str() ); | ||
49 | for( int j = 0; j < nWidth; j++ ) | ||
50 | { | ||
51 | fputc('#', stdout ); | ||
52 | } | ||
53 | nLen += nWidth; | ||
54 | nLen += printf("] 100%%"); | ||
55 | |||
56 | if( nLastLen > nLen ) | ||
57 | { | ||
58 | int jmax = nLastLen-nLen; | ||
59 | for( int j = 0; j < jmax; j++ ) | ||
60 | { | ||
61 | fputc(' ', stdout ); | ||
62 | } | ||
63 | } | ||
64 | nLastLen = 0; | ||
65 | |||
66 | fflush( stdout ); | ||
67 | } | ||
68 | |||
69 | void ViewerPercent::beginRequiresCheck( bool bCached, const std::string &sName ) | ||
70 | { | ||
71 | } | ||
72 | |||
73 | void ViewerPercent::endRequiresCheck() | ||
74 | { | ||
75 | } | ||
76 | |||
77 | void ViewerPercent::beginPerform( Perform *pPerform ) | ||
78 | { | ||
79 | nCurPerform++; | ||
80 | int nLen = printf("\r[%2d/%-2d] %s [", | ||
81 | nCurCommand, nTotalCommands, | ||
82 | sTarget.c_str() ); | ||
83 | int jmax = nCurPerform*nWidth/nTotalPerforms; | ||
84 | for( int j = 0; j < jmax; j++ ) | ||
85 | { | ||
86 | fputc('#', stdout ); | ||
87 | } | ||
88 | jmax = nWidth-jmax; | ||
89 | for( int j = 0; j < jmax; j++ ) | ||
90 | { | ||
91 | fputc(' ', stdout ); | ||
92 | } | ||
93 | nLen += nWidth; | ||
94 | nLen += printf("] %-2d%% %s", | ||
95 | nCurPerform*100/nTotalPerforms, | ||
96 | pPerform->getTarget().c_str() ); | ||
97 | |||
98 | if( nLastLen > nLen ) | ||
99 | { | ||
100 | jmax = nLastLen-nLen; | ||
101 | for( int j = 0; j < jmax; j++ ) | ||
102 | { | ||
103 | fputc(' ', stdout ); | ||
104 | } | ||
105 | } | ||
106 | nLastLen = nLen; | ||
107 | |||
108 | fflush( stdout ); | ||
109 | } | ||
110 | |||
111 | void ViewerPercent::endPerform() | ||
112 | { | ||
113 | } | ||
114 | |||