org.gnu.readline
public interface ReadlineCompleter
Method Summary | |
---|---|
String | completer(String text, int state)
A generator function for filename completion in the general case.
|
The completer method is called with the current text to be
expanded (that is: the string of characters after the last
{@link Readline#getWordBreakCharacters() word break character}) and
an integer. The integer is zero to indicate, that the user just requested
completion (usually by pressing the TAB-key). The completeter method now
can return one possible choice or null to indicate that there is no
choice. If the completer returned a non-null value it is called back by
the readline library with increasing state
variable until
it returns null.
Depending on the state and the return value, the readline library reacts differently.
null
for state=0, then
the readline library will beep to indicate that there is no
known completion.null
for state=1, then there was exactly one
possible completion, that is immediately expanded on the command line.Example
Consider you have a sorted set (like a TreeSet) of commands:
SortedSet commandSet; // SortedSet<String> ... commandSet = new TreeSet(); commandSet.add("copy"); commandSet.add("copyme"); commandSet.add("load"); commandSet.add("list"); ...
private Iterator possibleValues; // iterator for subsequent calls. public String completer(String text, int state) { if (state == 0) { // first call to completer(): initialize our choices-iterator possibleValues = commandSet.tailSet(text).iterator(); } if (possibleValues.hasNext()) { String nextKey = (String) possibleValues.next(); if (nextKey.startsWith(text)) return nextKey; } return null; // we reached the last choice. }
Parameters: text start of completion text. This is the text since the last word break character. state 0 or positive int. This state is zero on the first call for a completion request and increments for each subsequent call until the end of choices is reached.
Returns: String with a completion choice or null
, if there
are no more choices.
See Also: getWordBreakCharacters TestCompleter