Package org.jline.reader.impl
Class KillRing
java.lang.Object
org.jline.reader.impl.KillRing
The kill ring class keeps killed text in a fixed size ring. In this
class we also keep record of whether or not the last command was a
kill or a yank. Depending on this, the class may behave
different. For instance, two consecutive kill-word commands fill
the same slot such that the next yank will return the two
previously killed words instead that only the last one. Likewise
yank pop requires that the previous command was either a yank or a
yank-pop.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the string to the kill-ring.void
addBackwards
(String str) Adds the string to the kill-ring product of killing backwards.boolean
lastYank()
Returnstrue
if the last command was a yank.void
Resets the last-kill state.void
Resets the last-yank state.yank()
Yanks a previously killed text.yankPop()
Moves the pointer to the current slot back and returns the text in that position.
-
Constructor Details
-
KillRing
public KillRing(int size) Creates a new kill ring of the given size.- Parameters:
size
- the size of the ring
-
KillRing
public KillRing()Creates a new kill ring of the default size. SeeDEFAULT_SIZE
.
-
-
Method Details
-
resetLastYank
public void resetLastYank()Resets the last-yank state. -
resetLastKill
public void resetLastKill()Resets the last-kill state. -
lastYank
public boolean lastYank()Returnstrue
if the last command was a yank.- Returns:
true
if the last command was a yank
-
add
Adds the string to the kill-ring. Also sets lastYank to false and lastKill to true.- Parameters:
str
- the string to add
-
addBackwards
Adds the string to the kill-ring product of killing backwards. If the previous command was a kill text one then adds the text at the beginning of the previous kill to avoid that two consecutive backwards kills followed by a yank leaves things reversed.- Parameters:
str
- the string to add
-
yank
Yanks a previously killed text. Returnsnull
if the ring is empty.- Returns:
- the text in the current position
-
yankPop
Moves the pointer to the current slot back and returns the text in that position. If the previous command was not yank returns null.- Returns:
- the text in the previous position
-