]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.10 1999/02/27 22:29:11 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>
18 // AcqTextStatus::AcqTextStatus - Constructor /*{{{*/
19 // ---------------------------------------------------------------------
21 AcqTextStatus::AcqTextStatus(unsigned int &ScreenWidth
,unsigned int Quiet
) :
22 ScreenWidth(ScreenWidth
), Quiet(Quiet
)
26 // AcqTextStatus::Start - Downloading has started /*{{{*/
27 // ---------------------------------------------------------------------
29 void AcqTextStatus::Start()
31 pkgAcquireStatus::Start();
36 // AcqTextStatus::IMSHit - Called when an item got a HIT response /*{{{*/
37 // ---------------------------------------------------------------------
39 void AcqTextStatus::IMSHit(pkgAcquire::ItemDesc
&Itm
)
45 cout
<< '\r' << BlankLine
<< '\r';
47 cout
<< "Hit " << Itm
.Description
;
48 if (Itm
.Owner
->FileSize
!= 0)
49 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "b]";
54 // AcqTextStatus::Fetch - An item has started to download /*{{{*/
55 // ---------------------------------------------------------------------
56 /* This prints out the short description and the expected size */
57 void AcqTextStatus::Fetch(pkgAcquire::ItemDesc
&Itm
)
60 if (Itm
.Owner
->Complete
== true)
69 cout
<< '\r' << BlankLine
<< '\r';
71 cout
<< "Get:" << hex
<< Itm
.Owner
->ID
<< dec
<< ' ' << Itm
.Description
;
72 if (Itm
.Owner
->FileSize
!= 0)
73 cout
<< " [" << SizeToStr(Itm
.Owner
->FileSize
) << "b]";
77 // AcqTextStatus::Done - Completed a download /*{{{*/
78 // ---------------------------------------------------------------------
79 /* We don't display anything... */
80 void AcqTextStatus::Done(pkgAcquire::ItemDesc
&Itm
)
85 // AcqTextStatus::Fail - Called when an item fails to download /*{{{*/
86 // ---------------------------------------------------------------------
87 /* We print out the error text */
88 void AcqTextStatus::Fail(pkgAcquire::ItemDesc
&Itm
)
94 cout
<< '\r' << BlankLine
<< '\r';
96 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
98 cout
<< "Ign " << Itm
.Description
<< endl
;
102 cout
<< "Err " << Itm
.Description
<< endl
;
103 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
109 // AcqTextStatus::Stop - Finished downloading /*{{{*/
110 // ---------------------------------------------------------------------
111 /* This prints out the bytes downloaded and the overall average line
113 void AcqTextStatus::Stop()
115 pkgAcquireStatus::Stop();
120 cout
<< '\r' << BlankLine
<< '\r';
122 if (FetchedBytes
!= 0)
123 cout
<< "Fetched " << SizeToStr(FetchedBytes
) << "b in " <<
124 TimeToStr(ElapsedTime
) << " (" << SizeToStr(CurrentCPS
) <<
128 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
129 // ---------------------------------------------------------------------
130 /* This draws the current progress. Each line has an overall percent
131 meter and a per active item status meter along with an overall
132 bandwidth and ETA indicator. */
133 void AcqTextStatus::Pulse(pkgAcquire
*Owner
)
138 pkgAcquireStatus::Pulse(Owner
);
140 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
143 char *End
= Buffer
+ sizeof(Buffer
);
146 // Put in the percent done
147 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
150 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
151 I
= Owner
->WorkerStep(I
))
155 // There is no item running
156 if (I
->CurrentItem
== 0)
158 if (I
->Status
.empty() == false)
160 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
169 // Add in the short description
170 if (I
->CurrentItem
->Owner
->ID
!= 0)
171 snprintf(S
,End
-S
," [%x %s",I
->CurrentItem
->Owner
->ID
,
172 I
->CurrentItem
->ShortDesc
.c_str());
174 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
177 // Show the short mode string
178 if (I
->CurrentItem
->Owner
->Mode
!= 0)
180 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
184 // Add the current progress
186 snprintf(S
,End
-S
," %u",I
->CurrentSize
);
189 if (Mode
== Medium
|| I
->TotalSize
== 0)
190 snprintf(S
,End
-S
," %sb",SizeToStr(I
->CurrentSize
).c_str());
194 // Add the total size and percent
195 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
198 snprintf(S
,End
-S
," %u%%",
199 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
201 snprintf(S
,End
-S
,"/%sb %u%%",SizeToStr(I
->TotalSize
).c_str(),
202 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
205 snprintf(S
,End
-S
,"]");
210 snprintf(S
,End
-S
," [Working]");
212 // Put in the ETA and cps meter
216 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
217 sprintf(Tmp
," %sb/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
218 unsigned int Len
= strlen(Buffer
);
219 unsigned int LenT
= strlen(Tmp
);
220 if (Len
+ LenT
< ScreenWidth
)
222 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
223 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
226 Buffer
[ScreenWidth
] = 0;
228 // Draw the current status
229 if (strlen(Buffer
) == strlen(BlankLine
))
230 cout
<< '\r' << Buffer
<< flush
;
232 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
233 memset(BlankLine
,' ',strlen(Buffer
));
234 BlankLine
[strlen(Buffer
)] = 0;
239 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
240 // ---------------------------------------------------------------------
241 /* Prompt for a media swap */
242 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
245 cout
<< '\r' << BlankLine
<< '\r';
246 cout
<< "Media Change: Please insert the disc labeled '" << Media
<< "' in "\
247 "the drive '" << Drive
<< "' and press enter" << endl
;
250 while (C
!= '\n' && C
!= '\r')
251 read(STDIN_FILENO
,&C
,1);