Package jline.console
Class KillRing
- java.lang.Object
-
- jline.console.KillRing
-
public final class KillRing extends java.lang.ObjectThe 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.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_SIZEDefault size is 60, like in emacs.private intheadprivate booleanlastKillprivate booleanlastYankprivate java.lang.String[]slots
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String str)Adds the string to the kill-ring.voidaddBackwards(java.lang.String str)Adds the string to the kill-ring product of killing backwards.booleanlastYank()Returnstrueif the last command was a yank.private voidnext()Moves the pointer to the current slot forward.private voidprev()Moves the pointer to the current slot backwards.voidresetLastKill()Resets the last-kill state.voidresetLastYank()Resets the last-yank state.java.lang.Stringyank()Yanks a previously killed text.java.lang.StringyankPop()Moves the pointer to the current slot back and returns the text in that position.
-
-
-
Field Detail
-
DEFAULT_SIZE
private static final int DEFAULT_SIZE
Default size is 60, like in emacs.- See Also:
- Constant Field Values
-
slots
private final java.lang.String[] slots
-
head
private int head
-
lastKill
private boolean lastKill
-
lastYank
private boolean lastYank
-
-
Constructor Detail
-
KillRing
public KillRing(int size)
Creates a new kill ring of the given size.
-
KillRing
public KillRing()
Creates a new kill ring of the default size. SeeDEFAULT_SIZE.
-
-
Method Detail
-
resetLastYank
public void resetLastYank()
Resets the last-yank state.
-
resetLastKill
public void resetLastKill()
Resets the last-kill state.
-
lastYank
public boolean lastYank()
Returnstrueif the last command was a yank.
-
add
public void add(java.lang.String str)
Adds the string to the kill-ring. Also sets lastYank to false and lastKill to true.
-
addBackwards
public void addBackwards(java.lang.String str)
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.
-
yank
public java.lang.String yank()
Yanks a previously killed text. Returnsnullif the ring is empty.
-
yankPop
public java.lang.String 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.
-
next
private void next()
Moves the pointer to the current slot forward. If the end of the slots is reached then points back to the beginning.
-
prev
private void prev()
Moves the pointer to the current slot backwards. If the beginning of the slots is reached then traverses the slot backwards until one with not null content is found.
-
-