Class Candidate

  • All Implemented Interfaces:
    java.lang.Comparable<Candidate>

    public class Candidate
    extends java.lang.Object
    implements java.lang.Comparable<Candidate>
    Represents a completion candidate for tab completion.

    A Candidate encapsulates all the information needed to display and apply a completion suggestion. This includes the actual text to be inserted, how it should be displayed to the user, grouping information, descriptions, and other metadata that controls how the candidate behaves when selected.

    Candidates are created by Completer implementations and passed to the LineReader, which then filters, sorts, and displays them to the user when tab completion is requested.

    Each candidate has several properties:

    • value - The actual text to be inserted when the candidate is selected
    • display - How the candidate should be displayed to the user (may include ANSI styling)
    • group - Optional grouping category for organizing related candidates
    • description - Optional help text explaining the candidate
    • suffix - Optional text to append when the candidate is selected
    • complete - Whether the candidate is a complete word or may be further expanded
    See Also:
    Completer, LineReader.Option.AUTO_GROUP, LineReader.Option.GROUP
    • Constructor Summary

      Constructors 
      Constructor Description
      Candidate​(java.lang.String value)
      Simple constructor with only a single String as an argument.
      Candidate​(java.lang.String value, java.lang.String displ, java.lang.String group, java.lang.String descr, java.lang.String suffix, java.lang.String key, boolean complete)
      Constructs a new Candidate.
      Candidate​(java.lang.String value, java.lang.String displ, java.lang.String group, java.lang.String descr, java.lang.String suffix, java.lang.String key, boolean complete, int sort)
      Constructs a new Candidate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Candidate o)  
      boolean complete()
      Boolean indicating whether this candidate is complete or if the completer may further expand the candidate value after this candidate has been selected.
      java.lang.String descr()
      Description of this candidate, usually a small help message to understand the meaning of this candidate.
      java.lang.String displ()
      The string that will be displayed to the user.
      boolean equals​(java.lang.Object o)  
      java.lang.String group()
      The group name for this candidate.
      int hashCode()  
      java.lang.String key()
      Candidates which have the same key will be merged together.
      int sort()
      Integer used to override default sort logic.
      java.lang.String suffix()
      The suffix is added when this candidate is displayed.
      java.lang.String toString()  
      java.lang.String value()
      The value that will be used for the actual completion.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Candidate

        public Candidate​(java.lang.String value)
        Simple constructor with only a single String as an argument.
        Parameters:
        value - the candidate
      • Candidate

        public Candidate​(java.lang.String value,
                         java.lang.String displ,
                         java.lang.String group,
                         java.lang.String descr,
                         java.lang.String suffix,
                         java.lang.String key,
                         boolean complete,
                         int sort)
        Constructs a new Candidate.
        Parameters:
        value - the value
        displ - the display string
        group - the group
        descr - the description
        suffix - the suffix
        key - the key
        complete - the complete flag
        sort - the sort flag
      • Candidate

        public Candidate​(java.lang.String value,
                         java.lang.String displ,
                         java.lang.String group,
                         java.lang.String descr,
                         java.lang.String suffix,
                         java.lang.String key,
                         boolean complete)
        Constructs a new Candidate.
        Parameters:
        value - the value
        displ - the display string
        group - the group
        descr - the description
        suffix - the suffix
        key - the key
        complete - the complete flag
    • Method Detail

      • value

        public java.lang.String value()
        The value that will be used for the actual completion. This string should not contain ANSI sequences.
        Returns:
        the value
      • displ

        public java.lang.String displ()
        The string that will be displayed to the user. This string may contain ANSI sequences.
        Returns:
        the display string
      • group

        public java.lang.String group()
        The group name for this candidate. Candidates can be grouped together and this string is used as a key for the group and displayed to the user.
        Returns:
        the group
        See Also:
        LineReader.Option.GROUP, LineReader.Option.AUTO_GROUP
      • descr

        public java.lang.String descr()
        Description of this candidate, usually a small help message to understand the meaning of this candidate. This string may contain ANSI sequences.
        Returns:
        the description
      • suffix

        public java.lang.String suffix()
        The suffix is added when this candidate is displayed. However, if the next character entered does not match, the suffix will be automatically removed. This string should not contain ANSI sequences.
        Returns:
        the suffix
        See Also:
        LineReader.Option.AUTO_REMOVE_SLASH, LineReader.REMOVE_SUFFIX_CHARS
      • key

        public java.lang.String key()
        Candidates which have the same key will be merged together. For example, if a command has multiple aliases, they can be merged if they are using the same key.
        Returns:
        the key
      • complete

        public boolean complete()
        Boolean indicating whether this candidate is complete or if the completer may further expand the candidate value after this candidate has been selected. This can be the case when completing folders for example. If the candidate is complete and is selected, a space separator will be added.
        Returns:
        the completion flag
      • sort

        public int sort()
        Integer used to override default sort logic.
        Returns:
        the sort int
      • compareTo

        public int compareTo​(Candidate o)
        Specified by:
        compareTo in interface java.lang.Comparable<Candidate>
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object