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

jline ConsoleReader discards the read line and returns null when the line reaches EOF #10

Open
chaoyu-tang opened this issue Apr 30, 2015 · 0 comments

Comments

@chaoyu-tang
Copy link

In jline2 (jline-2.1.2.jar), the ConsoleReader discards the line content which has been read and returns null when the line reaches the end of the stream. See snippet of code in
class jline.console.ConsoleReader.java method:

public String readLine(String prompt, final Character mask) throws IOException:

            int c = pushBackChar.isEmpty() ? readCharacter() : pushBackChar.pop ();
            if (c == -1) {
                return null;
            }

and readCharacter():

public final int readCharacter() throws IOException {
    int c = reader.read();
    if (c >= 0) {
        Log.trace("Keystroke: ", c);
        // clear any echo characters
        if (terminal.isSupported()) {
            clearEcho(c);
        }
    }
    return c;
}

When EOF is reached in this line, the getCharacter() returns -1 and readLine returns null.

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

1 participant