mirror of
https://github.com/nushell/nushell
synced 2024-12-27 21:43:09 +00:00
Terminate REPL if not connected to tty input (#6480)
* Terminate REPL if not connected to tty input If the standard input stream is not a TTY abort the REPL execution. Solves a problem as the current REPL tries to be IO fault tolerant and would indefinetely fail when crossterm tries to handle the STDIN. Fixes nushell/nushell#6452 * Improve the error message
This commit is contained in:
parent
3278d290be
commit
33e1120add
3 changed files with 16 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2630,6 +2630,7 @@ dependencies = [
|
|||
name = "nu-cli"
|
||||
version = "0.67.1"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"chrono",
|
||||
"crossterm 0.24.0",
|
||||
"fancy-regex",
|
||||
|
|
|
@ -22,6 +22,7 @@ nu-ansi-term = "0.46.0"
|
|||
nu-color-config = { path = "../nu-color-config", version = "0.67.1" }
|
||||
reedline = { version = "0.10.0", features = ["bashisms", "sqlite"]}
|
||||
|
||||
atty = "0.2.14"
|
||||
chrono = "0.4.21"
|
||||
crossterm = "0.24.0"
|
||||
fancy-regex = "0.10.0"
|
||||
|
|
|
@ -43,6 +43,16 @@ pub fn evaluate_repl(
|
|||
) -> Result<()> {
|
||||
use reedline::{FileBackedHistory, Reedline, Signal};
|
||||
|
||||
// Guard against invocation without a connected terminal.
|
||||
// reedline / crossterm event polling will fail without a connected tty
|
||||
if !atty::is(atty::Stream::Stdin) {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::NotFound,
|
||||
"Nushell launched as interactive REPL but STDIN is not a TTY, either launch in a valid terminal or provide arguments to invoke a script!",
|
||||
))
|
||||
.into_diagnostic();
|
||||
}
|
||||
|
||||
let mut entry_num = 0;
|
||||
|
||||
let mut nu_prompt = NushellPrompt::new();
|
||||
|
@ -498,6 +508,10 @@ pub fn evaluate_repl(
|
|||
let message = err.to_string();
|
||||
if !message.contains("duration") {
|
||||
println!("Error: {:?}", err);
|
||||
// TODO: Identify possible error cases where a hard failure is preferable
|
||||
// Ignoring and reporting could hide bigger problems
|
||||
// e.g. https://github.com/nushell/nushell/issues/6452
|
||||
// Alternatively only allow that expected failures let the REPL loop
|
||||
}
|
||||
if shell_integration {
|
||||
run_ansi_sequence(&get_command_finished_marker(stack, engine_state))?;
|
||||
|
|
Loading…
Reference in a new issue