]>
git.saurik.com Git - apt.git/blob - cmdline/acqprogress.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: acqprogress.cc,v 1.16 1999/07/03 03:10:35 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
)
95 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatIdle
)
99 cout
<< '\r' << BlankLine
<< '\r';
101 if (Itm
.Owner
->Status
== pkgAcquire::Item::StatDone
)
103 cout
<< "Ign " << Itm
.Description
<< endl
;
107 cout
<< "Err " << Itm
.Description
<< endl
;
108 cout
<< " " << Itm
.Owner
->ErrorText
<< endl
;
114 // AcqTextStatus::Stop - Finished downloading /*{{{*/
115 // ---------------------------------------------------------------------
116 /* This prints out the bytes downloaded and the overall average line
118 void AcqTextStatus::Stop()
120 pkgAcquireStatus::Stop();
125 cout
<< '\r' << BlankLine
<< '\r';
127 if (FetchedBytes
!= 0)
128 cout
<< "Fetched " << SizeToStr(FetchedBytes
) << "B in " <<
129 TimeToStr(ElapsedTime
) << " (" << SizeToStr(CurrentCPS
) <<
133 // AcqTextStatus::Pulse - Regular event pulse /*{{{*/
134 // ---------------------------------------------------------------------
135 /* This draws the current progress. Each line has an overall percent
136 meter and a per active item status meter along with an overall
137 bandwidth and ETA indicator. */
138 bool AcqTextStatus::Pulse(pkgAcquire
*Owner
)
143 pkgAcquireStatus::Pulse(Owner
);
145 enum {Long
= 0,Medium
,Short
} Mode
= Long
;
148 char *End
= Buffer
+ sizeof(Buffer
);
151 // Put in the percent done
152 sprintf(S
,"%ld%%",long(double((CurrentBytes
+ CurrentItems
)*100.0)/double(TotalBytes
+TotalItems
)));
155 for (pkgAcquire::Worker
*I
= Owner
->WorkersBegin(); I
!= 0;
156 I
= Owner
->WorkerStep(I
))
160 // There is no item running
161 if (I
->CurrentItem
== 0)
163 if (I
->Status
.empty() == false)
165 snprintf(S
,End
-S
," [%s]",I
->Status
.c_str());
174 // Add in the short description
175 if (I
->CurrentItem
->Owner
->ID
!= 0)
176 snprintf(S
,End
-S
," [%lu %s",I
->CurrentItem
->Owner
->ID
,
177 I
->CurrentItem
->ShortDesc
.c_str());
179 snprintf(S
,End
-S
," [%s",I
->CurrentItem
->ShortDesc
.c_str());
182 // Show the short mode string
183 if (I
->CurrentItem
->Owner
->Mode
!= 0)
185 snprintf(S
,End
-S
," %s",I
->CurrentItem
->Owner
->Mode
);
189 // Add the current progress
191 snprintf(S
,End
-S
," %lu",I
->CurrentSize
);
194 if (Mode
== Medium
|| I
->TotalSize
== 0)
195 snprintf(S
,End
-S
," %sB",SizeToStr(I
->CurrentSize
).c_str());
199 // Add the total size and percent
200 if (I
->TotalSize
> 0 && I
->CurrentItem
->Owner
->Complete
== false)
203 snprintf(S
,End
-S
," %lu%%",
204 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
206 snprintf(S
,End
-S
,"/%sB %lu%%",SizeToStr(I
->TotalSize
).c_str(),
207 long(double(I
->CurrentSize
*100.0)/double(I
->TotalSize
)));
210 snprintf(S
,End
-S
,"]");
215 snprintf(S
,End
-S
," [Working]");
217 /* Put in the ETA and cps meter, block off signals to prevent strangeness
219 sigset_t Sigs
,OldSigs
;
221 sigaddset(&Sigs
,SIGWINCH
);
222 sigprocmask(SIG_BLOCK
,&Sigs
,&OldSigs
);
227 unsigned long ETA
= (unsigned long)((TotalBytes
- CurrentBytes
)/CurrentCPS
);
228 sprintf(Tmp
," %sB/s %s",SizeToStr(CurrentCPS
).c_str(),TimeToStr(ETA
).c_str());
229 unsigned int Len
= strlen(Buffer
);
230 unsigned int LenT
= strlen(Tmp
);
231 if (Len
+ LenT
< ScreenWidth
)
233 memset(Buffer
+ Len
,' ',ScreenWidth
- Len
);
234 strcpy(Buffer
+ ScreenWidth
- LenT
,Tmp
);
237 Buffer
[ScreenWidth
] = 0;
238 BlankLine
[ScreenWidth
] = 0;
239 sigprocmask(SIG_UNBLOCK
,&OldSigs
,0);
241 // Draw the current status
242 if (strlen(Buffer
) == strlen(BlankLine
))
243 cout
<< '\r' << Buffer
<< flush
;
245 cout
<< '\r' << BlankLine
<< '\r' << Buffer
<< flush
;
246 memset(BlankLine
,' ',strlen(Buffer
));
247 BlankLine
[strlen(Buffer
)] = 0;
254 // AcqTextStatus::MediaChange - Media need to be swapped /*{{{*/
255 // ---------------------------------------------------------------------
256 /* Prompt for a media swap */
257 bool AcqTextStatus::MediaChange(string Media
,string Drive
)
260 cout
<< '\r' << BlankLine
<< '\r';
261 cout
<< "Media Change: Please insert the disc labeled '" << Media
<< "' in "\
262 "the drive '" << Drive
<< "' and press enter" << endl
;
265 while (C
!= '\n' && C
!= '\r')
266 read(STDIN_FILENO
,&C
,1);