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 the ability to clear internal buffers (fixes #910) #915

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public interface Buffer {
Buffer copy();

void copyFrom(Buffer buffer);

/**
* Clear any internal buffer.
*/
void zeroOut();
}
5 changes: 5 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -777,4 +777,9 @@ String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallba
void setAutosuggestion(SuggestionType type);

SuggestionType getAutosuggestion();

/**
* Clear any internal buffers.
*/
void zeroOut();
}
6 changes: 6 additions & 0 deletions reader/src/main/java/org/jline/reader/impl/BufferImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package org.jline.reader.impl;

import java.util.Arrays;
import java.util.Objects;

import org.jline.reader.Buffer;
Expand Down Expand Up @@ -367,4 +368,9 @@ private void moveGapToCursor() {
g1 += l;
}
}

@Override
public void zeroOut() {
Arrays.fill(buffer, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6396,4 +6396,10 @@ private void rebind(KeyMap<Binding> keyMap, String operation, String prevBinding
keyMap.bind(ref, Character.toString(newBinding));
}
}

@Override
public void zeroOut() {
buf.zeroOut();
parsedLine = null;
}
}
Loading