]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.13 1999/04/20 05:59:29 jgg Exp $
4 /* ######################################################################
6 Acquire Progress - Command line progress meter
8 ##################################################################### */
10 // Include files /*{{{*/
11 #include "acqprogress.h"
12 #include <apt-pkg/acquire-item.h>
13 #include <apt-pkg/acquire-worker.h>
14 #include <apt-pkg/strutl.h>
20 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
21 // ---------------------------------------------------------------------
23 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
24 ScreenWidth(ScreenWidth
), Quiet(Quiet
)
28 // AcqTextStatus::Start - Downloading has started /*{{{*/
29 // ---------------------------------------------------------------------
31 void AcqTextStatus::Start()
33 pkgAcquireStatus::Start();
38 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
39 // ---------------------------------------------------------------------
41 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
47 cout
<< '\r' << BlankLine
<< '\r';
49 cout
<< "Hit " << Itm
.Description
;
50 if (Itm
.Owner
->FileSize
!= 0)
51 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "b]";
56 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
57 // ---------------------------------------------------------------------
58 /* This prints out the short description and the expected size */
59 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
62 if (Itm
.Owner
->Complete
== true)
71 cout
<< '\r' << BlankLine
<< '\r';
73 cout
<< "Get:" << Itm
.Owner
->ID
<< ' ' << Itm
.Description
;
74 if (Itm
.Owner
->FileSize
!= 0)
75 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "b]";
79 // AcqTextStatus::Done - Completed a download /*{{{*/
80 // ---------------------------------------------------------------------
81 /* We don't display anything... */
82 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
87 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
88 // ---------------------------------------------------------------------
89 /* We print out the error text */
90 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
96 cout
<< '\r' << BlankLine
<< '\r';
98 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
100 cout
<< "Ign " << Itm
.Description
<< endl
;
104 cout
<< "Err " << Itm
.Description
<< endl
;
105 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
111 // AcqTextStatus::Stop - Finished downloading /*{{{*/
112 // ---------------------------------------------------------------------
113 /* This prints out the bytes downloaded and the overall average line
115 void AcqTextStatus::Stop()
117 pkgAcquireStatus::Stop();
122 cout
<< '\r' << BlankLine
<< '\r';
124 if (FetchedBytes
!= 0)
125 cout
<< "Fetched " << SizeToStr(FetchedBytes
) << "b in " <<
126 TimeToStr(ElapsedTime
) << " (" << SizeToStr(CurrentCPS
) <<
130 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
131 // ---------------------------------------------------------------------
132 /* This draws the current progress. Each line has an overall percent
133 meter and a per active item status meter along with an overall
134 bandwidth and ETA indicator. */
135 void AcqTextStatus::Pulse(pkgAcquire
*Owner
)
140 pkgAcquireStatus::Pulse(Owner
);
142 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
145 char *End
= Buffer
+ sizeof(Buffer
);
148 // Put in the percent done
149 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
152 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
153 I
= Owner
->WorkerStep(I
))
157 // There is no item running
158 if (I
->CurrentItem
== 0)
160 if (I
->Status
.empty() == false)
162 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
171 // Add in the short description
172 if (I
->CurrentItem
->Owner
->ID
!= 0)
173 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
174 I
->CurrentItem
->ShortDesc
.c_str());
176 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
179 // Show the short mode string
180 if (I
->CurrentItem
->Owner
->Mode
!= 0)
182 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
186 // Add the current progress
188 snprintf(S
,End
-S
," %lu",I
->CurrentSize
);
191 if (Mode
== Medium
|| I
->TotalSize
== 0)
192 snprintf(S
,End
-S
," %sb",SizeToStr(I
->CurrentSize
).c_str());
196 // Add the total size and percent
197 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
200 snprintf(S
,End
-S
," %lu%%",
201 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
203 snprintf(S
,End
-S
,"/%sb %lu%%",SizeToStr(I
->TotalSize
).c_str(),
204 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
207 snprintf(S
,End
-S
,"]");
212 snprintf(S
,End
-S
," [Working]");
214 /* Put in the ETA and cps meter, block off signals to prevent strangeness
216 sigset_t Sigs
,OldSigs
;
218 sigaddset(&Sigs
,SIGWINCH
);
219 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
224 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
225 sprintf(Tmp
," %sb/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
226 unsigned int Len
= strlen(Buffer
);
227 unsigned int LenT
= strlen(Tmp
);
228 if (Len
+ LenT
< ScreenWidth
)
230 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
231 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
234 Buffer
[ScreenWidth
] = 0;
235 BlankLine
[ScreenWidth
] = 0;
236 sigprocmask(SIG_UNBLOCK
,&OldSigs
,0);
238 // Draw the current status
239 if (strlen(Buffer
) == strlen(BlankLine
))
240 cout
<< '\r' << Buffer
<< flush
;
242 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
243 memset(BlankLine
,' ',strlen(Buffer
));
244 BlankLine
[strlen(Buffer
)] = 0;
249 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
250 // ---------------------------------------------------------------------
251 /* Prompt for a media swap */
252 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
255 cout
<< '\r' << BlankLine
<< '\r';
256 cout
<< "Media Change: Please insert the disc labeled '" << Media
<< "' in "\
257 "the drive '" << Drive
<< "' and press enter" << endl
;
260 while (C
!= '\n' && C
!= '\r')
261 read(STDIN_FILENO
,&C
,1);