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