Esempio n. 1
0
  @Override
  public String promptWithCompleter(String message, final Completer tempCompleter) {
    synchronized (executorLock) {
      if (!message.isEmpty() && message.matches("^.*\\S$")) {
        message = message + " ";
      }
      message = renderColor(ShellColor.CYAN, " ? ") + message;

      try {
        reader.removeCompleter(this.completer);
        if (tempCompleter != null) {
          reader.addCompleter(tempCompleter);
        }
        reader.setHistoryEnabled(false);
        reader.setPrompt(message);
        flush();

        Callable<String> call =
            new Callable<String>() {
              @Override
              public String call() throws Exception {
                return readLine();
              }
            };

        ReturnValueThread<String> thread = new ReturnValueThread<String>(call);
        executorThread = thread;
        thread.run();
        thread.join();

        if (interruptedState) {
          throw new AbortedException();
        }

        flush();
        if (thread.getException() instanceof EndOfStreamException) {
          throw (EndOfStreamException) thread.getException();
        }

        return thread.getValue();
      } catch (InterruptedException e) {
        throw new RuntimeException("[killed]");
      } finally {
        if (tempCompleter != null) {
          reader.removeCompleter(tempCompleter);
        }
        reader.addCompleter(this.completer);
        reader.setHistoryEnabled(true);
        reader.setPrompt("");
        interruptedState = false;
      }
    }
  }
Esempio n. 2
0
  @Override
  public String promptSecret(String message) {
    if (!message.isEmpty() && message.matches("^.*\\S$")) {
      message = message + " ";
    }
    message = renderColor(ShellColor.CYAN, " ? ") + message;

    try {
      reader.removeCompleter(this.completer);
      reader.setHistoryEnabled(false);
      reader.setPrompt(message);
      flush();
      String line = readLine('*');
      flush();
      return line;
    } catch (IOException e) {
      throw new IllegalStateException("Shell input stream failure", e);
    } finally {
      reader.addCompleter(this.completer);
      reader.setHistoryEnabled(true);
      reader.setPrompt("");
    }
  }