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

Ability to overwrite the input line. #181

Closed
RobertZenz opened this issue Oct 6, 2017 · 4 comments
Closed

Ability to overwrite the input line. #181

RobertZenz opened this issue Oct 6, 2017 · 4 comments

Comments

@RobertZenz
Copy link

It would be nice if there would be the ability to overwrite the input line.

Like this:

You are seeing here the prompt the user will see.
-------------------------------------------------
Prompt: This is user input.

Now, when the user presses enter/return, the terminal should not advance to the next line, but instead the whole line should be removed and the cursor should return to the beginning of the line:

You are seeing here the prompt the user will see.
-------------------------------------------------
That was odd input.
Prompt: More user input goes here.

I'm not sure if that is easily possible, though.

@gnodet
Copy link
Member

gnodet commented Oct 9, 2017

You need to create a class derived from LineReaderImpl and do the following

            LineReaderImpl readerimpl = new LineReaderImpl(terminal) {
                @Override
                protected void cleanup() {
                    buf.clear();
                    post = null;
                    prompt = new AttributedString("");
                    redisplay(false);
                    terminal.puts(Capability.keypad_local);
                    terminal.trackMouse(Terminal.MouseTracking.Off);
                    if (isSet(Option.BRACKETED_PASTE))
                        terminal.writer().write(BRACKETED_PASTE_OFF);
                    flush();
                    history.moveToEnd();
                }
            };

This will leave the line completely cleaned when exiting the readLine call.

@RobertZenz
Copy link
Author

Works very well, thank you very much.

@RobertZenz
Copy link
Author

I've just managed to upgrade my application to the latest version and tested the new ERASE_LINE_ON_FINISH option. It is clearing the line fine, but it also forwards to the next line.

As far as I can see, that is because LineReaderImpl.cleanup() is calling doCleanup() which always outputs a new line character. So the current line cannot be reused.

@gnodet gnodet reopened this May 4, 2018
@gnodet gnodet closed this as completed in 557500c May 17, 2018
@RobertZenz
Copy link
Author

Sorry for the long response times. I've just tested 3.8.0 and it works as advertised.

Thank you very much.

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