Skip to content

Commit 7fc4560

Browse files
authored
fix: better output when consent is required without at a TTY (#98)
Fixes #95
1 parent 6a192d8 commit 7fc4560

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

crates/cargo-gpu/src/install_toolchain.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! toolchain installation logic
22
33
use anyhow::Context as _;
4+
use crossterm::tty::IsTty as _;
5+
6+
use crate::user_output;
47

58
/// Use `rustup` to install the toolchain and components, if not already installed.
69
///
@@ -103,9 +106,17 @@ fn get_consent_for_toolchain_install(
103106
if skip_toolchain_install_consent {
104107
return Ok(());
105108
}
109+
110+
if !std::io::stdout().is_tty() {
111+
user_output!("No TTY detected so can't ask for consent to install Rust toolchain.");
112+
log::error!("Attempted to ask for consent when there's no TTY");
113+
#[expect(clippy::exit, reason = "can't ask for user consent if there's no TTY")]
114+
std::process::exit(1);
115+
}
116+
106117
log::debug!("asking for consent to install the required toolchain");
107118
crossterm::terminal::enable_raw_mode().context("enabling raw mode")?;
108-
crate::user_output!("{prompt} [y/n]: \n");
119+
crate::user_output!("{prompt} [y/n]: ");
109120
let mut input = crossterm::event::read().context("reading crossterm event")?;
110121

111122
if let crossterm::event::Event::Key(crossterm::event::KeyEvent {

0 commit comments

Comments
 (0)