(&mut self, prompt: &str)
| 47 | } |
| 48 | |
| 49 | pub fn readline(&mut self, prompt: &str) -> ReadlineResult { |
| 50 | use std::io::prelude::*; |
| 51 | print!("{prompt}"); |
| 52 | if let Err(e) = io::stdout().flush() { |
| 53 | return ReadlineResult::Io(e); |
| 54 | } |
| 55 | |
| 56 | let next_line = io::stdin().lock().lines().next(); |
| 57 | match next_line { |
| 58 | Some(Ok(line)) => ReadlineResult::Line(line), |
| 59 | None => ReadlineResult::Eof, |
| 60 | Some(Err(e)) if e.kind() == io::ErrorKind::Interrupted => ReadlineResult::Interrupt, |
| 61 | Some(Err(e)) => ReadlineResult::Io(e), |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 |