/** * Implement the "vi" yank-to operation. This operation allows you * to yank the contents of the current line based upon a move operation, * for exaple "yw" yanks the current word, "3yw" yanks 3 words, etc. * * @param startPos The starting position from which to yank * @param endPos The ending position to which to yank * @return true if the yank succeeded */ private boolean viYankTo(int startPos, int endPos) throws IOException { int cursorPos = startPos; if (endPos < startPos) { int tmp = endPos; endPos = startPos; startPos = tmp; } if (startPos == endPos) { yankBuffer = ""; return true; } yankBuffer = buf.buffer.substring(startPos, endPos); /* * It was a movement command that moved the cursor to find the * end position, so put the cursor back where it started. */ setCursorPosition(cursorPos); return true; }
private void setBufferKeepPos(final String buffer) throws IOException { int pos = buf.cursor; setBuffer(buffer); setCursorPosition(pos); }
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()); }
setCursorPosition(pos); return true;
/** * This is a close facsimile of the actual vi previous word logic. In * actual vi words are determined by boundaries of identity characterse. * This logic is a bit more simple and simply looks at white space or * digits or characters. It should be revised at some point. * * @param count number of iterations * @return true if the move was successful, false otherwise */ private boolean viPreviousWord(int count) throws IOException { boolean ok = true; if (buf.cursor == 0) { return false; } int pos = buf.cursor - 1; for (int i = 0; pos > 0 && i < count; i++) { // If we are on white space, then move back. while (pos > 0 && isWhitespace(buf.buffer.charAt(pos))) { --pos; } while (pos > 0 && !isDelimiter(buf.buffer.charAt(pos-1))) { --pos; } if (pos > 0 && i < (count-1)) { --pos; } } setCursorPosition(pos); return ok; }
/** * Implements a close facsimile of the vi end-of-word movement. * If the character is on white space, it takes you to the end * of the next word. If it is on the last character of a word * it takes you to the next of the next word. Any other character * of a word, takes you to the end of the current word. * * @param count Number of times to repeat the action * @return true if it worked. */ private boolean viEndWord(int count) throws IOException { int pos = buf.cursor; int end = buf.buffer.length(); for (int i = 0; pos < end && i < count; i++) { if (pos < (end-1) && !isDelimiter(buf.buffer.charAt(pos)) && isDelimiter(buf.buffer.charAt (pos+1))) { ++pos; } // If we are on white space, then move back. while (pos < end && isDelimiter(buf.buffer.charAt(pos))) { ++pos; } while (pos < (end-1) && !isDelimiter(buf.buffer.charAt(pos+1))) { ++pos; } } setCursorPosition(pos); return true; }
setCursorPosition(startPos); buf.cursor = startPos; buf.buffer.delete(startPos, endPos);
private String insertComment(boolean isViMode) throws IOException { String comment = this.getCommentBegin(); setCursorPosition(0); putString(comment); if (isViMode) { consoleKeys.setKeyMap(KeyMap.VI_INSERT); } return accept(); }
while (pos < buf.buffer.length()) { if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break; while (pos >= 0) { if (buf.buffer.charAt(pos) == searchChar) { setCursorPosition(pos); ok = true; break;
++pos; setCursorPosition(pos); flush(); return true;
setCursorPosition(cursorDest);
private void insertClose(String s) throws IOException { putString(s); int closePosition = buf.cursor; moveCursor(-1); viMatch(); if (in.isNonBlockingEnabled()) { in.peek(parenBlinkTimeout); } setCursorPosition(closePosition); flush(); }
setCursorPosition (0); killLine(); setCursorPosition(0); killLine(); putString(origBuffer.buffer); setCursorPosition(origBuffer.cursor); return -1; setCursorPosition(0); killLine(); putString(origBuffer.buffer); setCursorPosition(0); return -1; setCursorPosition(0); killLine(); putString(history.get(idx)); setCursorPosition(0); flush(); setCursorPosition(0); killLine(); putString(history.get(idx)); setCursorPosition(0);
/** * 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 }
private void setBufferKeepPos(final String buffer) throws IOException { int pos = buf.cursor; setBuffer(buffer); setCursorPosition(pos); }
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 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()); }
private String insertComment(boolean isViMode) throws IOException { String comment = this.getCommentBegin(); setCursorPosition(0); putString(comment); if (isViMode) { consoleKeys.setKeyMap(KeyMap.VI_INSERT); } return accept(); }
public void abortCurrentRead() throws IOException { this.reader.println(); this.reader.println("Keyboard Interrupt"); this.reader.println(); this.inputSoFar.setLength(0); this.reader.setCursorPosition(0); this.reader.killLine(); this.reader.setPrompt(lastPrompt); this.reader.redrawLine(); this.reader.flush(); }
private void insertClose(String s) throws IOException { putString(s); int closePosition = buf.cursor; moveCursor(-1); viMatch(); if (in.isNonBlockingEnabled()) { in.peek(parenBlinkTimeout); } setCursorPosition(closePosition); flush(); }