diff --git a/src/term.rs b/src/term.rs index 1715a2ff..0a402585 100644 --- a/src/term.rs +++ b/src/term.rs @@ -245,8 +245,15 @@ impl Term { /// Read a single character from the terminal. /// /// This does not echo the character and blocks until a single character - /// is entered. + /// or complete key chord is entered. If the terminal is not user attended + /// the return value will be an error. pub fn read_char(&self) -> io::Result { + if !self.is_tty { + return Err(io::Error::new( + io::ErrorKind::NotConnected, + "Not a terminal", + )); + } loop { match self.read_key()? { Key::Char(c) => { @@ -255,12 +262,6 @@ impl Term { Key::Enter => { return Ok('\n'); } - Key::Unknown => { - return Err(io::Error::new( - io::ErrorKind::NotConnected, - "Not a terminal", - )) - } _ => {} } } @@ -324,12 +325,6 @@ impl Term { self.write_line("")?; break; } - Key::Unknown => { - return Err(io::Error::new( - io::ErrorKind::NotConnected, - "Not a terminal", - )) - } _ => (), } }