/** * Redraw the rest of the buffer from the cursor onwards. This is necessary * for inserting text into the buffer. */ private void drawBuffer() throws IOException { drawBuffer(0); }
/** * Issue a delete. * * @return true if successful */ public boolean delete() throws IOException { if (buf.cursor == buf.buffer.length()) { return false; } buf.buffer.delete(buf.cursor, buf.cursor + 1); drawBuffer(1); return true; }
/** * Delete the character at the current position and redraw the remainder of the buffer. */ private boolean deleteCurrentCharacter() throws IOException { if (buf.length() == 0 || buf.cursor == buf.length()) { return false; } buf.buffer.deleteCharAt(buf.cursor); drawBuffer(1); return true; }
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; }
/** * 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 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; }
/** * Performs character transpose. The character prior to the cursor and the * character under the cursor are swapped and the cursor is advanced one * character unless you are already at the end of the line. * * @param count The number of times to perform the transpose * @return true if the operation succeeded, false otherwise (e.g. transpose * cannot happen at the beginning of the line). */ private boolean transposeChars(int count) throws IOException { for (; count > 0; --count) { if (buf.cursor == 0 || buf.cursor == buf.buffer.length()) { return false; } int first = buf.cursor-1; int second = buf.cursor; char tmp = buf.buffer.charAt (first); buf.buffer.setCharAt(first, buf.buffer.charAt(second)); buf.buffer.setCharAt(second, tmp); // This could be done more efficiently by only re-drawing at the end. moveInternal(-1); drawBuffer(); moveInternal(2); } 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; }
/** * Output put the prompt + the current buffer */ public void drawLine() throws IOException { String prompt = getPrompt(); if (prompt != null) { rawPrint(prompt); } fmtPrint(buf.buffer, 0, buf.cursor, promptLen); // force drawBuffer to check for weird wrap (after clear screen) drawBuffer(); }
/** * Write out the specified string to the buffer and the output stream. */ public void putString(final CharSequence str) throws IOException { int pos = getCursorPosition(); buf.write(str); if (mask == null) { // no masking fmtPrint(str, pos); } else if (mask == NULL_MASK) { // don't print anything } else { rawPrint(mask, str.length()); } drawBuffer(); }
buf.cursor = startPos; buf.buffer.delete(startPos, endPos); drawBuffer(endPos - startPos);
/** * Clear the echoed characters for the specified character code. */ private int clearEcho(final int c) throws IOException { // if the terminal is not echoing, then ignore if (!terminal.isEchoEnabled()) { return 0; } // otherwise, clear int pos = getCursorPosition(); int num = wcwidth(c, pos); moveCursorFromTo(pos + num, pos); drawBuffer(num); return num; }
/** * Redraw the rest of the buffer from the cursor onwards. This is necessary * for inserting text into the buffer. */ private void drawBuffer() throws IOException { drawBuffer(0); }
/** * Issue a delete. * * @return true if successful */ public boolean delete() throws IOException { if (buf.cursor == buf.buffer.length()) { return false; } buf.buffer.delete(buf.cursor, buf.cursor + 1); drawBuffer(1); return true; }
/** * Delete the character at the current position and redraw the remainder of the buffer. */ private boolean deleteCurrentCharacter() throws IOException { if (buf.length() == 0 || buf.cursor == buf.length()) { return false; } buf.buffer.deleteCharAt(buf.cursor); drawBuffer(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; }
/** * Output put the prompt + the current buffer */ public void drawLine() throws IOException { String prompt = getPrompt(); if (prompt != null) { rawPrint(prompt); } fmtPrint(buf.buffer, 0, buf.cursor, promptLen); // force drawBuffer to check for weird wrap (after clear screen) drawBuffer(); }