File tree Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Expand file tree Collapse file tree 1 file changed +8
-13
lines changed Original file line number Diff line number Diff line change @@ -245,8 +245,15 @@ impl Term {
245
245
/// Read a single character from the terminal.
246
246
///
247
247
/// This does not echo the character and blocks until a single character
248
- /// is entered.
248
+ /// or complete key chord is entered. If the terminal is not user attended
249
+ /// the return value will be an error.
249
250
pub fn read_char ( & self ) -> io:: Result < char > {
251
+ if !self . is_tty {
252
+ return Err ( io:: Error :: new (
253
+ io:: ErrorKind :: NotConnected ,
254
+ "Not a terminal" ,
255
+ ) ) ;
256
+ }
250
257
loop {
251
258
match self . read_key ( ) ? {
252
259
Key :: Char ( c) => {
@@ -255,12 +262,6 @@ impl Term {
255
262
Key :: Enter => {
256
263
return Ok ( '\n' ) ;
257
264
}
258
- Key :: Unknown => {
259
- return Err ( io:: Error :: new (
260
- io:: ErrorKind :: NotConnected ,
261
- "Not a terminal" ,
262
- ) )
263
- }
264
265
_ => { }
265
266
}
266
267
}
@@ -324,12 +325,6 @@ impl Term {
324
325
self . write_line ( "" ) ?;
325
326
break ;
326
327
}
327
- Key :: Unknown => {
328
- return Err ( io:: Error :: new (
329
- io:: ErrorKind :: NotConnected ,
330
- "Not a terminal" ,
331
- ) )
332
- }
333
328
_ => ( ) ,
334
329
}
335
330
}
You can’t perform that action at this time.
0 commit comments