11use std:: collections:: VecDeque ;
22use std:: fmt;
33use std:: io:: Write ;
4+ use std:: sync:: { Arc , Mutex } ;
45use std:: time:: { Duration , Instant } ;
56
67use crate :: currentprocess:: { filesource:: StdoutSource , process, terminalsource} ;
@@ -13,6 +14,9 @@ use crate::Notification;
1314const DOWNLOAD_TRACK_COUNT : usize = 5 ;
1415
1516/// Tracks download progress and displays information about it to a terminal.
17+ ///
18+ /// *not* safe for tracking concurrent downloads yet - it is basically undefined
19+ /// what will happen.
1620pub ( crate ) struct DownloadTracker {
1721 /// Content-Length of the to-be downloaded object.
1822 content_len : Option < usize > ,
@@ -46,8 +50,8 @@ pub(crate) struct DownloadTracker {
4650
4751impl DownloadTracker {
4852 /// Creates a new DownloadTracker.
49- pub ( crate ) fn new ( ) -> Self {
50- Self {
53+ pub ( crate ) fn new_with_display_progress ( display_progress : bool ) -> Arc < Mutex < Self > > {
54+ Arc :: new ( Mutex :: new ( Self {
5155 content_len : None ,
5256 total_downloaded : 0 ,
5357 downloaded_this_sec : 0 ,
@@ -57,13 +61,8 @@ impl DownloadTracker {
5761 term : process ( ) . stdout ( ) . terminal ( ) ,
5862 displayed_charcount : None ,
5963 units : vec ! [ Unit :: B ] ,
60- display_progress : true ,
61- }
62- }
63-
64- pub ( crate ) fn with_display_progress ( mut self , display_progress : bool ) -> Self {
65- self . display_progress = display_progress;
66- self
64+ display_progress : display_progress,
65+ } ) )
6766 }
6867
6968 pub ( crate ) fn handle_notification ( & mut self , n : & Notification < ' _ > ) -> bool {
0 commit comments