Class Completers.FileNameCompleter

  • All Implemented Interfaces:
    Completer
    Direct Known Subclasses:
    Completers.DirectoriesCompleter, Completers.FilesCompleter
    Enclosing class:
    Completers

    public static class Completers.FileNameCompleter
    extends java.lang.Object
    implements Completer
    A file name completer takes the buffer and issues a list of potential completions.

    This completer tries to behave as similar as possible to bash's file name completion (using GNU readline) with the following exceptions:

    • Candidates that are directories will end with "/"
    • Wildcard regular expressions are not evaluated or replaced
    • The "~" character can be used to represent the user's home, but it cannot complete to other users' homes, since java does not provide any way of determining that easily
    Since:
    2.3
    Author:
    Marc Prud'hommeaux, Jason Dillon
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected boolean accept​(java.nio.file.Path path)  
      void complete​(LineReader reader, ParsedLine commandLine, java.util.List<Candidate> candidates)
      Populates candidates with a list of possible completions for the command line.
      protected java.lang.String getDisplay​(Terminal terminal, java.nio.file.Path p, StyleResolver resolver, java.lang.String separator)  
      protected java.lang.String getSeparator​(boolean useForwardSlash)  
      protected java.nio.file.Path getUserDir()  
      protected java.nio.file.Path getUserHome()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FileNameCompleter

        public FileNameCompleter()
    • Method Detail

      • complete

        public void complete​(LineReader reader,
                             ParsedLine commandLine,
                             java.util.List<Candidate> candidates)
        Description copied from interface: Completer
        Populates candidates with a list of possible completions for the command line.

        The list of candidates will be sorted and filtered by the LineReader, so that the list of candidates displayed to the user will usually be smaller than the list given by the completer. Thus it is not necessary for the completer to do any matching based on the current buffer. On the contrary, in order for the typo matcher to work, all possible candidates for the word being completed should be returned.

        Implementations should add Candidate objects to the candidates list. Each candidate can include additional information such as descriptions, groups, and display attributes that will be used when presenting completion options to the user.

        This method is called by the LineReader when the user requests completion, typically by pressing the Tab key.

        Specified by:
        complete in interface Completer
        Parameters:
        reader - The line reader instance that is requesting completion
        commandLine - The parsed command line containing the current input state
        candidates - The List of candidates to populate with completion options
        See Also:
        Candidate
      • accept

        protected boolean accept​(java.nio.file.Path path)
      • getUserDir

        protected java.nio.file.Path getUserDir()
      • getUserHome

        protected java.nio.file.Path getUserHome()
      • getSeparator

        protected java.lang.String getSeparator​(boolean useForwardSlash)
      • getDisplay

        protected java.lang.String getDisplay​(Terminal terminal,
                                              java.nio.file.Path p,
                                              StyleResolver resolver,
                                              java.lang.String separator)