public static String processMessegeForExtraCharactersFromConsoleBuffer(String messege) { ConsoleReader reader = Gfsh.getConsoleReader(); if (reader != null) { int bufferLength = reader.getCursorBuffer().length(); if (bufferLength > messege.length()) { int appendSpaces = bufferLength - messege.length(); for (int i = 0; i < appendSpaces; i++) { messege = messege + " "; } } } return messege; } }
private static String readLine(ConsoleReader reader, String prompt) throws IOException { String earlierLine = reader.getCursorBuffer().toString(); String readLine; try { readLine = reader.readLine(prompt); } catch (IndexOutOfBoundsException e) { if (earlierLine.length() == 0) { reader.println(); readLine = LINE_SEPARATOR; reader.getCursorBuffer().cursor = 0; } else { readLine = readLine(reader, prompt); } } return readLine; }
CursorBuffer buf = reader.getCursorBuffer();
} else { prompt = getDefaultSecondaryPrompt(); reader.getCursorBuffer().cursor = 0; reader.getCursorBuffer().write(removeBackslash(line) + LINE_SEPARATOR);
@Override public synchronized void flush() { try { if (jline) { reader.print(ConsoleReader.RESET_LINE + ""); reader.flush(); super.flush(); try { reader.drawLine(); } catch (Throwable ex) { reader.getCursorBuffer().clear(); } reader.flush(); } else { super.flush(); } } catch (IOException ex) { logger.log(Level.SEVERE, "I/O exception flushing console output", ex); } } }
public static void setBuffer(final ConsoleReader reader, final CharSequence value, final int offset) throws IOException { while ((reader.getCursorBuffer().cursor > offset) && reader.backspace()) { // empty } reader.putString(value); reader.setCursorPosition(offset + value.length()); }
public boolean complete(final ConsoleReader reader, final List<CharSequence> candidates, final int pos) throws IOException { CursorBuffer buf = reader.getCursorBuffer(); // if there is only one completion, then fill in the buffer if (candidates.size() == 1) { String value = Ansi.stripAnsi(candidates.get(0).toString()); if (buf.cursor == buf.buffer.length() && printSpaceAfterFullCompletion && !value.endsWith(" ")) { value += " "; } // fail if the only candidate is the same as the current buffer if (value.equals(buf.toString())) { return false; } setBuffer(reader, value, pos); return true; } else if (candidates.size() > 1) { String value = getUnambiguousCompletions(candidates); setBuffer(reader, value, pos); } printCandidates(reader, candidates); // redraw the current console buffer reader.drawLine(); return true; }
/** * Possible states in which the current readline operation may be in. */ private static enum State { /** * The user is just typing away */ NORMAL, /** * In the middle of a emacs seach */ SEARCH, FORWARD_SEARCH, /** * VI "yank-to" operation ("y" during move mode) */ VI_YANK_TO, /** * VI "delete-to" operation ("d" during move mode) */ VI_DELETE_TO, /** * VI "change-to" operation ("c" during move mode) */ VI_CHANGE_TO }
public void clear() { consoleReader.getCursorBuffer().clear(); }
protected void updateBuffer(final ConsoleReader reader, final CharSequence output, final int offset) throws IOException { while ((reader.getCursorBuffer().cursor > offset) && reader.backspace()) { } if (output != null && output.length() > 0) { reader.putString(output); int newCursorPosition = offset + output.length(); if (output.charAt(output.length()-1) == ')' && output.charAt(output.length()-2) == '(' ) { //we want to put the cursor between the parentheses here newCursorPosition--; } reader.setCursorPosition(newCursorPosition); } }
public static String processMessegeForExtraCharactersFromConsoleBuffer(String messege){ ConsoleReader reader = Gfsh.getConsoleReader(); if (reader != null) { int bufferLength = reader.getCursorBuffer().length(); if(bufferLength > messege.length()){ int appendSpaces = bufferLength - messege.length(); for(int i = 0; i < appendSpaces; i++){ messege = messege + " "; } } } return messege; } }
private static String readLine(ConsoleReader reader, String prompt) throws IOException { String earlierLine = reader.getCursorBuffer().toString(); String readLine = null; try { readLine = reader.readLine(prompt); } catch (IndexOutOfBoundsException e) { if (earlierLine.length() == 0) { reader.println(); readLine = LINE_SEPARATOR; reader.getCursorBuffer().cursor = 0; } else { readLine = readLine(reader, prompt); } } return readLine; }
public static void setBuffer(final ConsoleReader reader, final CharSequence value, final int offset) throws IOException { while ((reader.getCursorBuffer().cursor > offset) && reader.backspace()) { // empty } reader.putString(value); reader.setCursorPosition(offset + value.length()); }
public synchronized void stashLine() { this.stashed = reader.getCursorBuffer().copy(); try { reader.getOutput().write("\u001b[1G\u001b[K"); reader.flush(); } catch (IOException e) { // ignore } }
reader.drawLine(); } catch (Throwable ex) { reader.getCursorBuffer().clear();
@Override public void actionPerformed(ActionEvent e) { CursorBuffer buf = textTerminal.reader.getCursorBuffer(); String partialInput = buf.buffer.toString(); buf.clear(); ReadHandlerData handlerData = handler.apply(textTerminal); ReadInterruptionStrategy.Action action = handlerData.getAction(); if(action == CONTINUE) { buf.write(partialInput); } else { if(action == RESTART) { textTerminal.initialReadBuffer = partialInput; } ReadInterruptionData interruptData = ReadInterruptionData.from(handlerData, partialInput); throw new ReadInterruptionException(interruptData, partialInput); } } }
public boolean complete(ConsoleReader reader, @SuppressWarnings("rawtypes") List<CharSequence> candidates, int pos) throws IOException { CursorBuffer buf = reader.getCursorBuffer(); // if there is only one completion, then fill in the buffer if (candidates.size() == 1) { String value = candidates.get(0).toString(); // fail if the only candidate is the same as the current buffer if (value.equals(buf.toString())) { return false; } jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos); return true; } if (candidates.size() > 1) { String value = getUnambiguousCompletions(candidates); jline.console.completer.CandidateListCompletionHandler.setBuffer(reader, value, pos); } if (eagerNewlines) { reader.println(); } jline.console.completer.CandidateListCompletionHandler.printCandidates(reader, candidates); // redraw the current console buffer reader.drawLine(); return true; }
public boolean complete(final ConsoleReader reader, final List<CharSequence> candidates, final int pos) throws IOException { CursorBuffer buffer = reader.getCursorBuffer(); // if there is only one completion, then fill in the buffer, that's all if (candidates.size() == 1) { CharSequence candidate = candidates.get(0); // fail if the only candidate is the same as the current buffer if (candidate.equals(buffer.toString())) { return false; } updateBuffer(reader, candidate, pos); return true; } //if there are more suggestions, then fill in the buffer with the longer common prefix available //and show auto-suggestions if (candidates.size() > 1) { String commonPrefix = getUnambiguousCompletions(candidates); updateBuffer(reader, commonPrefix, pos); } printCandidates(reader, candidates); //next line seems to cause small problems when cursor is not at the end of the buffer //e.g. FilterBuilders.queryFilter(QueryBuilders.) reader.drawLine(); return true; }
private boolean interruptTask() throws Exception { boolean interrupt = false; reader.getCursorBuffer().clear(); reader.redrawLine(); ConsoleTask task = getCurrentTask(); if (task != null) { synchronized (task) { log.debug("Interrupting task"); interrupt = true; if (task.isStopping()) { task.abort(); } else if (task.isRunning()) { task.stop(); } } } else { log.debug("No task running to interrupt"); } return interrupt; } }
/** * Possible states in which the current readline operation may be in. */ private static enum State { /** * The user is just typing away */ NORMAL, /** * In the middle of a emacs seach */ SEARCH, FORWARD_SEARCH, /** * VI "yank-to" operation ("y" during move mode) */ VI_YANK_TO, /** * VI "delete-to" operation ("d" during move mode) */ VI_DELETE_TO, /** * VI "change-to" operation ("c" during move mode) */ VI_CHANGE_TO }