- java.lang.Object
-
- org.jline.shell.widget.CommandTailTipWidgets
-
public class CommandTailTipWidgets extends java.lang.ObjectProvides real-time command-line suggestions as the user types, usingCommandDescriptionfor 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 aCommandDispatcher.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:
CommandDescription,CommandLine,CommandDispatcher
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCommandTailTipWidgets.TipTypeThe type of suggestions to display.
-
Field Summary
Fields Modifier and Type Field Description protected org.jline.reader.LineReaderreader
-
Constructor Summary
Constructors Constructor Description CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.function.Function<CommandLine,CommandDescription> descFun, int descriptionSize, CommandTailTipWidgets.TipType tipType)Creates widgets using a dynamic description function.CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.Map<java.lang.String,CommandDescription> tailTips)Creates widgets using a static map of command descriptions.CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.Map<java.lang.String,CommandDescription> tailTips, int descriptionSize)Creates widgets using a static map with a status bar.CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.Map<java.lang.String,CommandDescription> tailTips, int descriptionSize, CommandTailTipWidgets.TipType tipType)Creates widgets using a static map with full configuration.CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.Map<java.lang.String,CommandDescription> tailTips, CommandTailTipWidgets.TipType tipType)Creates widgets using a static map with a specific tip type.CommandTailTipWidgets(org.jline.reader.LineReader reader, CommandDispatcher dispatcher)Creates widgets using aCommandDispatcherfor dynamic description lookup.CommandTailTipWidgets(org.jline.reader.LineReader reader, CommandDispatcher dispatcher, int descriptionSize)Creates widgets using aCommandDispatcherwith a status bar.CommandTailTipWidgets(org.jline.reader.LineReader reader, CommandDispatcher dispatcher, int descriptionSize, CommandTailTipWidgets.TipType tipType)Creates widgets using aCommandDispatcherwith full configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdescriptionSize()Returns the current status bar size.voiddisable()Disables the widgets, restoring default key bindings.voidenable()Enables the widgets, installing custom key bindings.voidinitDescription()Initializes the terminal status bar with a border.booleanisEnabled()Returns whether the widgets are currently enabled.voidsetDescriptionCache(boolean cache)Sets whether resolved descriptions should be cached permanently.voidsetDescriptions(java.util.Map<java.lang.String,CommandDescription> tailTips)Replaces the description map with a new set of command descriptions.voidsetDescriptionSize(int descriptionSize)Sets the status bar size.voidsetSyntaxHighlighter(java.util.function.Function<org.jline.utils.AttributedString,org.jline.utils.AttributedString> highlighter)Sets a function to highlight syntax in description text.voidsetTipType(CommandTailTipWidgets.TipType type)Sets the tip type.booleantailtipAcceptLine()booleantailtipBackwardDelete()booleantailtipComplete()booleantailtipDelete()booleantailtipInsert()booleantailtipKillLine()booleantailtipKillWholeLine()booleantailtipUpdateStatus()CommandTailTipWidgets.TipTypetipType()Returns the current tip type.booleantoggleKeyBindings()booleantoggleWindow()
-
-
-
Constructor Detail
-
CommandTailTipWidgets
public CommandTailTipWidgets(org.jline.reader.LineReader reader, CommandDispatcher dispatcher)Creates widgets using aCommandDispatcherfor dynamic description lookup.Uses
CommandTailTipWidgets.TipType.COMBINEDand no status bar.- Parameters:
reader- the line readerdispatcher- the command dispatcher
-
CommandTailTipWidgets
public CommandTailTipWidgets(org.jline.reader.LineReader reader, CommandDispatcher dispatcher, int descriptionSize)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(org.jline.reader.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
public CommandTailTipWidgets(org.jline.reader.LineReader reader, java.util.Map<java.lang.String,CommandDescription> tailTips)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(org.jline.reader.LineReader reader, java.util.Map<java.lang.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(org.jline.reader.LineReader reader, java.util.Map<java.lang.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(org.jline.reader.LineReader reader, java.util.Map<java.lang.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(org.jline.reader.LineReader reader, java.util.function.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 Detail
-
setSyntaxHighlighter
public void setSyntaxHighlighter(java.util.function.Function<org.jline.utils.AttributedString,org.jline.utils.AttributedString> highlighter)
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
public void setDescriptions(java.util.Map<java.lang.String,CommandDescription> tailTips)
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
public void setTipType(CommandTailTipWidgets.TipType type)
Sets the tip type.- Parameters:
type- the new tip type
-
tipType
public CommandTailTipWidgets.TipType tipType()
Returns the current tip type.- Returns:
- the tip type
-
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()
-
-