Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an Iterator #82

Closed
Yamakaky opened this issue Oct 2, 2016 · 6 comments
Closed

Add an Iterator #82

Yamakaky opened this issue Oct 2, 2016 · 6 comments

Comments

@Yamakaky
Copy link

Yamakaky commented Oct 2, 2016

We could do:

for cmd in editor {
    match ...
}

It would end on EOF or

@gwenn
Copy link
Collaborator

gwenn commented Oct 2, 2016

And for ?

@Yamakaky
Copy link
Author

Yamakaky commented Oct 2, 2016

In my code, I ignore it. It's handy if you want to discard the current line. python does it.

@gwenn
Copy link
Collaborator

gwenn commented Oct 2, 2016

Something like:

impl<C: Completer> Iterator for Editor<C> {
    type Item = Result<String>;

    fn next(&mut self) -> Option<Result<String>> {
        let readline = self.readline(""); // FIXME prompt
        match readline {
            l @ Ok(_) => Some(l),
            Err(error::ReadlineError::Eof) => None,
            e @ Err(_) => Some(e),
        }
    }
}

?

@Yamakaky
Copy link
Author

Yamakaky commented Oct 2, 2016

Yeah, something like that. The prompt could be configured at creation time, since it tend to stay the same for most program. You should also keep the current interface, in case someone want to do something different

gwenn added a commit to gwenn/rustyline that referenced this issue Oct 8, 2016
gwenn added a commit to gwenn/rustyline that referenced this issue Oct 8, 2016
@Yamakaky
Copy link
Author

SGTM. Just add an implementation for IntoIterator for extra convenience ^^

kkawakam added a commit that referenced this issue Oct 27, 2016
@gwenn
Copy link
Collaborator

gwenn commented Aug 26, 2018

2.0 released

@gwenn gwenn closed this as completed Aug 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants