Class CommandTailTipWidgets


  • public class CommandTailTipWidgets
    extends java.lang.Object
    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:
    CommandDescription, CommandLine, CommandDispatcher
    • Constructor Detail

      • CommandTailTipWidgets

        public CommandTailTipWidgets​(LineReader reader,
                                     CommandDispatcher dispatcher,
                                     int descriptionSize)
        Creates widgets using a CommandDispatcher with a status bar.
        Parameters:
        reader - the line reader
        dispatcher - the command dispatcher
        descriptionSize - 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 a CommandDispatcher with full configuration.
        Parameters:
        reader - the line reader
        dispatcher - the command dispatcher
        descriptionSize - the number of lines in the status bar (0 for none)
        tipType - the type of suggestions to display
      • CommandTailTipWidgets

        public CommandTailTipWidgets​(LineReader reader,
                                     java.util.Map<java.lang.String,​CommandDescription> tailTips)
        Creates widgets using a static map of command descriptions.

        Uses CommandTailTipWidgets.TipType.COMBINED and no status bar.

        Parameters:
        reader - the line reader
        tailTips - map of command names to descriptions
      • CommandTailTipWidgets

        public CommandTailTipWidgets​(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 reader
        tailTips - map of command names to descriptions
        tipType - the type of suggestions to display
      • CommandTailTipWidgets

        public CommandTailTipWidgets​(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 reader
        tailTips - map of command names to descriptions
        descriptionSize - the number of lines in the status bar (0 for none)
      • CommandTailTipWidgets

        public CommandTailTipWidgets​(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 reader
        tailTips - map of command names to descriptions
        descriptionSize - the number of lines in the status bar (0 for none)
        tipType - the type of suggestions to display
      • CommandTailTipWidgets

        public CommandTailTipWidgets​(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 reader
        descFun - function that returns a description for a command line
        descriptionSize - 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<AttributedString,​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
      • 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()