Package org.jline.shell.widget
Class CommandTailTipWidgets
java.lang.Object
org.jline.shell.widget.CommandTailTipWidgets
Provides real-time command-line suggestions as the user types, using
CommandDescription for positional argument hints and option help.
Suggestions are displayed either as inline tail-tips after the cursor, as completer-driven suggestions, or both. A terminal status bar can optionally show detailed argument and option descriptions.
This widget works with the new shell API (CommandDescription,
CommandLine, ArgumentDescription) and can be configured
with a static map, a dynamic lookup function, or a CommandDispatcher.
Example using a CommandDispatcher:
CommandTailTipWidgets widgets = new CommandTailTipWidgets(reader, dispatcher, 5); widgets.enable();
Example using a static map:
Map<String, CommandDescription> descriptions = Map.of("ls", lsDesc, "cd", cdDesc);
CommandTailTipWidgets widgets = new CommandTailTipWidgets(reader, descriptions, 5, TipType.COMBINED);
widgets.enable();
- Since:
- 4.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe type of suggestions to display. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCommandTailTipWidgets(LineReader reader, Function<CommandLine, CommandDescription> descFun, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using a dynamic description function.CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips) Creates widgets using a static map of command descriptions.CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, int descriptionSize) Creates widgets using a static map with a status bar.CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using a static map with full configuration.CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, CommandTailTipWidgets.TipType tipType) Creates widgets using a static map with a specific tip type.CommandTailTipWidgets(LineReader reader, CommandDispatcher dispatcher) Creates widgets using aCommandDispatcherfor dynamic description lookup.CommandTailTipWidgets(LineReader reader, CommandDispatcher dispatcher, int descriptionSize) Creates widgets using aCommandDispatcherwith a status bar.CommandTailTipWidgets(LineReader reader, CommandDispatcher dispatcher, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using aCommandDispatcherwith full configuration. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the current status bar size.voiddisable()Disables the widgets, restoring default key bindings.voidenable()Enables the widgets, installing custom key bindings.voidInitializes the terminal status bar with a border.booleanReturns whether the widgets are currently enabled.voidsetDescriptionCache(boolean cache) Sets whether resolved descriptions should be cached permanently.voidsetDescriptions(Map<String, CommandDescription> tailTips) Replaces the description map with a new set of command descriptions.voidsetDescriptionSize(int descriptionSize) Sets the status bar size.voidsetSyntaxHighlighter(Function<AttributedString, AttributedString> highlighter) Sets a function to highlight syntax in description text.voidSets the tip type.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleantipType()Returns the current tip type.booleanboolean
-
Field Details
-
reader
-
-
Constructor Details
-
CommandTailTipWidgets
Creates widgets using aCommandDispatcherfor dynamic description lookup.Uses
CommandTailTipWidgets.TipType.COMBINEDand no status bar.- Parameters:
reader- the line readerdispatcher- the command dispatcher
-
CommandTailTipWidgets
Creates widgets using aCommandDispatcherwith a status bar.- Parameters:
reader- the line readerdispatcher- the command dispatcherdescriptionSize- the number of lines in the status bar (0 for none)
-
CommandTailTipWidgets
public CommandTailTipWidgets(LineReader reader, CommandDispatcher dispatcher, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using aCommandDispatcherwith full configuration.- Parameters:
reader- the line readerdispatcher- the command dispatcherdescriptionSize- the number of lines in the status bar (0 for none)tipType- the type of suggestions to display
-
CommandTailTipWidgets
Creates widgets using a static map of command descriptions.Uses
CommandTailTipWidgets.TipType.COMBINEDand no status bar.- Parameters:
reader- the line readertailTips- map of command names to descriptions
-
CommandTailTipWidgets
public CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, CommandTailTipWidgets.TipType tipType) Creates widgets using a static map with a specific tip type.- Parameters:
reader- the line readertailTips- map of command names to descriptionstipType- the type of suggestions to display
-
CommandTailTipWidgets
public CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, int descriptionSize) Creates widgets using a static map with a status bar.- Parameters:
reader- the line readertailTips- map of command names to descriptionsdescriptionSize- the number of lines in the status bar (0 for none)
-
CommandTailTipWidgets
public CommandTailTipWidgets(LineReader reader, Map<String, CommandDescription> tailTips, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using a static map with full configuration.- Parameters:
reader- the line readertailTips- map of command names to descriptionsdescriptionSize- the number of lines in the status bar (0 for none)tipType- the type of suggestions to display
-
CommandTailTipWidgets
public CommandTailTipWidgets(LineReader reader, Function<CommandLine, CommandDescription> descFun, int descriptionSize, CommandTailTipWidgets.TipType tipType) Creates widgets using a dynamic description function.- Parameters:
reader- the line readerdescFun- function that returns a description for a command linedescriptionSize- the number of lines in the status bar (0 for none)tipType- the type of suggestions to display
-
-
Method Details
-
setSyntaxHighlighter
Sets a function to highlight syntax in description text.If set, this function is applied to main description lines when the description is not already marked as highlighted.
- Parameters:
highlighter- function to highlight an attributed string
-
setDescriptions
Replaces the description map with a new set of command descriptions.- Parameters:
tailTips- the new command descriptions
-
setDescriptionSize
public void setDescriptionSize(int descriptionSize) Sets the status bar size.- Parameters:
descriptionSize- the number of lines (0 to disable)
-
descriptionSize
public int descriptionSize()Returns the current status bar size.- Returns:
- the description size
-
setTipType
Sets the tip type.- Parameters:
type- the new tip type
-
tipType
-
isEnabled
public boolean isEnabled()Returns whether the widgets are currently enabled.- Returns:
- true if enabled
-
disable
public void disable()Disables the widgets, restoring default key bindings. -
enable
public void enable()Enables the widgets, installing custom key bindings. -
setDescriptionCache
public void setDescriptionCache(boolean cache) Sets whether resolved descriptions should be cached permanently.- Parameters:
cache- true to cache descriptions
-
tailtipComplete
public boolean tailtipComplete() -
tailtipAcceptLine
public boolean tailtipAcceptLine() -
tailtipBackwardDelete
public boolean tailtipBackwardDelete() -
tailtipDelete
public boolean tailtipDelete() -
tailtipKillLine
public boolean tailtipKillLine() -
tailtipKillWholeLine
public boolean tailtipKillWholeLine() -
tailtipInsert
public boolean tailtipInsert() -
tailtipUpdateStatus
public boolean tailtipUpdateStatus() -
initDescription
public void initDescription()Initializes the terminal status bar with a border. -
toggleWindow
public boolean toggleWindow() -
toggleKeyBindings
public boolean toggleKeyBindings()
-