diff --git a/reader/src/main/java/org/jline/reader/Buffer.java b/reader/src/main/java/org/jline/reader/Buffer.java index a00f22343..408b716e4 100644 --- a/reader/src/main/java/org/jline/reader/Buffer.java +++ b/reader/src/main/java/org/jline/reader/Buffer.java @@ -83,4 +83,9 @@ public interface Buffer { Buffer copy(); void copyFrom(Buffer buffer); + + /** + * Clear any internal buffer. + */ + void zeroOut(); } diff --git a/reader/src/main/java/org/jline/reader/LineReader.java b/reader/src/main/java/org/jline/reader/LineReader.java index 8e03aaa3e..5318d8621 100644 --- a/reader/src/main/java/org/jline/reader/LineReader.java +++ b/reader/src/main/java/org/jline/reader/LineReader.java @@ -777,4 +777,9 @@ String readLine(String prompt, String rightPrompt, MaskingCallback maskingCallba void setAutosuggestion(SuggestionType type); SuggestionType getAutosuggestion(); + + /** + * Clear any internal buffers. + */ + void zeroOut(); } diff --git a/reader/src/main/java/org/jline/reader/impl/BufferImpl.java b/reader/src/main/java/org/jline/reader/impl/BufferImpl.java index 2ba10f70e..e217bfccc 100644 --- a/reader/src/main/java/org/jline/reader/impl/BufferImpl.java +++ b/reader/src/main/java/org/jline/reader/impl/BufferImpl.java @@ -8,6 +8,7 @@ */ package org.jline.reader.impl; +import java.util.Arrays; import java.util.Objects; import org.jline.reader.Buffer; @@ -367,4 +368,9 @@ private void moveGapToCursor() { g1 += l; } } + + @Override + public void zeroOut() { + Arrays.fill(buffer, 0); + } } diff --git a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java index 778c53869..f685a7dcb 100644 --- a/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java +++ b/reader/src/main/java/org/jline/reader/impl/LineReaderImpl.java @@ -6396,4 +6396,10 @@ private void rebind(KeyMap keyMap, String operation, String prevBinding keyMap.bind(ref, Character.toString(newBinding)); } } + + @Override + public void zeroOut() { + buf.zeroOut(); + parsedLine = null; + } }