Skip to content
Snippets Groups Projects
Commit 7369fd66 authored by gwenn's avatar gwenn
Browse files

Draft for #82

parent d8832713
No related branches found
No related tags found
No related merge requests found
......@@ -1109,6 +1109,25 @@ impl<C: Completer> Editor<C> {
pub fn set_completer(&mut self, completer: Option<C>) {
self.completer = completer;
}
/// ```
/// let config = rustyline::Config::default();
/// let mut rl = rustyline::Editor::<()>::new(config);
/// for readline in rl.iter("> ") {
/// match readline {
/// Ok(line) => {
/// println!("Line: {}", line);
/// },
/// Err(err) => {
/// println!("Error: {:?}", err);
/// break
/// }
/// }
/// }
/// ```
pub fn iter<'a>(&'a mut self, prompt: &'a str) -> Iter<C> {
Iter { editor: self, prompt: prompt }
}
}
impl<C: Completer> fmt::Debug for Editor<C> {
......@@ -1120,6 +1139,27 @@ impl<C: Completer> fmt::Debug for Editor<C> {
}
}
pub struct Iter<'a, C: Completer> where C: 'a {
editor: &'a mut Editor<C>,
prompt: &'a str,
}
impl<'a, C: Completer> Iterator for Iter<'a, C> {
type Item = Result<String>;
fn next(&mut self) -> Option<Result<String>> {
let readline = self.editor.readline(self.prompt);
match readline {
Ok(l) => {
self.editor.add_history_entry(&l); // TODO Validate
Some(Ok(l))
},
Err(error::ReadlineError::Eof) => None,
e @ Err(_) => Some(e),
}
}
}
#[cfg(all(unix,test))]
mod test {
use std::io::Write;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment