Skip to content

Commit

Permalink
Ability to erase the line at the end of a readLine call, fixes #181
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Oct 10, 2017
1 parent 7b3acf1 commit 3fa869c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,13 @@ enum Option {
INSERT_TAB(true),
MOUSE,
DISABLE_HIGHLIGHTER,
BRACKETED_PASTE(true);
BRACKETED_PASTE(true),
/**
* Instead of printing a new line when the line is read, the entire line
* (including the prompt) will be erased, thereby leaving the screen as it
* was before the readLine call.
*/
ERASE_LINE_ON_FINISH;

private final boolean def;

Expand Down
14 changes: 14 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,20 @@ protected int getViRange(Reference cmd, ViMoveMode mode) {
*/

protected void cleanup() {
if (isSet(Option.ERASE_LINE_ON_FINISH)) {
Buffer oldBuffer = buf.copy();
AttributedString oldPrompt = prompt;
buf.clear();
prompt = new AttributedString("");
doCleanup();
prompt = oldPrompt;
buf.copyFrom(oldBuffer);
} else {
doCleanup();
}
}

protected void doCleanup() {
buf.cursor(buf.length());
post = null;
if (size.getColumns() > 0 || size.getRows() > 0) {
Expand Down

0 comments on commit 3fa869c

Please sign in to comment.