3
3
use anyhow:: Context as _;
4
4
use crossterm:: tty:: IsTty as _;
5
5
6
- use crate :: user_output;
7
-
8
6
/// Use `rustup` to install the toolchain and components, if not already installed.
9
7
///
10
8
/// Pretty much runs:
11
9
///
12
10
/// * rustup toolchain add nightly-2024-04-24
13
11
/// * rustup component add --toolchain nightly-2024-04-24 rust-src rustc-dev llvm-tools
12
+ #[ inline]
14
13
pub fn ensure_toolchain_and_components_exist (
15
14
channel : & str ,
16
15
skip_toolchain_install_consent : bool ,
@@ -36,7 +35,7 @@ pub fn ensure_toolchain_and_components_exist(
36
35
format ! ( "Install {message}" ) . as_ref ( ) ,
37
36
skip_toolchain_install_consent,
38
37
) ?;
39
- crate :: user_output!( "Installing {message}\n " ) ;
38
+ crate :: user_output!( std :: io :: stdout ( ) , "Installing {message}\n " ) ? ;
40
39
41
40
let output_toolchain_add = std:: process:: Command :: new ( "rustup" )
42
41
. args ( [ "toolchain" , "add" ] )
@@ -79,7 +78,7 @@ pub fn ensure_toolchain_and_components_exist(
79
78
format ! ( "Install {message}" ) . as_ref ( ) ,
80
79
skip_toolchain_install_consent,
81
80
) ?;
82
- crate :: user_output!( "Installing {message}\n " ) ;
81
+ crate :: user_output!( std :: io :: stdout ( ) , "Installing {message}\n " ) ? ;
83
82
84
83
let output_component_add = std:: process:: Command :: new ( "rustup" )
85
84
. args ( [ "component" , "add" , "--toolchain" ] )
@@ -108,15 +107,18 @@ fn get_consent_for_toolchain_install(
108
107
}
109
108
110
109
if !std:: io:: stdout ( ) . is_tty ( ) {
111
- user_output ! ( "No TTY detected so can't ask for consent to install Rust toolchain." ) ;
110
+ crate :: user_output!(
111
+ std:: io:: stdout( ) ,
112
+ "No TTY detected so can't ask for consent to install Rust toolchain."
113
+ ) ?;
112
114
log:: error!( "Attempted to ask for consent when there's no TTY" ) ;
113
115
#[ expect( clippy:: exit, reason = "can't ask for user consent if there's no TTY" ) ]
114
116
std:: process:: exit ( 1 ) ;
115
117
}
116
118
117
119
log:: debug!( "asking for consent to install the required toolchain" ) ;
118
120
crossterm:: terminal:: enable_raw_mode ( ) . context ( "enabling raw mode" ) ?;
119
- crate :: user_output!( "{prompt} [y/n]: " ) ;
121
+ crate :: user_output!( std :: io :: stdout ( ) , "{prompt} [y/n]: " ) ? ;
120
122
let mut input = crossterm:: event:: read ( ) . context ( "reading crossterm event" ) ?;
121
123
122
124
if let crossterm:: event:: Event :: Key ( crossterm:: event:: KeyEvent {
@@ -138,7 +140,7 @@ fn get_consent_for_toolchain_install(
138
140
{
139
141
Ok ( ( ) )
140
142
} else {
141
- crate :: user_output!( "Exiting...\n " ) ;
143
+ crate :: user_output!( std :: io :: stdout ( ) , "Exiting...\n " ) ? ;
142
144
#[ expect( clippy:: exit, reason = "user requested abort" ) ]
143
145
std:: process:: exit ( 0 ) ;
144
146
}
0 commit comments