(&mut self, prompt: Option<&str>)
| 105 | } |
| 106 | |
| 107 | pub fn read_line(&mut self, prompt: Option<&str>) -> Result<Option<String>, ReadlineError> { |
| 108 | match &mut self.inner { |
| 109 | inner::Inner::Readline(rl) => { |
| 110 | let prompt = prompt.unwrap_or_default(); |
| 111 | let curr_line = rl.readline(prompt); |
| 112 | match curr_line { |
| 113 | Ok(line) => { |
| 114 | if Self::should_append_history(&line) { |
| 115 | let _ = rl.add_history_entry(line.as_str()); |
| 116 | } |
| 117 | Ok(Some(line)) |
| 118 | }, |
| 119 | Err(ReadlineError::Interrupted | ReadlineError::Eof) => Ok(None), |
| 120 | Err(err) => Err(err), |
| 121 | } |
| 122 | }, |
| 123 | inner::Inner::Mock { index, lines } => { |
| 124 | *index += 1; |
| 125 | Ok(lines.get(*index - 1).cloned()) |
| 126 | }, |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | fn should_append_history(line: &str) -> bool { |
| 131 | let trimmed = line.trim().to_lowercase(); |
no test coverage detected