Class Basic

  • All Implemented Interfaces:
    Console

    public class Basic
    extends Object
    implements Console
    Helper for input from stdin.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • Basic

        public Basic()
    • Method Detail

      • readLine

        protected String readLine()
        Reads a line from stdin.
        Returns:
        the line, null if failed to read
      • readAll

        protected String readAll()
        Reads all lines from stdin (till null encountered, i.e. "Ctrl+D").
        Returns:
        the line, null if failed to read
      • enterMultiLineValue

        public String enterMultiLineValue​(String msg)
        Lets the user enter a multi-line value.
        Specified by:
        enterMultiLineValue in interface Console
        Parameters:
        msg - the message to output before reading the input
        Returns:
        the entered value, null if cancelled or failed to read input
      • enterValue

        public String enterValue​(String msg)
        Lets the user enter a value.
        Specified by:
        enterValue in interface Console
        Parameters:
        msg - the message to output before reading the input
        Returns:
        the entered value, null if cancelled or failed to read input
      • enterValue

        public String enterValue​(String msg,
                                 String initial)
        Lets the user enter a value.
        Specified by:
        enterValue in interface Console
        Parameters:
        msg - the message to output before reading the input
        initial - the initial value, ignored if empty or null
        Returns:
        the entered value, null if cancelled or failed to read input (or initial value if empty string returned)
      • enterMultipleValues

        public String[] enterMultipleValues​(String msg)
        Lets the user enter multiple values. Empty string terminates the loop.
        Specified by:
        enterMultipleValues in interface Console
        Parameters:
        msg - the message to output before reading the input
        Returns:
        the entered value, null if cancelled or failed to read input
      • enterPassword

        public BasePassword enterPassword​(String msg)
        Lets the user enter a password.
        Specified by:
        enterPassword in interface Console
        Parameters:
        msg - the message to output before reading the input
        Returns:
        the entered value, null if cancelled or failed to read input
      • selectOption

        public String selectOption​(String msg,
                                   String[] options)
        Lets the user select from a number of choices.
        Specified by:
        selectOption in interface Console
        Parameters:
        msg - the message to output before reading the input
        options - the options to choose from
        Returns:
        the selected option, null if cancelled or failed to read input
      • selectOption

        public String selectOption​(String msg,
                                   String[] options,
                                   String initial)
        Lets the user select from a number of choices.
        Specified by:
        selectOption in interface Console
        Parameters:
        msg - the message to output before reading the input
        options - the options to choose from
        initial - the initial selection (selected if just hitting enter), null or empty string to ignore
        Returns:
        the selected option, null if cancelled or failed to read input
      • selectFiles

        public PlaceholderFile[] selectFiles​(String msg,
                                             PlaceholderFile... initial)
        Lets the user select files.
        Specified by:
        selectFiles in interface Console
        Parameters:
        msg - the message to output
        initial - the initial files
        Returns:
        the directory, null if cancelled
      • printlnOut

        public void printlnOut​(String msg)
        Outputs the message.
        Specified by:
        printlnOut in interface Console
        Parameters:
        msg - the message to output
      • printlnErr

        public void printlnErr​(String msg)
        Outputs the error message.
        Specified by:
        printlnErr in interface Console
        Parameters:
        msg - the error message to output