|
|||||||||
| Home >> All >> org >> gnu >> [ readline overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.gnu.readline
Interface ReadlineCompleter

- public interface ReadlineCompleter
Callback interface that implements completion. You've to implement this interface in order to provide completion in your application. The default completion mode of the Readline library would otherwise be simple filename completion.
| Method Summary | |
java.lang.String |
completer(java.lang.String text,
int state)
A generator function for filename completion in the general case. |
| Method Detail |
completer
public java.lang.String completer(java.lang.String text, int state)
- A generator function for filename completion in the general case.
Note that completion in Bash is a little different because of all
the pathnames that must be followed when looking up completions
for a command. The Bash source is a useful reference for writing
custom completion functions.
The completer method is called with the current text to be expanded (that is: the string of characters after the last word break character 55 ) 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
statevariable until it returns null.Depending on the state and the return value, the readline library reacts differently.
- if the completer returns
nullfor state=0, then the readline library will beep to indicate that there is no known completion. - if the completer returns a value for state=0 and
nullfor state=1, then there was exactly one possible completion, that is immediately expanded on the command line. - if the completer returns choices for states >= 1, then these choices are displayed to the user to choose from.
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"); ...
now, you could write a completion method that provides completion for these commands: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. }
- if the completer returns
|
|||||||||
| Home >> All >> org >> gnu >> [ readline overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC