示例#1
0
  @Override
  public String readLine(final Character mask) throws IOException {
    String line;
    if (mask != null) {
      line = reader.readLine(mask);
    } else {
      line = reader.readLine();
    }

    if ((line != null) && !"\n".equals(line)) {
      write((byte) '\n');
    }
    flush();

    return line;
  }
示例#2
0
 @Override
 public int scan() {
   try {
     return reader.readVirtualKey();
   } catch (IOException e) {
     return -1;
   }
 }
示例#3
0
  private void _setHistory(final List<String> lines) {
    MemoryHistory history = new MemoryHistory();

    for (String line : lines) {
      history.add(line);
    }

    reader.setHistory(history);
  }
示例#4
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;
      }
    }
  }
示例#5
0
  void doShell(@Observes final AcceptUserInput event) throws Exception {
    String line;
    reader.setPrompt(getPrompt());
    while (!exitRequested) {
      try {
        line = readLine();

        if (line != null) {
          if (!"".equals(line.trim())) {
            writeToHistory(line);
            execute(line);
            flush();
          }
          reader.setPrompt(getPrompt());
        }

      } catch (Exception e) {
        handleException(e);
      }
    }
  }
示例#6
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("");
    }
  }
示例#7
0
 private void _flushBuffer() throws IOException {
   if (bufferingMode == BufferingMode.Direct) {
     reader.flush();
   }
 }
示例#8
0
 @Override
 public boolean isAnsiSupported() {
   return (reader != null) && reader.getTerminal().isAnsiSupported();
 }
示例#9
0
 @Override
 public void registerKeyListener(final KeyListener keyListener) {
   reader.registerKeyListener(keyListener);
 }
示例#10
0
 @Override
 public int getAbsoluteHeight() {
   return reader.getTerminal().getHeight();
 }