diff --git a/src/prompts/confirm.rs b/src/prompts/confirm.rs index 386105eb..46b5f9bb 100644 --- a/src/prompts/confirm.rs +++ b/src/prompts/confirm.rs @@ -150,6 +150,10 @@ impl Confirm<'_> { } fn _interact_on(self, term: &Term, allow_quit: bool) -> Result> { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + let mut render = TermThemeRenderer::new(term, self.theme); let default_if_show = if self.show_default { diff --git a/src/prompts/input.rs b/src/prompts/input.rs index 059bef86..31692b56 100644 --- a/src/prompts/input.rs +++ b/src/prompts/input.rs @@ -1,4 +1,4 @@ -use std::{cmp::Ordering, fmt::Debug, iter, str::FromStr}; +use std::{cmp::Ordering, fmt::Debug, io, iter, str::FromStr}; use console::{Key, Term}; @@ -288,6 +288,10 @@ where /// Like [`interact_text`](Self::interact_text) but allows a specific terminal to be set. pub fn interact_text_on(mut self, term: &Term) -> Result { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + let mut render = TermThemeRenderer::new(term, self.theme); loop { @@ -639,6 +643,10 @@ where /// Like [`interact`](Self::interact) but allows a specific terminal to be set. pub fn interact_on(mut self, term: &Term) -> Result { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + let mut render = TermThemeRenderer::new(term, self.theme); loop { diff --git a/src/prompts/multi_select.rs b/src/prompts/multi_select.rs index b044bf58..41cb89b9 100644 --- a/src/prompts/multi_select.rs +++ b/src/prompts/multi_select.rs @@ -196,6 +196,10 @@ impl MultiSelect<'_> { } fn _interact_on(self, term: &Term, allow_quit: bool) -> Result>> { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + if self.items.is_empty() { return Err(io::Error::new( io::ErrorKind::Other, diff --git a/src/prompts/password.rs b/src/prompts/password.rs index 78d7a298..6e1316e4 100644 --- a/src/prompts/password.rs +++ b/src/prompts/password.rs @@ -1,3 +1,5 @@ +use std::io; + use console::Term; use zeroize::Zeroizing; @@ -135,6 +137,10 @@ impl<'a> Password<'a> { /// Like [`interact`](Self::interact) but allows a specific terminal to be set. pub fn interact_on(self, term: &Term) -> Result { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + let mut render = TermThemeRenderer::new(term, self.theme); render.set_prompts_reset_height(false); diff --git a/src/prompts/select.rs b/src/prompts/select.rs index b5b1f765..81d06c30 100644 --- a/src/prompts/select.rs +++ b/src/prompts/select.rs @@ -185,6 +185,10 @@ impl Select<'_> { /// Like `interact` but allows a specific terminal to be set. fn _interact_on(self, term: &Term, allow_quit: bool) -> Result> { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + if self.items.is_empty() { return Err(io::Error::new( io::ErrorKind::Other, diff --git a/src/prompts/sort.rs b/src/prompts/sort.rs index dbce5aec..0e3aa7df 100644 --- a/src/prompts/sort.rs +++ b/src/prompts/sort.rs @@ -168,6 +168,10 @@ impl Sort<'_> { } fn _interact_on(self, term: &Term, allow_quit: bool) -> Result>> { + if !term.is_term() { + return Err(io::Error::new(io::ErrorKind::NotConnected, "not a terminal").into()); + } + if self.items.is_empty() { return Err(io::Error::new( io::ErrorKind::Other,