@@ -10,13 +10,12 @@ 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;
17
- use crate :: currentprocess:: argsource:: ArgSource ;
18
15
use crate :: currentprocess:: {
16
+ argsource:: ArgSource ,
19
17
filesource:: { StdinSource , StdoutSource } ,
18
+ terminalsource,
20
19
varsource:: VarSource ,
21
20
} ;
22
21
use crate :: utils:: notifications as util_notifications;
@@ -32,7 +31,7 @@ use crate::{Cfg, Notification};
32
31
pub ( crate ) const WARN_COMPLETE_PROFILE : & str = "downloading with complete profile isn't recommended unless you are a developer of the rust language" ;
33
32
34
33
pub ( crate ) fn confirm ( question : & str , default : bool ) -> Result < bool > {
35
- write ! ( process( ) . stdout( ) , "{question} " ) ?;
34
+ write ! ( process( ) . stdout( ) . lock ( ) , "{question} " ) ?;
36
35
let _ = std:: io:: stdout ( ) . flush ( ) ;
37
36
let input = read_line ( ) ?;
38
37
@@ -43,7 +42,7 @@ pub(crate) fn confirm(question: &str, default: bool) -> Result<bool> {
43
42
_ => false ,
44
43
} ;
45
44
46
- writeln ! ( process( ) . stdout( ) ) ?;
45
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
47
46
48
47
Ok ( r)
49
48
}
@@ -55,11 +54,14 @@ pub(crate) enum Confirm {
55
54
}
56
55
57
56
pub ( crate ) fn confirm_advanced ( ) -> Result < Confirm > {
58
- writeln ! ( process( ) . stdout( ) ) ?;
59
- writeln ! ( process( ) . stdout( ) , "1) Proceed with installation (default)" ) ?;
60
- writeln ! ( process( ) . stdout( ) , "2) Customize installation" ) ?;
61
- writeln ! ( process( ) . stdout( ) , "3) Cancel installation" ) ?;
62
- write ! ( process( ) . stdout( ) , ">" ) ?;
57
+ writeln ! ( process( ) . stdout( ) . lock( ) ) ?;
58
+ writeln ! (
59
+ process( ) . stdout( ) . lock( ) ,
60
+ "1) Proceed with installation (default)"
61
+ ) ?;
62
+ writeln ! ( process( ) . stdout( ) . lock( ) , "2) Customize installation" ) ?;
63
+ writeln ! ( process( ) . stdout( ) . lock( ) , "3) Cancel installation" ) ?;
64
+ write ! ( process( ) . stdout( ) . lock( ) , ">" ) ?;
63
65
64
66
let _ = std:: io:: stdout ( ) . flush ( ) ;
65
67
let input = read_line ( ) ?;
@@ -70,17 +72,17 @@ pub(crate) fn confirm_advanced() -> Result<Confirm> {
70
72
_ => Confirm :: No ,
71
73
} ;
72
74
73
- writeln ! ( process( ) . stdout( ) ) ?;
75
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
74
76
75
77
Ok ( r)
76
78
}
77
79
78
80
pub ( crate ) fn question_str ( question : & str , default : & str ) -> Result < String > {
79
- writeln ! ( process( ) . stdout( ) , "{question} [{default}]" ) ?;
81
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} [{default}]" ) ?;
80
82
let _ = std:: io:: stdout ( ) . flush ( ) ;
81
83
let input = read_line ( ) ?;
82
84
83
- writeln ! ( process( ) . stdout( ) ) ?;
85
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
84
86
85
87
if input. is_empty ( ) {
86
88
Ok ( default. to_string ( ) )
@@ -91,12 +93,12 @@ pub(crate) fn question_str(question: &str, default: &str) -> Result<String> {
91
93
92
94
pub ( crate ) fn question_bool ( question : & str , default : bool ) -> Result < bool > {
93
95
let default_text = if default { "(Y/n)" } else { "(y/N)" } ;
94
- writeln ! ( process( ) . stdout( ) , "{question} {default_text}" ) ?;
96
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "{question} {default_text}" ) ?;
95
97
96
98
let _ = std:: io:: stdout ( ) . flush ( ) ;
97
99
let input = read_line ( ) ?;
98
100
99
- writeln ! ( process( ) . stdout( ) ) ?;
101
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
100
102
101
103
if input. is_empty ( ) {
102
104
Ok ( default)
@@ -212,10 +214,10 @@ fn show_channel_updates(
212
214
) -> Result < ( ) > {
213
215
let data = updates. into_iter ( ) . map ( |( pkg, result) | {
214
216
let ( banner, color) = match & result {
215
- Ok ( UpdateStatus :: Installed ) => ( "installed" , Some ( term2 :: color :: GREEN ) ) ,
216
- Ok ( UpdateStatus :: Updated ( _) ) => ( "updated" , Some ( term2 :: color :: GREEN ) ) ,
217
+ Ok ( UpdateStatus :: Installed ) => ( "installed" , Some ( terminalsource :: Color :: Green ) ) ,
218
+ Ok ( UpdateStatus :: Updated ( _) ) => ( "updated" , Some ( terminalsource :: Color :: Green ) ) ,
217
219
Ok ( UpdateStatus :: Unchanged ) => ( "unchanged" , None ) ,
218
- Err ( _) => ( "update failed" , Some ( term2 :: color :: RED ) ) ,
220
+ Err ( _) => ( "update failed" , Some ( terminalsource :: Color :: Red ) ) ,
219
221
} ;
220
222
221
223
let ( previous_version, version) = match & pkg {
@@ -253,7 +255,7 @@ fn show_channel_updates(
253
255
Ok ( ( pkg, banner, width, color, version, previous_version) )
254
256
} ) ;
255
257
256
- let mut t = term2 :: stdout ( ) ;
258
+ let mut t = process ( ) . stdout ( ) . terminal ( ) ;
257
259
258
260
let data: Vec < _ > = data. collect :: < Result < _ > > ( ) ?;
259
261
let max_width = data
@@ -263,20 +265,20 @@ fn show_channel_updates(
263
265
for ( pkg, banner, width, color, version, previous_version) in data {
264
266
let padding = max_width - width;
265
267
let padding: String = " " . repeat ( padding) ;
266
- let _ = write ! ( t, " {padding}" ) ;
267
- let _ = t. attr ( term2 :: Attr :: Bold ) ;
268
+ let _ = write ! ( t. lock ( ) , " {padding}" ) ;
269
+ let _ = t. attr ( terminalsource :: Attr :: Bold ) ;
268
270
if let Some ( color) = color {
269
271
let _ = t. fg ( color) ;
270
272
}
271
- let _ = write ! ( t, "{pkg} {banner}" ) ;
273
+ let _ = write ! ( t. lock ( ) , "{pkg} {banner}" ) ;
272
274
let _ = t. reset ( ) ;
273
- let _ = write ! ( t, " - {version}" ) ;
275
+ let _ = write ! ( t. lock ( ) , " - {version}" ) ;
274
276
if let Some ( previous_version) = previous_version {
275
- let _ = write ! ( t, " (from {previous_version})" ) ;
277
+ let _ = write ! ( t. lock ( ) , " (from {previous_version})" ) ;
276
278
}
277
- let _ = writeln ! ( t) ;
279
+ let _ = writeln ! ( t. lock ( ) ) ;
278
280
}
279
- let _ = writeln ! ( t) ;
281
+ let _ = writeln ! ( t. lock ( ) ) ;
280
282
281
283
Ok ( ( ) )
282
284
}
@@ -294,7 +296,7 @@ pub(crate) fn update_all_channels(
294
296
295
297
let show_channel_updates = || {
296
298
if !toolchains. is_empty ( ) {
297
- writeln ! ( process( ) . stdout( ) ) ?;
299
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
298
300
299
301
let t = toolchains
300
302
. into_iter ( )
@@ -374,7 +376,7 @@ where
374
376
}
375
377
376
378
pub ( crate ) fn list_targets ( distributable : DistributableToolchain < ' _ > ) -> Result < utils:: ExitCode > {
377
- let mut t = term2 :: stdout ( ) ;
379
+ let mut t = process ( ) . stdout ( ) . terminal ( ) ;
378
380
let manifestation = distributable. get_manifestation ( ) ?;
379
381
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
380
382
let manifest = distributable. get_manifest ( ) ?;
@@ -387,11 +389,11 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
387
389
. as_ref ( )
388
390
. expect ( "rust-std should have a target" ) ;
389
391
if component. installed {
390
- let _ = t. attr ( term2 :: Attr :: Bold ) ;
391
- let _ = writeln ! ( t, "{target} (installed)" ) ;
392
+ let _ = t. attr ( terminalsource :: Attr :: Bold ) ;
393
+ let _ = writeln ! ( t. lock ( ) , "{target} (installed)" ) ;
392
394
let _ = t. reset ( ) ;
393
395
} else if component. available {
394
- let _ = writeln ! ( t, "{target}" ) ;
396
+ let _ = writeln ! ( t. lock ( ) , "{target}" ) ;
395
397
}
396
398
}
397
399
}
@@ -402,7 +404,7 @@ pub(crate) fn list_targets(distributable: DistributableToolchain<'_>) -> Result<
402
404
pub ( crate ) fn list_installed_targets (
403
405
distributable : DistributableToolchain < ' _ > ,
404
406
) -> Result < utils:: ExitCode > {
405
- let mut t = term2 :: stdout ( ) ;
407
+ let t = process ( ) . stdout ( ) ;
406
408
let manifestation = distributable. get_manifestation ( ) ?;
407
409
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
408
410
let manifest = distributable. get_manifest ( ) ?;
@@ -415,7 +417,7 @@ pub(crate) fn list_installed_targets(
415
417
. as_ref ( )
416
418
. expect ( "rust-std should have a target" ) ;
417
419
if component. installed {
418
- writeln ! ( t, "{target}" ) ?;
420
+ writeln ! ( t. lock ( ) , "{target}" ) ?;
419
421
}
420
422
}
421
423
}
@@ -425,35 +427,36 @@ pub(crate) fn list_installed_targets(
425
427
pub ( crate ) fn list_components (
426
428
distributable : DistributableToolchain < ' _ > ,
427
429
) -> Result < utils:: ExitCode > {
428
- let mut t = term2:: stdout ( ) ;
430
+ let mut t = process ( ) . stdout ( ) . terminal ( ) ;
431
+
429
432
let manifestation = distributable. get_manifestation ( ) ?;
430
433
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
431
434
let manifest = distributable. get_manifest ( ) ?;
432
435
let components = manifest. query_components ( distributable. desc ( ) , & config) ?;
433
436
for component in components {
434
437
let name = component. name ;
435
438
if component. installed {
436
- t. attr ( term2 :: Attr :: Bold ) ?;
437
- writeln ! ( t, "{name} (installed)" ) ?;
439
+ t. attr ( terminalsource :: Attr :: Bold ) ?;
440
+ writeln ! ( t. lock ( ) , "{name} (installed)" ) ?;
438
441
t. reset ( ) ?;
439
442
} else if component. available {
440
- writeln ! ( t, "{name}" ) ?;
443
+ writeln ! ( t. lock ( ) , "{name}" ) ?;
441
444
}
442
445
}
443
446
444
447
Ok ( utils:: ExitCode ( 0 ) )
445
448
}
446
449
447
450
pub ( crate ) fn list_installed_components ( distributable : DistributableToolchain < ' _ > ) -> Result < ( ) > {
448
- let mut t = term2 :: stdout ( ) ;
451
+ let t = process ( ) . stdout ( ) ;
449
452
let manifestation = distributable. get_manifestation ( ) ?;
450
453
let config = manifestation. read_config ( ) ?. unwrap_or_default ( ) ;
451
454
let manifest = distributable. get_manifest ( ) ?;
452
455
let components = manifest. query_components ( distributable. desc ( ) , & config) ?;
453
456
454
457
for component in components {
455
458
if component. installed {
456
- writeln ! ( t, "{}" , component. name) ?;
459
+ writeln ! ( t. lock ( ) , "{}" , component. name) ?;
457
460
}
458
461
}
459
462
Ok ( ( ) )
@@ -478,7 +481,7 @@ fn print_toolchain_path(
478
481
String :: new ( )
479
482
} ;
480
483
writeln ! (
481
- process( ) . stdout( ) ,
484
+ process( ) . stdout( ) . lock ( ) ,
482
485
"{}{}{}{}" ,
483
486
& toolchain,
484
487
if_default,
@@ -496,7 +499,7 @@ pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCod
496
499
. map ( Into :: into)
497
500
. collect :: < Vec < _ > > ( ) ;
498
501
if toolchains. is_empty ( ) {
499
- writeln ! ( process( ) . stdout( ) , "no installed toolchains" ) ?;
502
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no installed toolchains" ) ?;
500
503
} else {
501
504
let def_toolchain_name = cfg. get_default ( ) ?. map ( |t| ( & t) . into ( ) ) ;
502
505
let cwd = utils:: current_dir ( ) ?;
@@ -534,7 +537,7 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
534
537
let overrides = cfg. settings_file . with ( |s| Ok ( s. overrides . clone ( ) ) ) ?;
535
538
536
539
if overrides. is_empty ( ) {
537
- writeln ! ( process( ) . stdout( ) , "no overrides" ) ?;
540
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "no overrides" ) ?;
538
541
} else {
539
542
let mut any_not_exist = false ;
540
543
for ( k, v) in overrides {
@@ -543,15 +546,15 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
543
546
any_not_exist = true ;
544
547
}
545
548
writeln ! (
546
- process( ) . stdout( ) ,
549
+ process( ) . stdout( ) . lock ( ) ,
547
550
"{:<40}\t {:<20}" ,
548
551
utils:: format_path_for_display( & k)
549
552
+ if dir_exists { "" } else { " (not a directory)" } ,
550
553
v
551
554
) ?
552
555
}
553
556
if any_not_exist {
554
- writeln ! ( process( ) . stdout( ) ) ?;
557
+ writeln ! ( process( ) . stdout( ) . lock ( ) ) ?;
555
558
info ! (
556
559
"you may remove overrides for non-existent directories with
557
560
`rustup override unset --nonexistent`"
@@ -576,43 +579,51 @@ pub(crate) fn version() -> &'static str {
576
579
pub ( crate ) fn dump_testament ( ) -> Result < utils:: ExitCode > {
577
580
use git_testament:: GitModification :: * ;
578
581
writeln ! (
579
- process( ) . stdout( ) ,
582
+ process( ) . stdout( ) . lock ( ) ,
580
583
"Rustup version renders as: {}" ,
581
584
version( )
582
585
) ?;
583
586
writeln ! (
584
- process( ) . stdout( ) ,
587
+ process( ) . stdout( ) . lock ( ) ,
585
588
"Current crate version: {}" ,
586
589
env!( "CARGO_PKG_VERSION" )
587
590
) ?;
588
591
if TESTAMENT . branch_name . is_some ( ) {
589
592
writeln ! (
590
- process( ) . stdout( ) ,
593
+ process( ) . stdout( ) . lock ( ) ,
591
594
"Built from branch: {}" ,
592
595
TESTAMENT . branch_name. unwrap( )
593
596
) ?;
594
597
} else {
595
- writeln ! ( process( ) . stdout( ) , "Branch information missing" ) ?;
598
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Branch information missing" ) ?;
596
599
}
597
- writeln ! ( process( ) . stdout( ) , "Commit info: {}" , TESTAMENT . commit) ?;
600
+ writeln ! (
601
+ process( ) . stdout( ) . lock( ) ,
602
+ "Commit info: {}" ,
603
+ TESTAMENT . commit
604
+ ) ?;
598
605
if TESTAMENT . modifications . is_empty ( ) {
599
- writeln ! ( process( ) . stdout( ) , "Working tree is clean" ) ?;
606
+ writeln ! ( process( ) . stdout( ) . lock ( ) , "Working tree is clean" ) ?;
600
607
} else {
601
608
for fmod in TESTAMENT . modifications {
602
609
match fmod {
603
- Added ( f) => writeln ! ( process( ) . stdout( ) , "Added: {}" , String :: from_utf8_lossy( f) ) ?,
610
+ Added ( f) => writeln ! (
611
+ process( ) . stdout( ) . lock( ) ,
612
+ "Added: {}" ,
613
+ String :: from_utf8_lossy( f)
614
+ ) ?,
604
615
Removed ( f) => writeln ! (
605
- process( ) . stdout( ) ,
616
+ process( ) . stdout( ) . lock ( ) ,
606
617
"Removed: {}" ,
607
618
String :: from_utf8_lossy( f)
608
619
) ?,
609
620
Modified ( f) => writeln ! (
610
- process( ) . stdout( ) ,
621
+ process( ) . stdout( ) . lock ( ) ,
611
622
"Modified: {}" ,
612
623
String :: from_utf8_lossy( f)
613
624
) ?,
614
625
Untracked ( f) => writeln ! (
615
- process( ) . stdout( ) ,
626
+ process( ) . stdout( ) . lock ( ) ,
616
627
"Untracked: {}" ,
617
628
String :: from_utf8_lossy( f)
618
629
) ?,
0 commit comments