]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.7 1999/01/27 02:48:53 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
) << ']';
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
) << ']';
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 cout
<< "Err " << Itm
.Description
<< endl
;
97 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
101 // AcqTextStatus::Stop - Finished downloading /*{{{*/
102 // ---------------------------------------------------------------------
103 /* This prints out the bytes downloaded and the overall average line
105 void AcqTextStatus::Stop()
107 pkgAcquireStatus::Stop();
112 cout
<< '\r' << BlankLine
<< '\r';
114 if (FetchedBytes
!= 0)
115 cout
<< "Fetched " << SizeToStr(FetchedBytes
) << " in " <<
116 TimeToStr(ElapsedTime
) << " (" << SizeToStr(CurrentCPS
) <<
120 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
121 // ---------------------------------------------------------------------
122 /* This draws the current progress. Each line has an overall percent
123 meter and a per active item status meter along with an overall
124 bandwidth and ETA indicator. */
125 void AcqTextStatus::Pulse(pkgAcquire
*Owner
)
130 pkgAcquireStatus::Pulse(Owner
);
132 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
135 char *End
= Buffer
+ sizeof(Buffer
);
138 // Put in the percent done
139 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
142 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
143 I
= Owner
->WorkerStep(I
))
147 // There is no item running
148 if (I
->CurrentItem
== 0)
150 if (I
->Status
.empty() == false)
152 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
161 // Add in the short description
162 if (I
->CurrentItem
->Owner
->ID
!= 0)
163 snprintf(S
,End
-S
," [%x %s",I
->CurrentItem
->Owner
->ID
,
164 I
->CurrentItem
->ShortDesc
.c_str());
166 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
169 // Show the short mode string
170 if (I
->CurrentItem
->Owner
->Mode
!= 0)
172 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
176 // Add the current progress
178 snprintf(S
,End
-S
," %u",I
->CurrentSize
);
181 if (Mode
== Medium
|| I
->TotalSize
== 0)
182 snprintf(S
,End
-S
," %s",SizeToStr(I
->CurrentSize
).c_str());
186 // Add the total size and percent
187 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
190 snprintf(S
,End
-S
," %u%%",
191 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
193 snprintf(S
,End
-S
,"/%s %u%%",SizeToStr(I
->TotalSize
).c_str(),
194 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
197 snprintf(S
,End
-S
,"]");
202 snprintf(S
,End
-S
," [Working]");
204 // Put in the ETA and cps meter
208 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
209 sprintf(Tmp
," %s/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
210 unsigned int Len
= strlen(Buffer
);
211 unsigned int LenT
= strlen(Tmp
);
212 if (Len
+ LenT
< ScreenWidth
)
214 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
215 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
218 Buffer
[ScreenWidth
] = 0;
220 // Draw the current status
221 if (strlen(Buffer
) == strlen(BlankLine
))
222 cout
<< '\r' << Buffer
<< flush
;
224 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
225 memset(BlankLine
,' ',strlen(Buffer
));
226 BlankLine
[strlen(Buffer
)] = 0;
231 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
232 // ---------------------------------------------------------------------
233 /* Prompt for a media swap */
234 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
237 cout
<< '\r' << BlankLine
<< '\r';
238 cout
<< "Media Change: Please insert the disc labeled '" << Media
<< "' in "\
239 "the drive '" << Drive
<< "' and press enter" << endl
;
242 while (C
!= '\n' && C
!= '\r')
243 read(STDIN_FILENO
,&C
,1);