@@ -10,10 +10,9 @@ use std::{cmp, env};
10
10
use anyhow:: { anyhow, Context , Result } ;
11
11
use git_testament:: { git_testament, render_testament} ;
12
12
use lazy_static:: lazy_static;
13
- use term2:: Terminal ;
14
13
15
14
use super :: self_update;
16
- use super :: term2 ;
15
+ use super :: term ;
17
16
use crate :: utils:: notifications as util_notifications;
18
17
use crate :: utils:: notify:: NotificationLevel ;
19
18
use crate :: utils:: utils;
@@ -27,7 +26,7 @@ use crate::{Cfg, Notification};
27
26
pub ( crate ) const WARN_COMPLETE_PROFILE : & str = "downloading with complete profile isn't recommended unless you are a developer of the rust language" ;
28
27
29
28
pub ( crate ) fn confirm ( question : & str , default : bool ) -> Result < bool > {
30
- write ! ( process( ) . stdout( ) , "{question} " ) ?;
29
+ write ! ( process( ) . stdout( ) . lock ( ) , "{question} " ) ?;
31
30
let _ = std:: io:: stdout ( ) . flush ( ) ;
32
31
let input = read_line ( ) ?;
33
32
@@ -38,7 +37,7 @@ pub(crate) fn confirm(question: &str, default: bool) -> Result<bool> {
38
37
_ => false ,
39
38
} ;
40
39
41
- writeln ! ( process( ) . stdout( ) ) ?;
40
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
42
41
43
42
Ok ( r)
44
43
}
@@ -50,11 +49,14 @@ pub(crate) enum Confirm {
50
49
}
51
50
52
51
pub ( crate ) fn confirm_advanced ( ) -> Result < Confirm > {
53
- writeln ! ( process( ) . stdout( ) ) ?;
54
- writeln ! ( process( ) . stdout( ) , "1) Proceed with installation (default)" ) ?;
55
- writeln ! ( process( ) . stdout( ) , "2) Customize installation" ) ?;
56
- writeln ! ( process( ) . stdout( ) , "3) Cancel installation" ) ?;
57
- write ! ( process( ) . stdout( ) , ">" ) ?;
52
+ writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
53
+ writeln ! (
54
+ process( ) . stdout( ) . lock( ) ,
55
+ "1) Proceed with installation (default)"
56
+ ) ?;
57
+ writeln ! ( process( ) . stdout( ) . lock( ) , "2) Customize installation" ) ?;
58
+ writeln ! ( process( ) . stdout( ) . lock( ) , "3) Cancel installation" ) ?;
59
+ write ! ( process( ) . stdout( ) . lock( ) , ">" ) ?;
58
60
59
61
let _ = std:: io:: stdout ( ) . flush ( ) ;
60
62
let input = read_line ( ) ?;
@@ -65,17 +67,17 @@ pub(crate) fn confirm_advanced() -> Result<Confirm> {
65
67
_ => Confirm :: No ,
66
68
} ;
67
69
68
- writeln ! ( process( ) . stdout( ) ) ?;
70
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
69
71
70
72
Ok ( r)
71
73
}
72
74
73
75
pub ( crate ) fn question_str ( question : & str , default : & str ) -> Result < String > {
74
- writeln ! ( process( ) . stdout( ) , "{question} [{default}]" ) ?;
76
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} [{default}]" ) ?;
75
77
let _ = std:: io:: stdout ( ) . flush ( ) ;
76
78
let input = read_line ( ) ?;
77
79
78
- writeln ! ( process( ) . stdout( ) ) ?;
80
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
79
81
80
82
if input. is_empty ( ) {
81
83
Ok ( default. to_string ( ) )
@@ -86,12 +88,12 @@ pub(crate) fn question_str(question: &str, default: &str) -> Result<String> {
86
88
87
89
pub ( crate ) fn question_bool ( question : & str , default : bool ) -> Result < bool > {
88
90
let default_text = if default { "(Y/n)" } else { "(y/N)" } ;
89
- writeln ! ( process( ) . stdout( ) , "{question} {default_text}" ) ?;
91
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} {default_text}" ) ?;
90
92
91
93
let _ = std:: io:: stdout ( ) . flush ( ) ;
92
94
let input = read_line ( ) ?;
93
95
94
- writeln ! ( process( ) . stdout( ) ) ?;
96
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
95
97
96
98
if input. is_empty ( ) {
97
99
Ok ( default)
@@ -207,10 +209,10 @@ fn show_channel_updates(
207
209
) -> Result < ( ) > {
208
210
let data = updates. into_iter ( ) . map ( |( pkg, result) | {
209
211
let ( banner, color) = match & result {
210
- Ok ( UpdateStatus :: Installed ) => ( "installed" , Some ( term2 :: color :: GREEN ) ) ,
211
- Ok ( UpdateStatus :: Updated ( _) ) => ( "updated" , Some ( term2 :: color :: GREEN ) ) ,
212
+ Ok ( UpdateStatus :: Installed ) => ( "installed" , Some ( term :: Color :: Green ) ) ,
213
+ Ok ( UpdateStatus :: Updated ( _) ) => ( "updated" , Some ( term :: Color :: Green ) ) ,
212
214
Ok ( UpdateStatus :: Unchanged ) => ( "unchanged" , None ) ,
213
- Err ( _) => ( "update failed" , Some ( term2 :: color :: RED ) ) ,
215
+ Err ( _) => ( "update failed" , Some ( term :: Color :: Red ) ) ,
214
216
} ;
215
217
216
218
let ( previous_version, version) = match & pkg {
@@ -248,7 +250,7 @@ fn show_channel_updates(
248
250
Ok ( ( pkg, banner, width, color, version, previous_version) )
249
251
} ) ;
250
252
251
- let mut t = term2 :: stdout ( ) ;
253
+ let mut t = process ( ) . stdout ( ) ;
252
254
253
255
let data: Vec < _ > = data. collect :: < Result < _ > > ( ) ?;
254
256
let max_width = data
@@ -258,20 +260,20 @@ fn show_channel_updates(
258
260
for ( pkg, banner, width, color, version, previous_version) in data {
259
261
let padding = max_width - width;
260
262
let padding: String = " " . repeat ( padding) ;
261
- let _ = write ! ( t, " {padding}" ) ;
262
- let _ = t. attr ( term2 :: Attr :: Bold ) ;
263
+ let _ = write ! ( t. lock ( ) , " {padding}" ) ;
264
+ let _ = t. attr ( term :: Attr :: Bold ) ;
263
265
if let Some ( color) = color {
264
266
let _ = t. fg ( color) ;
265
267
}
266
- let _ = write ! ( t, "{pkg} {banner}" ) ;
268
+ let _ = write ! ( t. lock ( ) , "{pkg} {banner}" ) ;
267
269
let _ = t. reset ( ) ;
268
- let _ = write ! ( t, " - {version}" ) ;
270
+ let _ = write ! ( t. lock ( ) , " - {version}" ) ;
269
271
if let Some ( previous_version) = previous_version {
270
- let _ = write ! ( t, " (from {previous_version})" ) ;
272
+ let _ = write ! ( t. lock ( ) , " (from {previous_version})" ) ;
271
273
}
272
- let _ = writeln ! ( t) ;
274
+ let _ = writeln ! ( t. lock ( ) ) ;
273
275
}
274
- let _ = writeln ! ( t) ;
276
+ let _ = writeln ! ( t. lock ( ) ) ;
275
277
276
278
Ok ( ( ) )
277
279
}
@@ -289,7 +291,7 @@ pub(crate) fn update_all_channels(
289
291
290
292
let show_channel_updates = || {
291
293
if !toolchains. is_empty ( ) {
292
- writeln ! ( process( ) . stdout( ) ) ?;
294
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
293
295
294
296
let t = toolchains
295
297
. into_iter ( )
@@ -369,7 +371,7 @@ where
369
371
}
370
372
371
373
pub ( crate ) fn list_targets ( distributable : DistributableToolchain < ' _ > ) -> Result < utils:: ExitCode > {
372
- let mut t = term2 :: stdout ( ) ;
374
+ let mut t = process ( ) . stdout ( ) ;
373
375
let manifestation = distributable. get_manifestation ( ) ?;
374
376
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
375
377
let manifest = distributable. get_manifest ( ) ?;
@@ -382,11 +384,11 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
382
384
. as_ref ( )
383
385
. expect ( "rust-std should have a target" ) ;
384
386
if component. installed {
385
- let _ = t. attr ( term2 :: Attr :: Bold ) ;
386
- let _ = writeln ! ( t, "{target} (installed)" ) ;
387
+ let _ = t. attr ( term :: Attr :: Bold ) ;
388
+ let _ = writeln ! ( t. lock ( ) , "{target} (installed)" ) ;
387
389
let _ = t. reset ( ) ;
388
390
} else if component. available {
389
- let _ = writeln ! ( t, "{target}" ) ;
391
+ let _ = writeln ! ( t. lock ( ) , "{target}" ) ;
390
392
}
391
393
}
392
394
}
@@ -397,7 +399,9 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
397
399
pub ( crate ) fn list_installed_targets (
398
400
distributable : DistributableToolchain < ' _ > ,
399
401
) -> Result < utils:: ExitCode > {
400
- let mut t = term2:: stdout ( ) ;
402
+ let t = process ( ) . stdout ( ) ;
403
+ let mut t_lock = t. lock ( ) ;
404
+
401
405
let manifestation = distributable. get_manifestation ( ) ?;
402
406
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
403
407
let manifest = distributable. get_manifest ( ) ?;
@@ -410,7 +414,7 @@ pub(crate) fn list_installed_targets(
410
414
. as_ref ( )
411
415
. expect ( "rust-std should have a target" ) ;
412
416
if component. installed {
413
- writeln ! ( t , "{target}" ) ?;
417
+ writeln ! ( t_lock , "{target}" ) ?;
414
418
}
415
419
}
416
420
}
@@ -420,35 +424,36 @@ pub(crate) fn list_installed_targets(
420
424
pub ( crate ) fn list_components (
421
425
distributable : DistributableToolchain < ' _ > ,
422
426
) -> Result < utils:: ExitCode > {
423
- let mut t = term2:: stdout ( ) ;
427
+ let mut t = process ( ) . stdout ( ) ;
428
+
424
429
let manifestation = distributable. get_manifestation ( ) ?;
425
430
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
426
431
let manifest = distributable. get_manifest ( ) ?;
427
432
let components = manifest. query_components ( distributable. desc ( ) , & config) ?;
428
433
for component in components {
429
434
let name = component. name ;
430
435
if component. installed {
431
- t. attr ( term2 :: Attr :: Bold ) ?;
432
- writeln ! ( t, "{name} (installed)" ) ?;
436
+ t. attr ( term :: Attr :: Bold ) ?;
437
+ writeln ! ( t. lock ( ) , "{name} (installed)" ) ?;
433
438
t. reset ( ) ?;
434
439
} else if component. available {
435
- writeln ! ( t, "{name}" ) ?;
440
+ writeln ! ( t. lock ( ) , "{name}" ) ?;
436
441
}
437
442
}
438
443
439
444
Ok ( utils:: ExitCode ( 0 ) )
440
445
}
441
446
442
447
pub ( crate ) fn list_installed_components ( distributable : DistributableToolchain < ' _ > ) -> Result < ( ) > {
443
- let mut t = term2 :: stdout ( ) ;
448
+ let t = process ( ) . stdout ( ) ;
444
449
let manifestation = distributable. get_manifestation ( ) ?;
445
450
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
446
451
let manifest = distributable. get_manifest ( ) ?;
447
452
let components = manifest. query_components ( distributable. desc ( ) , & config) ?;
448
453
449
454
for component in components {
450
455
if component. installed {
451
- writeln ! ( t, "{}" , component. name) ?;
456
+ writeln ! ( t. lock ( ) , "{}" , component. name) ?;
452
457
}
453
458
}
454
459
Ok ( ( ) )
@@ -473,7 +478,7 @@ fn print_toolchain_path(
473
478
String :: new ( )
474
479
} ;
475
480
writeln ! (
476
- process( ) . stdout( ) ,
481
+ process( ) . stdout( ) . lock ( ) ,
477
482
"{}{}{}{}" ,
478
483
& toolchain,
479
484
if_default,
@@ -491,7 +496,7 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
491
496
. map ( Into :: into)
492
497
. collect :: < Vec < _ > > ( ) ;
493
498
if toolchains. is_empty ( ) {
494
- writeln ! ( process( ) . stdout( ) , "no installed toolchains" ) ?;
499
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no installed toolchains" ) ?;
495
500
} else {
496
501
let def_toolchain_name = cfg. get_default ( ) ?. map ( |t| ( & t) . into ( ) ) ;
497
502
let cwd = utils:: current_dir ( ) ?;
@@ -529,7 +534,7 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
529
534
let overrides = cfg. settings_file . with ( |s| Ok ( s. overrides . clone ( ) ) ) ?;
530
535
531
536
if overrides. is_empty ( ) {
532
- writeln ! ( process( ) . stdout( ) , "no overrides" ) ?;
537
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no overrides" ) ?;
533
538
} else {
534
539
let mut any_not_exist = false ;
535
540
for ( k, v) in overrides {
@@ -538,15 +543,15 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
538
543
any_not_exist = true ;
539
544
}
540
545
writeln ! (
541
- process( ) . stdout( ) ,
546
+ process( ) . stdout( ) . lock ( ) ,
542
547
"{:<40}\t {:<20}" ,
543
548
utils:: format_path_for_display( & k)
544
549
+ if dir_exists { "" } else { " (not a directory)" } ,
545
550
v
546
551
) ?
547
552
}
548
553
if any_not_exist {
549
- writeln ! ( process( ) . stdout( ) ) ?;
554
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
550
555
info ! (
551
556
"you may remove overrides for non-existent directories with
552
557
`rustup override unset --nonexistent`"
@@ -571,43 +576,51 @@ pub(crate) fn version() -> &'static str {
571
576
pub ( crate ) fn dump_testament ( ) -> Result < utils:: ExitCode > {
572
577
use git_testament:: GitModification :: * ;
573
578
writeln ! (
574
- process( ) . stdout( ) ,
579
+ process( ) . stdout( ) . lock ( ) ,
575
580
"Rustup version renders as: {}" ,
576
581
version( )
577
582
) ?;
578
583
writeln ! (
579
- process( ) . stdout( ) ,
584
+ process( ) . stdout( ) . lock ( ) ,
580
585
"Current crate version: {}" ,
581
586
env!( "CARGO_PKG_VERSION" )
582
587
) ?;
583
588
if TESTAMENT . branch_name . is_some ( ) {
584
589
writeln ! (
585
- process( ) . stdout( ) ,
590
+ process( ) . stdout( ) . lock ( ) ,
586
591
"Built from branch: {}" ,
587
592
TESTAMENT . branch_name. unwrap( )
588
593
) ?;
589
594
} else {
590
- writeln ! ( process( ) . stdout( ) , "Branch information missing" ) ?;
595
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Branch information missing" ) ?;
591
596
}
592
- writeln ! ( process( ) . stdout( ) , "Commit info: {}" , TESTAMENT . commit) ?;
597
+ writeln ! (
598
+ process( ) . stdout( ) . lock( ) ,
599
+ "Commit info: {}" ,
600
+ TESTAMENT . commit
601
+ ) ?;
593
602
if TESTAMENT . modifications . is_empty ( ) {
594
- writeln ! ( process( ) . stdout( ) , "Working tree is clean" ) ?;
603
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Working tree is clean" ) ?;
595
604
} else {
596
605
for fmod in TESTAMENT . modifications {
597
606
match fmod {
598
- Added ( f) => writeln ! ( process( ) . stdout( ) , "Added: {}" , String :: from_utf8_lossy( f) ) ?,
607
+ Added ( f) => writeln ! (
608
+ process( ) . stdout( ) . lock( ) ,
609
+ "Added: {}" ,
610
+ String :: from_utf8_lossy( f)
611
+ ) ?,
599
612
Removed ( f) => writeln ! (
600
- process( ) . stdout( ) ,
613
+ process( ) . stdout( ) . lock ( ) ,
601
614
"Removed: {}" ,
602
615
String :: from_utf8_lossy( f)
603
616
) ?,
604
617
Modified ( f) => writeln ! (
605
- process( ) . stdout( ) ,
618
+ process( ) . stdout( ) . lock ( ) ,
606
619
"Modified: {}" ,
607
620
String :: from_utf8_lossy( f)
608
621
) ?,
609
622
Untracked ( f) => writeln ! (
610
- process( ) . stdout( ) ,
623
+ process( ) . stdout( ) . lock ( ) ,
611
624
"Untracked: {}" ,
612
625
String :: from_utf8_lossy( f)
613
626
) ?,
0 commit comments