@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; }
@Override public int scan() { try { return reader.readVirtualKey(); } catch (IOException e) { return -1; } }
private void _setHistory(final List<String> lines) { MemoryHistory history = new MemoryHistory(); for (String line : lines) { history.add(line); } reader.setHistory(history); }
@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; } } }
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); } } }
@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(""); } }
private void _flushBuffer() throws IOException { if (bufferingMode == BufferingMode.Direct) { reader.flush(); } }
@Override public boolean isAnsiSupported() { return (reader != null) && reader.getTerminal().isAnsiSupported(); }
@Override public void registerKeyListener(final KeyListener keyListener) { reader.registerKeyListener(keyListener); }
@Override public int getAbsoluteHeight() { return reader.getTerminal().getHeight(); }