Java Code Examples for jline.console.ConsoleReader#setExpandEvents()

The following examples show how to use jline.console.ConsoleReader#setExpandEvents() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleShellFactory.java    From Bukkit-SSHD with Apache License 2.0 6 votes vote down vote up
public void start(Environment env) throws IOException {
    try {
        consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
        consoleReader.setExpandEvents(true);
        consoleReader.addCompleter(new ConsoleCommandCompleter());

        StreamHandler streamHandler = new FlushyStreamHandler(out, new ConsoleLogFormatter(), consoleReader);
        streamHandlerAppender = new StreamHandlerAppender(streamHandler);

        ((Logger) LogManager.getRootLogger()).addAppender(streamHandlerAppender);

        environment = env;
        thread = new Thread(this, "SSHD ConsoleShell " + env.getEnv().get(Environment.ENV_USER));
        thread.start();
    } catch (Exception e) {
        throw new IOException("Error starting shell", e);
    }
}
 
Example 2
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    LogExceptions(e);
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 3
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    LogExceptions(e);
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 4
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    LogExceptions(e);
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 5
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    LogExceptions(e);
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 6
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 7
Source File: Util.java    From ecosys with Apache License 2.0 5 votes vote down vote up
/**
 * function to generate a prompt for user to input username
 * @param doubleCheck, notes whether the password should be confirmed one more time.
 * @param isNew, indicates whether it is inputting a new password
 * @return SHA-1 hashed password on success, null on error
 */
public static String Prompt4Password(boolean doubleCheck, boolean isNew, String username) {
  String ANSI_BLUE = "\u001B[1;34m";
  String ANSI_RESET = "\u001B[0m";
  String pass = null;
  try {
    ConsoleReader tempConsole = new ConsoleReader();
    String prompttext = isNew ? "New Password : " : "Password for " + username + " : ";
    String prompt = ANSI_BLUE + prompttext + ANSI_RESET;
    tempConsole.setPrompt(prompt);
    tempConsole.setExpandEvents(false);
    String pass1 = tempConsole.readLine(new Character('*'));
    if (doubleCheck) {
      String pass2 = pass1;
      prompt = ANSI_BLUE + "Re-enter Password : " + ANSI_RESET;
      tempConsole.setPrompt(prompt);
      pass2 = tempConsole.readLine(new Character('*'));
      if (!pass1.equals(pass2)) {
        System.out.println("The two passwords do not match.");
        return null;
      }
    }
    // need to hash the password so that we do not store it as plain text
    pass = pass1;
  } catch (Exception e) {
    LogExceptions(e);
    System.out.println("Error while inputting password.");
  }
  return pass;
}
 
Example 8
Source File: JLineConsole.java    From es6draft with MIT License 5 votes vote down vote up
private static ConsoleReader newConsoleReader(String programName) throws IOException {
    final boolean isWindows = isWindows();
    final String type = System.getProperty(TerminalFactory.JLINE_TERMINAL);
    if (isWindows && type == null) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.WINDOWS, UnsupportedTerminal.class);
    } else if (isWindows && type.equalsIgnoreCase(TerminalFactory.UNIX)) {
        TerminalFactory.registerFlavor(TerminalFactory.Flavor.UNIX, CygwinTerminal.class);
    }
    FileInputStream in = new FileInputStream(FileDescriptor.in);
    Terminal terminal = TerminalFactory.get();
    ConsoleReader consoleReader = new ConsoleReader(programName, in, System.out, terminal, getDefaultEncoding());
    consoleReader.setExpandEvents(false);
    return consoleReader;
}
 
Example 9
Source File: CQLClient.java    From PoseidonX with Apache License 2.0 4 votes vote down vote up
private int readConconsole()
    throws IOException
{
    ConsoleReader reader = new ConsoleReader();
    reader.setBellEnabled(false);
    //这样就可以支持'!='这样的输入了。
    reader.setExpandEvents(false);
    reader.setCopyPasteDetection(true);
    
    String line;
    int ret = 0;
    StringBuilder prefix = new StringBuilder();
    printHelp();
    
    String tip = DEFAULT_CLI_TIP;
    
    while ((line = reader.readLine(tip)) != null)
    {
        tip = WAITING_INPUT_TIP;
        if (!prefix.toString().equals(""))
        {
            prefix.append("\n");
        }
        
        if (line.trim().startsWith("--"))
        {
            continue;
        }
        
        if (line.trim().endsWith(";") && !line.trim().endsWith("\\;"))
        {
            line = prefix.toString() + line;
            ret = processLine(line);
            prefix.delete(0, prefix.length());
            tip = DEFAULT_CLI_TIP;
        }
        else
        {
            prefix.append(line);
            continue;
        }
    }
    return ret;
}