Class Commands


  • public class Commands
    extends java.lang.Object
    Provides built-in commands for JLine applications.

    This class contains implementations of common terminal commands and utilities such as:

    • tmux - Terminal multiplexer
    • nano - Text editor
    • less - View file contents with pagination
    • history - Display and manage command history
    • complete - Edit command-specific tab completions
    • widget - Manipulate line reader widgets
    • keymap - Manipulate keymaps
    • setopt/unsetopt - Set/unset line reader options
    • setvar - Set line reader variables
    • colors - View color tables and ANSI styles
    • highlighter - Manage syntax highlighting themes

    These commands can be used to provide a familiar command-line interface in JLine-based applications.

    • Constructor Summary

      Constructors 
      Constructor Description
      Commands()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void colors​(Terminal terminal, java.io.PrintStream out, java.lang.String[] argv)
      Displays color tables and ANSI styles.
      static void complete​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.util.Map<java.lang.String,​java.util.List<Completers.CompletionData>> completions, java.lang.String[] argv)
      Edits command-specific tab completions.
      protected static java.util.List<java.nio.file.Path> findFiles​(java.nio.file.Path root, java.lang.String files)
      Finds files matching a glob pattern.
      static void highlighter​(LineReader lineReader, Terminal terminal, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] argv, ConfigurationPath configPath)
      Manages syntax highlighting themes.
      static void history​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.nio.file.Path currentDir, java.lang.String[] argv)
      Displays or manipulates the command history.
      static void keymap​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] argv)
      Manipulates line reader keymaps.
      static void less​(Terminal terminal, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err, java.nio.file.Path currentDir, java.lang.Object[] argv)
      Launches the less pager with the specified arguments.
      static void less​(Terminal terminal, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err, java.nio.file.Path currentDir, java.lang.Object[] argv, ConfigurationPath configPath)
      Launches the less pager with the specified arguments.
      static void nano​(Terminal terminal, java.io.PrintStream out, java.io.PrintStream err, java.nio.file.Path currentDir, java.lang.String[] argv)
      Launches the nano text editor with the specified arguments.
      static void nano​(Terminal terminal, java.io.PrintStream out, java.io.PrintStream err, java.nio.file.Path currentDir, java.lang.String[] argv, ConfigurationPath configPath)
      Launches the nano text editor with the specified arguments.
      static void setopt​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] argv)
      Sets line reader options.
      static void setvar​(LineReader lineReader, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] argv)
      Sets or displays line reader variables.
      static void tmux​(Terminal terminal, java.io.PrintStream out, java.io.PrintStream err, java.util.function.Supplier<java.lang.Object> getter, java.util.function.Consumer<java.lang.Object> setter, java.util.function.Consumer<Terminal> runner, java.lang.String[] argv)
      Implements a terminal multiplexer similar to tmux.
      static void unsetopt​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.lang.String[] argv)
      Unsets line reader options.
      static void widget​(LineReader reader, java.io.PrintStream out, java.io.PrintStream err, java.util.function.Function<java.lang.String,​Widget> widgetCreator, java.lang.String[] argv)
      Manipulates line reader widgets.
      • Methods inherited from class java.lang.Object

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

      • Commands

        public Commands()
    • Method Detail

      • tmux

        public static void tmux​(Terminal terminal,
                                java.io.PrintStream out,
                                java.io.PrintStream err,
                                java.util.function.Supplier<java.lang.Object> getter,
                                java.util.function.Consumer<java.lang.Object> setter,
                                java.util.function.Consumer<Terminal> runner,
                                java.lang.String[] argv)
                         throws java.lang.Exception
        Implements a terminal multiplexer similar to tmux.
        Parameters:
        terminal - the terminal to use
        out - the output stream
        err - the error stream
        getter - supplier to get the current tmux instance
        setter - consumer to set the current tmux instance
        runner - consumer to run a terminal
        argv - command arguments
        Throws:
        java.lang.Exception - if an error occurs
      • nano

        public static void nano​(Terminal terminal,
                                java.io.PrintStream out,
                                java.io.PrintStream err,
                                java.nio.file.Path currentDir,
                                java.lang.String[] argv)
                         throws java.lang.Exception
        Launches the nano text editor with the specified arguments. This is a convenience method that calls nano(Terminal, PrintStream, PrintStream, Path, String[], ConfigurationPath) with a null ConfigurationPath.
        Parameters:
        terminal - the terminal to use
        out - the output stream
        err - the error stream
        currentDir - the current directory
        argv - command arguments
        Throws:
        java.lang.Exception - if an error occurs
      • nano

        public static void nano​(Terminal terminal,
                                java.io.PrintStream out,
                                java.io.PrintStream err,
                                java.nio.file.Path currentDir,
                                java.lang.String[] argv,
                                ConfigurationPath configPath)
                         throws java.lang.Exception
        Launches the nano text editor with the specified arguments.
        Parameters:
        terminal - the terminal to use
        out - the output stream
        err - the error stream
        currentDir - the current directory
        argv - command arguments
        configPath - the configuration path or null for default
        Throws:
        java.lang.Exception - if an error occurs
      • less

        public static void less​(Terminal terminal,
                                java.io.InputStream in,
                                java.io.PrintStream out,
                                java.io.PrintStream err,
                                java.nio.file.Path currentDir,
                                java.lang.Object[] argv)
                         throws java.lang.Exception
        Launches the less pager with the specified arguments. This is a convenience method that calls less(Terminal, InputStream, PrintStream, PrintStream, Path, Object[], ConfigurationPath) with a null ConfigurationPath.
        Parameters:
        terminal - the terminal to use
        in - the input stream
        out - the output stream
        err - the error stream
        currentDir - the current directory
        argv - command arguments
        Throws:
        java.lang.Exception - if an error occurs
      • less

        public static void less​(Terminal terminal,
                                java.io.InputStream in,
                                java.io.PrintStream out,
                                java.io.PrintStream err,
                                java.nio.file.Path currentDir,
                                java.lang.Object[] argv,
                                ConfigurationPath configPath)
                         throws java.lang.Exception
        Launches the less pager with the specified arguments.
        Parameters:
        terminal - the terminal to use
        in - the input stream
        out - the output stream
        err - the error stream
        currentDir - the current directory
        argv - command arguments (can be String or Source objects)
        configPath - the configuration path or null for default
        Throws:
        java.lang.Exception - if an error occurs
      • findFiles

        protected static java.util.List<java.nio.file.Path> findFiles​(java.nio.file.Path root,
                                                                      java.lang.String files)
                                                               throws java.io.IOException
        Finds files matching a glob pattern.
        Parameters:
        root - the root directory to search from
        files - the glob pattern to match
        Returns:
        a list of matching paths
        Throws:
        java.io.IOException - if an I/O error occurs
      • history

        public static void history​(LineReader reader,
                                   java.io.PrintStream out,
                                   java.io.PrintStream err,
                                   java.nio.file.Path currentDir,
                                   java.lang.String[] argv)
                            throws java.lang.Exception
        Displays or manipulates the command history.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        currentDir - the current directory
        argv - command arguments
        Throws:
        java.lang.Exception - if an error occurs
      • complete

        public static void complete​(LineReader reader,
                                    java.io.PrintStream out,
                                    java.io.PrintStream err,
                                    java.util.Map<java.lang.String,​java.util.List<Completers.CompletionData>> completions,
                                    java.lang.String[] argv)
                             throws Options.HelpException
        Edits command-specific tab completions.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        completions - the map of command completions
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
      • widget

        public static void widget​(LineReader reader,
                                  java.io.PrintStream out,
                                  java.io.PrintStream err,
                                  java.util.function.Function<java.lang.String,​Widget> widgetCreator,
                                  java.lang.String[] argv)
                           throws java.lang.Exception
        Manipulates line reader widgets.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        widgetCreator - function to create widgets from function names
        argv - command arguments
        Throws:
        java.lang.Exception - if an error occurs
      • keymap

        public static void keymap​(LineReader reader,
                                  java.io.PrintStream out,
                                  java.io.PrintStream err,
                                  java.lang.String[] argv)
                           throws Options.HelpException
        Manipulates line reader keymaps.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
      • setopt

        public static void setopt​(LineReader reader,
                                  java.io.PrintStream out,
                                  java.io.PrintStream err,
                                  java.lang.String[] argv)
                           throws Options.HelpException
        Sets line reader options.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
      • unsetopt

        public static void unsetopt​(LineReader reader,
                                    java.io.PrintStream out,
                                    java.io.PrintStream err,
                                    java.lang.String[] argv)
                             throws Options.HelpException
        Unsets line reader options.
        Parameters:
        reader - the line reader
        out - the output stream
        err - the error stream
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
      • setvar

        public static void setvar​(LineReader lineReader,
                                  java.io.PrintStream out,
                                  java.io.PrintStream err,
                                  java.lang.String[] argv)
                           throws Options.HelpException
        Sets or displays line reader variables.
        Parameters:
        lineReader - the line reader
        out - the output stream
        err - the error stream
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
      • colors

        public static void colors​(Terminal terminal,
                                  java.io.PrintStream out,
                                  java.lang.String[] argv)
                           throws Options.HelpException,
                                  java.io.IOException
        Displays color tables and ANSI styles.
        Parameters:
        terminal - the terminal to use
        out - the output stream
        argv - command arguments
        Throws:
        Options.HelpException - if help is requested or an error occurs
        java.io.IOException - if an I/O error occurs
      • highlighter

        public static void highlighter​(LineReader lineReader,
                                       Terminal terminal,
                                       java.io.PrintStream out,
                                       java.io.PrintStream err,
                                       java.lang.String[] argv,
                                       ConfigurationPath configPath)
                                throws Options.HelpException
        Manages syntax highlighting themes.
        Parameters:
        lineReader - the line reader
        terminal - the terminal to use
        out - the output stream
        err - the error stream
        argv - command arguments
        configPath - the configuration path
        Throws:
        Options.HelpException - if help is requested or an error occurs