Skip to content

Commit

Permalink
Widgets: added javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattirn committed Oct 14, 2019
1 parent 389ec83 commit bd23dac
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
59 changes: 59 additions & 0 deletions builtins/src/main/java/org/jline/builtins/Widgets.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import org.jline.keymap.KeyMap;
import org.jline.reader.Binding;
import org.jline.reader.Buffer;
import org.jline.reader.EndOfFileException;
import org.jline.reader.LineReader;
import org.jline.reader.UserInterruptException;
import org.jline.reader.LineReader.SuggestionType;
import org.jline.reader.Reference;
import org.jline.reader.Widget;
Expand Down Expand Up @@ -173,6 +175,9 @@ public void initDescription(int size) {
}
}

/**
* Creates and manages widgets that auto-closes, deletes and skips over matching delimiters intelligently.
*/
public static class AutopairWidgets extends Widgets {
/*
* Inspired by zsh-autopair
Expand Down Expand Up @@ -436,6 +441,10 @@ private boolean nexToBoundary(String d) {
}
}

/**
* Creates and manages widgets for as you type command line suggestions.
* Suggestions are created using a using command history.
*/
public static class AutosuggestionWidgets extends Widgets {
private boolean enabled = false;

Expand Down Expand Up @@ -531,29 +540,79 @@ private void defaultBindings() {
}
}

/**
* Creates and manages widgets for as you type command line suggestions.
* Suggestions are created using a command completer data and/or positional argument descriptions.
*/
public static class TailTipWidgets extends Widgets {
public enum TipType {
/**
* Prepare command line suggestions using a command positional argument descriptions.
*/
TAIL_TIP,
/**
* Prepare command line suggestions using a command completer data.
*/
COMPLETER,
/**
* Prepare command line suggestions using either a command positional argument descriptions if exists
* or command completers data.
*/
COMBINED
}
private boolean enabled = false;
private Map<String,List<ArgDesc>> tailTips = new HashMap<>();
private TipType tipType;
private int descriptionSize = 0;

/**
* Creates tailtip widgets used in command line suggestions. Suggestions are created using a command
* positional argument names. If argument descriptions do not exists command completer data will be used.
* Status bar for argument descriptions will not be created.
*
* @param reader LineReader.
* @param tailTips Commands positional argument descriptions.
* @throws IllegalStateException If widgets are already created.
*/
public TailTipWidgets(LineReader reader, Map<String,List<ArgDesc>> tailTips) {
this(reader, tailTips, 0, TipType.COMBINED);
}

/**
* Creates tailtip widgets used in command line suggestions.
* Status bar for argument descriptions will not be created.
*
* @param reader LineReader.
* @param tailTips Commands positional argument descriptions.
* @param tipType Defines which data will be used for suggestions.
* @throws IllegalStateException If widgets are already created.
*/
public TailTipWidgets(LineReader reader, Map<String,List<ArgDesc>> tailTips, TipType tipType) {
this(reader, tailTips, 0, tipType);
}

/**
* Creates tailtip widgets used in command line suggestions. Suggestions are created using a command
* positional argument names. If argument descriptions do not exists command completer data will be used.
*
* @param reader LineReader.
* @param tailTips Commands positional argument descriptions.
* @param descriptionSize Size of the status bar.
* @throws IllegalStateException If widgets are already created.
*/
public TailTipWidgets(LineReader reader, Map<String,List<ArgDesc>> tailTips, int descriptionSize) {
this(reader, tailTips, descriptionSize, TipType.COMBINED);
}

/**
* Creates tailtip widgets used in command line suggestions.
*
* @param reader LineReader.
* @param tailTips Commands positional argument descriptions.
* @param descriptionSize Size of the status bar.
* @param tipType Defines which data will be used for suggestions.
* @throws IllegalStateException If widgets are already created.
*/
public TailTipWidgets(LineReader reader, Map<String,List<ArgDesc>> tailTips, int descriptionSize, TipType tipType) {
super(reader);
if (existsWidget(TT_ACCEPT_LINE)) {
Expand Down
14 changes: 14 additions & 0 deletions reader/src/main/java/org/jline/reader/LineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,23 @@ enum RegionType {
}

enum SuggestionType {
/**
* As you type command line suggestions are disabled.
*/
NONE,
/**
* Prepare command line suggestions using command history.
* Requires an additional widgets implementation.
*/
HISTORY,
/**
* Prepare command line suggestions using command completer data.
*/
COMPLETER,
/**
* Prepare command line suggestions using command completer data and/or command positional argument descriptions.
* Requires an additional widgets implementation.
*/
TAIL_TIP
}

Expand Down

0 comments on commit bd23dac

Please sign in to comment.