/** * Move the cursor position to the specified absolute index. */ public boolean setCursorPosition(final int position) throws IOException { if (position == buf.cursor) { return true; } return moveCursor(position - buf.cursor) != 0; }
/** * Pasts the yank buffer to the right of the current cursor position * and moves the cursor to the end of the pasted region. * * @param count Number of times to perform the operation. * @return true if it worked, false otherwise */ private boolean viPut(int count) throws IOException { if (yankBuffer.length () == 0) { return true; } if (buf.cursor < buf.buffer.length ()) { moveCursor(1); } for (int i = 0; i < count; i++) { putString(yankBuffer); } moveCursor(-1); return true; }
/** * Implements the vi change character command (in move-mode "r" * followed by the character to change to). * @param count Number of times to perform the action * @param c The character to change to * @return Whether or not there were problems encountered */ private boolean viChangeChar(int count, int c) throws IOException { // EOF, ESC, or CTRL-C aborts. if (c < 0 || c == '\033' || c == '\003') { return true; } boolean ok = true; for (int i = 0; ok && i < count; i++) { ok = buf.cursor < buf.buffer.length (); if (ok) { buf.buffer.setCharAt(buf.cursor, (char) c); drawBuffer(1); if (i < (count-1)) { moveCursor(1); } } } return ok; }
private boolean capitalizeWord() throws IOException { boolean first = true; int i = 1; char c; while (buf.cursor + i - 1< buf.length() && !isDelimiter((c = buf.buffer.charAt(buf.cursor + i - 1)))) { buf.buffer.setCharAt(buf.cursor + i - 1, first ? Character.toUpperCase(c) : Character.toLowerCase(c)); first = false; i++; } drawBuffer(); moveCursor(i - 1); return true; }
private boolean upCaseWord() throws IOException { int i = 1; char c; while (buf.cursor + i - 1 < buf.length() && !isDelimiter((c = buf.buffer.charAt(buf.cursor + i - 1)))) { buf.buffer.setCharAt(buf.cursor + i - 1, Character.toUpperCase(c)); i++; } drawBuffer(); moveCursor(i - 1); return true; }
private boolean downCaseWord() throws IOException { int i = 1; char c; while (buf.cursor + i - 1 < buf.length() && !isDelimiter((c = buf.buffer.charAt(buf.cursor + i - 1)))) { buf.buffer.setCharAt(buf.cursor + i - 1, Character.toLowerCase(c)); i++; } drawBuffer(); moveCursor(i - 1); return true; }
/** * Switches the case of the current character from upper to lower * or lower to upper as necessary and advances the cursor one * position to the right. * @param count The number of times to repeat * @return true if it completed successfully, false if not all * case changes could be completed. */ private boolean viChangeCase(int count) throws IOException { boolean ok = true; for (int i = 0; ok && i < count; i++) { ok = buf.cursor < buf.buffer.length (); if (ok) { char ch = buf.buffer.charAt(buf.cursor); if (Character.isUpperCase(ch)) { ch = Character.toLowerCase(ch); } else if (Character.isLowerCase(ch)) { ch = Character.toUpperCase(ch); } buf.buffer.setCharAt(buf.cursor, ch); drawBuffer(1); moveCursor(1); } } return ok; }
protected boolean moveToEnd() throws IOException { if (buf.cursor == buf.length()) { return true; } return moveCursor(buf.length() - buf.cursor) > 0; }
private boolean nextWord() throws IOException { while (isDelimiter(buf.nextChar()) && (moveCursor(1) != 0)) { // nothing } while (!isDelimiter(buf.nextChar()) && (moveCursor(1) != 0)) { // nothing } return true; }
private boolean previousWord() throws IOException { while (isDelimiter(buf.current()) && (moveCursor(-1) != 0)) { // nothing } while (!isDelimiter(buf.current()) && (moveCursor(-1) != 0)) { // nothing } return true; }
/** * Issue <em>num</em> backspaces. * * @return the number of characters backed up */ private int backspace(final int num) throws IOException { if (buf.cursor == 0) { return 0; } int count = - moveCursor(-num); int clear = wcwidth(buf.buffer, buf.cursor, buf.cursor + count, getCursorPosition()); buf.buffer.delete(buf.cursor, buf.cursor + count); drawBuffer(clear); return count; }
moveCursor(-1); moveCursor(1); moveCursor(1);
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(); }
/** * 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 }
/** * Move the cursor position to the specified absolute index. */ public boolean setCursorPosition(final int position) throws IOException { if (position == buf.cursor) { return true; } return moveCursor(position - buf.cursor) != 0; }
private boolean upCaseWord() throws IOException { int i = 1; char c; while (buf.cursor + i - 1 < buf.length() && !isDelimiter((c = buf.buffer.charAt(buf.cursor + i - 1)))) { buf.buffer.setCharAt(buf.cursor + i - 1, Character.toUpperCase(c)); i++; } drawBuffer(); moveCursor(i - 1); return true; }
protected boolean moveToEnd() throws IOException { if (buf.cursor == buf.length()) { return true; } return moveCursor(buf.length() - buf.cursor) > 0; }
private boolean nextWord() throws IOException { while (isDelimiter(buf.nextChar()) && (moveCursor(1) != 0)) { // nothing } while (!isDelimiter(buf.nextChar()) && (moveCursor(1) != 0)) { // nothing } return true; }
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(); }