Java Code Examples for org.jline.reader.LineReader#readLine()

The following examples show how to use org.jline.reader.LineReader#readLine() . 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: SimpleTerminalConsole.java    From TerminalConsoleAppender with MIT License 6 votes vote down vote up
private void readCommands(Terminal terminal) {
    LineReader reader = buildReader(LineReaderBuilder.builder().terminal(terminal));
    TerminalConsoleAppender.setReader(reader);

    try {
        String line;
        while (isRunning()) {
            try {
                line = reader.readLine("> ");
            } catch (EndOfFileException ignored) {
                // Continue reading after EOT
                continue;
            }

            if (line == null) {
                break;
            }

            processInput(line);
        }
    } catch (UserInterruptException e) {
        shutdown();
    } finally {
        TerminalConsoleAppender.setReader(null);
    }
}
 
Example 2
Source File: LoginCommand.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
private void login(String username, String code, Settings settings) {
    printBanner();

    LineReader reader = ShellUtils.lineReader(null, Optional.empty());
    try {
        if (username == null) {
            username = reader.readLine(getPrompt("Username"));
        }
        String password = reader.readLine(getPrompt("Password"), new Character('*'));
        postForTokenAndHandleResponse(username, password, code, settings, reader);
    }
    catch (EndOfFileException | UserInterruptException e) {
        log.error("Canceled!");
    }
    finally {
        ShellUtils.shutdown(reader);
    }
}
 
Example 3
Source File: LoginCommand.java    From rug-cli with GNU General Public License v3.0 6 votes vote down vote up
private void postForTokenAndHandleResponse(String username, String password, String code,
        Settings settings, LineReader reader) {
    Status status = new LoginOperations().postForToken(username, password, code, settings);

    if (status == Status.OK) {
        log.newline();
        log.info(Style.green(
                "Successfully logged in to GitHub and stored token in ~/.atomist/cli.yml"));
    }
    else if (status == Status.BAD_CREDENTIALS) {
        throw new CommandException(
                "Provided credentials are invalid. Please try again with correct credentials.",
                "login");
    }
    else if (status == Status.MFA_REQUIRED) {
        log.newline();
        log.info("  Please provide a MFA code");
        code = reader.readLine(getPrompt("MFA code"));
        postForTokenAndHandleResponse(username, password, code, settings, reader);
    }
}
 
Example 4
Source File: SshShellHelper.java    From ssh-shell-spring-boot with Apache License 2.0 5 votes vote down vote up
/**
 * Print confirmation message and get response
 *
 * @param message message to print
 * @return response read from terminal
 */
public String read(String message) {
    LineReader lr = reader();
    if (message != null) {
        lr.getTerminal().writer().println(message);
    }
    lr.readLine();
    if (lr.getTerminal() instanceof AbstractPosixTerminal) {
        lr.getTerminal().writer().println();
    }
    return lr.getParsedLine().line();
}
 
Example 5
Source File: InteractiveMode.java    From rdflint with MIT License 4 votes vote down vote up
/**
 * execute interacitve mode.
 */
void execute(Map<String, String> cmdOptions) throws IOException {
  // initialize graph model
  Model m = ModelFactory.createDefaultModel();

  // initialize jline
  Terminal terminal = TerminalBuilder.builder()
      .system(true)
      .build();
  LineReader lineReader = LineReaderBuilder.builder()
      .terminal(terminal)
      .completer(new InteractiveCompleter(m))
      .parser(new InteractiveParser())
      .build();

  String welcome = MessageFormat
      .format(messages.getString("interactivemode.welcome"), RdfLint.VERSION);
  System.out.println(welcome);// NOPMD

  RdfLintParameters params = new RdfLintParameters();
  try {
    // load configurations
    params = ConfigurationLoader.loadParameters(cmdOptions);
    // load rdf
    m.removeAll();
    m.add(DatasetLoader.loadRdfSet(params, params.getTargetDir()));
  } catch (Exception ex) {
    System.out.println(ex.getLocalizedMessage()); // NOPMD
  }

  while (true) {
    String line;

    try {
      line = lineReader.readLine("SPARQL> ");
    } catch (UserInterruptException | EndOfFileException e) {
      return;
    }

    if (!interactiveCommand(System.out, line, params, cmdOptions, m)) {
      return;
    }
  }
}
 
Example 6
Source File: Setup.java    From jsqsh with Apache License 2.0 2 votes vote down vote up
private static String readline(LineReader in, String prompt) {

        return in.readLine(prompt);
    }