1
+ use crate :: term2;
1
2
use rustup:: dist:: Notification as In ;
2
3
use rustup:: utils:: tty;
3
4
use rustup:: utils:: Notification as Un ;
4
5
use rustup:: Notification ;
5
6
use std:: collections:: VecDeque ;
6
7
use std:: fmt;
8
+ use std:: io:: Write ;
9
+ use term:: Terminal ;
7
10
use time:: precise_time_s;
8
11
9
12
/// Keep track of this many past download amounts
@@ -25,7 +28,10 @@ pub struct DownloadTracker {
25
28
/// How many seconds have elapsed since the download started
26
29
seconds_elapsed : u32 ,
27
30
/// The terminal we write the information to.
28
- term : Option < Box < term:: StdoutTerminal > > ,
31
+ /// XXX: Could be a term trait, but with #1818 on the horizon that
32
+ /// is a pointless change to make - better to let that transition
33
+ /// happen and take stock after that.
34
+ term : term2:: StdoutTerminal ,
29
35
/// Whether we displayed progress for the download or not.
30
36
///
31
37
/// If the download is quick enough, we don't have time to
@@ -47,7 +53,7 @@ impl DownloadTracker {
47
53
downloaded_last_few_secs : VecDeque :: with_capacity ( DOWNLOAD_TRACK_COUNT ) ,
48
54
seconds_elapsed : 0 ,
49
55
last_sec : None ,
50
- term : term :: stdout ( ) ,
56
+ term : term2 :: stdout ( ) ,
51
57
displayed_charcount : None ,
52
58
}
53
59
}
@@ -60,7 +66,7 @@ impl DownloadTracker {
60
66
true
61
67
}
62
68
Notification :: Install ( In :: Utils ( Un :: DownloadDataReceived ( data) ) ) => {
63
- if tty:: stdout_isatty ( ) && self . term . is_some ( ) {
69
+ if tty:: stdout_isatty ( ) {
64
70
self . data_received ( data. len ( ) ) ;
65
71
}
66
72
true
@@ -108,7 +114,7 @@ impl DownloadTracker {
108
114
if self . displayed_charcount . is_some ( ) {
109
115
// Display the finished state
110
116
self . display ( ) ;
111
- let _ = writeln ! ( self . term. as_mut ( ) . unwrap ( ) ) ;
117
+ let _ = writeln ! ( self . term) ;
112
118
}
113
119
self . prepare_for_new_download ( ) ;
114
120
}
@@ -134,7 +140,7 @@ impl DownloadTracker {
134
140
let speed_h = HumanReadable ( speed) ;
135
141
136
142
// First, move to the start of the current line and clear it.
137
- let _ = self . term . as_mut ( ) . unwrap ( ) . carriage_return ( ) ;
143
+ let _ = self . term . carriage_return ( ) ;
138
144
// We'd prefer to use delete_line() but on Windows it seems to
139
145
// sometimes do unusual things
140
146
// let _ = self.term.as_mut().unwrap().delete_line();
@@ -143,9 +149,9 @@ impl DownloadTracker {
143
149
// This is not ideal as very narrow terminals might mess up,
144
150
// but it is more likely to succeed until term's windows console
145
151
// fixes whatever's up with delete_line().
146
- let _ = write ! ( self . term. as_mut ( ) . unwrap ( ) , "{}" , " " . repeat( n) ) ;
147
- let _ = self . term . as_mut ( ) . unwrap ( ) . flush ( ) ;
148
- let _ = self . term . as_mut ( ) . unwrap ( ) . carriage_return ( ) ;
152
+ let _ = write ! ( self . term, "{}" , " " . repeat( n) ) ;
153
+ let _ = self . term . flush ( ) ;
154
+ let _ = self . term . carriage_return ( ) ;
149
155
}
150
156
151
157
let output = match self . content_len {
@@ -163,9 +169,9 @@ impl DownloadTracker {
163
169
None => format ! ( "Total: {} Speed: {}/s" , total_h, speed_h) ,
164
170
} ;
165
171
166
- let _ = write ! ( self . term. as_mut ( ) . unwrap ( ) , "{}" , output) ;
172
+ let _ = write ! ( self . term, "{}" , output) ;
167
173
// Since stdout is typically line-buffered and we don't print a newline, we manually flush.
168
- let _ = self . term . as_mut ( ) . unwrap ( ) . flush ( ) ;
174
+ let _ = self . term . flush ( ) ;
169
175
self . displayed_charcount = Some ( output. chars ( ) . count ( ) ) ;
170
176
}
171
177
}
0 commit comments