-
Notifications
You must be signed in to change notification settings - Fork 238
Autosuggestions
ℹ️ Info: The JLine wiki content has been integrated into the new web site. The wiki won't be updated anymore.
Fish-like autosuggestions for JLine.
AutosuggestionWidgets suggests commands as you type based on command history.
Note: Because 'a muted gray color' was not rendered correctly by asciinema the suggestions on above recording are colored in 'magenta'.
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.completer(completer)
.parser(parser)
.build();
// Create autosuggestion widgets
AutosuggestionWidgets autosuggestionWidgets = new AutosuggestionWidgets(reader);
// Enable autosuggestions
autosuggestionWidgets.enable();As you type commands, you will see a completion offered after the cursor in a muted gray color.
If you press the → key (forward-char widget) or End (end-of-line widget) with the cursor at the end of the buffer, it will accept the suggestion, replacing the contents of the command line buffer with the suggestion.
If you invoke the forward-word widget, it will partially accept the suggestion up to the point that the cursor moves to.
This plugin provides autosuggest-toggle widget that toggles between enabled/disabled suggestions.
TailTipWidgets suggests commands as you type based on command completer data and/or command arguments and options descriptions.
Note: Because 'a muted gray color' was not rendered correctly by asciinema the suggestions on above recording are colored in 'magenta'.
LineReader reader = LineReaderBuilder.builder()
.terminal(terminal)
.completer(completer)
.parser(parser)
.build();
Map<String, CmdDesc> tailTips = new HashMap<>();
Map<String, List<AttributedString>> widgetOpts = new HashMap<>();
List<AttributedString> mainDesc = Arrays.asList(new AttributedString("widget -N new-widget [function-name]")
, new AttributedString("widget -D widget ...")
, new AttributedString("widget -A old-widget new-widget")
, new AttributedString("widget -U string ...")
, new AttributedString("widget -l [options]")
);
widgetOpts.put("-N", Arrays.asList(new AttributedString("Create new widget")));
widgetOpts.put("-D", Arrays.asList(new AttributedString("Delete widgets")));
widgetOpts.put("-A", Arrays.asList(new AttributedString("Create alias to widget")));
widgetOpts.put("-U", Arrays.asList(new AttributedString("Push characters to the stack")));
widgetOpts.put("-l", Arrays.asList(new AttributedString("List user-defined widgets")));
tailTips.put("widget", new CmdDesc(mainDesc, ArgDesc.doArgNames(Arrays.asList("[pN...]")), widgetOpts));
....
....
....
// Create tailtip widgets that uses description window size 5 and
// does not display suggestions after the cursor
TailTipWidgets tailtipWidgets = new TailTipWidgets(reader, tailTips, 5, TipType.COMPLETER);
// Enable autosuggestions
tailtipWidgets.enable();As you type commands, you will see a completion offered after the cursor in a muted gray color and argument/option description on status pane.
Command line tab completion works as normal.
Description pane can be disabled by setting descriptionSize = 0.
Suggestions type can be configured using constructor parameter tipType:
-
COMPLETERTab completions are displayed below command line. No suggestions are displayed after cursor. -
TAIL_TIPArgument suggestions are displayed after cursor. No tab completions are displayed. -
COMBINEDArgument suggestions are shown if available otherwise tab completions are displayed.
The maximum number of completer suggestions displayed can be controlled by JLine variable list-max.
For example creating TailTipWidgets as
TailTipWidgets tailtipWidgets = new TailTipWidgets(reader, tailTips, 0, TipType.TAIL_TIP);you will obtain Redis like suggestions.
This plugin provides two widgets:
-
tailtip-toggleToggles between enabled/disabled suggestions. -
tailtip-windowToggles tailtip description pane.
For example, this would bind alt + w to toggle tailtip description pane.
keymap ^[w tailtip-window