From 93b4e617dbf30bf8765197cbe892ac67b4b3aa9e Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 13 Jan 2011 10:10:32 +0000 Subject: Fix for a jline paste bug. No review. --- src/jline/src/main/java/jline/UnixTerminal.java | 2 +- src/jline/src/main/java/jline/WindowsTerminal.java | 2 +- .../src/main/java/jline/console/ConsoleReader.java | 38 ++++++++++------------ 3 files changed, 19 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/jline/src/main/java/jline/UnixTerminal.java b/src/jline/src/main/java/jline/UnixTerminal.java index 37f18aea4e..755d899765 100644 --- a/src/jline/src/main/java/jline/UnixTerminal.java +++ b/src/jline/src/main/java/jline/UnixTerminal.java @@ -28,7 +28,7 @@ import static jline.console.Key.*; * /dev/tty file to disable character echoing and enable * character input. All known unix systems (including * Linux and Macintosh OS X) support the stty), so this - * implementation should work for an reasonable POSIX sys. + * implementation should work for an reasonable POSIX system. * * @author Marc Prud'hommeaux * @author Dale Kemp diff --git a/src/jline/src/main/java/jline/WindowsTerminal.java b/src/jline/src/main/java/jline/WindowsTerminal.java index 4304d6d473..dcaa3a9cde 100644 --- a/src/jline/src/main/java/jline/WindowsTerminal.java +++ b/src/jline/src/main/java/jline/WindowsTerminal.java @@ -302,7 +302,7 @@ public class WindowsTerminal * control keys are processed by the system and are not returned in the * ReadFile or ReadConsole buffer. If the ENABLE_LINE_INPUT mode is also * enabled, backspace, carriage return, and linefeed characters are handled - * by the sys. + * by the system. */ ENABLE_PROCESSED_INPUT(1), diff --git a/src/jline/src/main/java/jline/console/ConsoleReader.java b/src/jline/src/main/java/jline/console/ConsoleReader.java index b49966cf7e..660bb0cbc2 100644 --- a/src/jline/src/main/java/jline/console/ConsoleReader.java +++ b/src/jline/src/main/java/jline/console/ConsoleReader.java @@ -555,8 +555,20 @@ public class ConsoleReader if (mask != null) { Arrays.fill(chars, mask); } - - print(chars); + if (terminal.hasWeirdWrap()) { + // need to determine if wrapping will occur: + int width = terminal.getWidth(); + int pos = getCursorPosition(); + for (int i = 0; i < chars.length; i++) { + print(chars[i]); + if ((pos + i + 1) % width == 0) { + print(32); // move cursor to next line by printing dummy space + print(13); // CR / not newline. + } + } + } else { + print(chars); + } clearAhead(clear, chars.length); if (terminal.isAnsiSupported()) { if (chars.length > 0) { @@ -571,7 +583,7 @@ public class ConsoleReader // best guess on whether the cursor is in that weird location... // Need to do this without calling ansi cursor location methods // otherwise it breaks paste of wrapped lines in xterm. - if (getCursorPosition() == width + if (getCursorPosition() > 0 && (getCursorPosition() % width == 0) && buf.cursor == buf.length() && clear == 0) { // the following workaround is reverse-engineered from looking // at what bash sent to the terminal in the same situation @@ -603,20 +615,10 @@ public class ConsoleReader } if (terminal.isAnsiSupported()) { - // it's possible the real cursor is in the last column of a terminal - // with weird wrapping. int width = terminal.getWidth(); int screenCursorCol = getCursorPosition() + delta; - if (delta > 0 && terminal.hasWeirdWrap() - && screenCursorCol % width == 0) { - // need to clear out the line below - cursor has not wrapped - printAnsiSequence("B"); - printAnsiSequence("2K"); - printAnsiSequence("A"); - } else { - // clear current line - printAnsiSequence("K"); - } + // clear current line + printAnsiSequence("K"); // if cursor+num wraps, then we need to clear the line(s) below too int curCol = screenCursorCol % width; int endCol = (screenCursorCol + num - 1) % width; @@ -654,12 +656,6 @@ public class ConsoleReader int width = getTerminal().getWidth(); int cursor = getCursorPosition(); int realCursor = cursor + num; - // adjust cursor if it did not wrapped on its own - if (terminal.hasWeirdWrap() && realCursor%width == 0) { - if (getCurrentPosition() - 1 != realCursor%width) { - realCursor--; - } - } int realCol = realCursor % width; int newCol = cursor % width; int moveup = num / width; -- cgit v1.2.3