From a0909c05738489c72237852e3ec3f748fc1b53b6 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Thu, 14 Apr 2011 19:33:39 +0000 Subject: Some patches to jline, and new jar. for improving the keybindings. No review. --- lib/jline.jar.desired.sha1 | 2 +- src/jline/pom.xml | 273 --------------------- src/jline/project/build.properties | 4 +- src/jline/project/plugins/project/build.properties | 2 +- .../java/scala/tools/jline/TerminalSupport.java | 10 +- .../main/java/scala/tools/jline/UnixTerminal.java | 15 +- .../scala/tools/jline/console/ConsoleReader.java | 46 ++-- .../main/java/scala/tools/jline/console/Key.java | 6 + .../scala/tools/jline/keybindings.properties | 3 + .../scala/tools/jline/macbindings.properties | 62 +++++ 10 files changed, 121 insertions(+), 302 deletions(-) delete mode 100644 src/jline/pom.xml create mode 100644 src/jline/src/main/resources/scala/tools/jline/macbindings.properties diff --git a/lib/jline.jar.desired.sha1 b/lib/jline.jar.desired.sha1 index ba6e62ff61..a0f97c4d7a 100644 --- a/lib/jline.jar.desired.sha1 +++ b/lib/jline.jar.desired.sha1 @@ -1 +1 @@ -32f4eb98f8135b0d565e4e7aa72550f34fc4c133 ?jline.jar +115e0f58e2ffa089c083c466b0161216dd4c916e ?jline.jar diff --git a/src/jline/pom.xml b/src/jline/pom.xml deleted file mode 100644 index 08a59b054d..0000000000 --- a/src/jline/pom.xml +++ /dev/null @@ -1,273 +0,0 @@ - - - - 4.0.0 - - - org.sonatype.forge - forge-parent - 6 - - - org.sonatype.jline - jline - JLine - 2.6-SNAPSHOT - - - Sonatype - http://sonatype.org - - - - - The BSD License - http://www.opensource.org/licenses/bsd-license.php - repo - - - - - scm:git:git://github.com/jdillon/jline2.git - scm:git:ssh://git@github.com/jdillon/jline2.git - http://github.com/jdillon/jline2 - - - - Hudson - https://grid.sonatype.org/ci/job/JLine2 - - - - - jdillon - Jason Dillon - jason@planet57.com - - Build Master - Developer - - - - - - UTF-8 - - - - - - - org.fusesource.jansi - jansi - 1.4 - - - - - junit - junit - 4.8.1 - test - - - - - install - - - - ${project.basedir}/src/main/resources - false - - **/* - - - - - ${project.basedir}/src/main/filtered-resources - true - - **/* - - - - - - - ${project.basedir}/src/test/resources - false - - **/* - - - - - ${project.basedir}/src/test/filtered-resources - true - - **/* - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.6 - - true - once - -ea - false - ${project.build.directory} - - **/Abstract*.java - **/Test*.java - - - **/*Test.java - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.5 - 1.5 - - - - - org.apache.felix - maven-bundle-plugin - 2.1.0 - - - process-classes - - manifest - - - - !scala.tools.jline*,javax.swing;resolution:=optional,* - * - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.3.1 - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - - - - - test-jar - - - - - - - org.apache.maven.plugins - maven-scm-plugin - 1.4 - - - - - org.apache.maven.plugins - maven-shade-plugin - 1.4 - - - - shade - - - - - junit:junit - - - - - org.fusesource.jansi:jansi - - META-INF/maven/** - *.txt - junit/** - org/junit/** - org/hamcrest/** - org/fusesource/hawtjni/runtime/Jni* - org/fusesource/hawtjni/runtime/*Flag* - org/fusesource/hawtjni/runtime/T32* - org/fusesource/hawtjni/runtime/NativeStats* - - - - - - - - - - - - - retro - - - retro - true - - - - - - org.codehaus.mojo - retrotranslator-maven-plugin - 1.0-alpha-4 - - - - translate-project - - - jdk14 - true - - - - - - - - - - \ No newline at end of file diff --git a/src/jline/project/build.properties b/src/jline/project/build.properties index 3ecffcd808..89d3b4a498 100644 --- a/src/jline/project/build.properties +++ b/src/jline/project/build.properties @@ -1,8 +1,8 @@ #Project properties +#Wed Mar 23 21:05:24 PDT 2011 project.organization=org.improving project.name=jline -sbt.version=0.7.5.RC0 +sbt.version=0.7.6.RC0 project.version=0.98 build.scala.versions=2.8.1 -/*build.scala.versions=2.9.0-SNAPSHOT*/ project.initialize=false diff --git a/src/jline/project/plugins/project/build.properties b/src/jline/project/plugins/project/build.properties index 0b7014c531..24481fef8e 100644 --- a/src/jline/project/plugins/project/build.properties +++ b/src/jline/project/plugins/project/build.properties @@ -1,3 +1,3 @@ #Project properties -#Thu Feb 10 14:58:03 PST 2011 +#Tue Apr 05 12:32:56 PDT 2011 plugin.uptodate=true diff --git a/src/jline/src/main/java/scala/tools/jline/TerminalSupport.java b/src/jline/src/main/java/scala/tools/jline/TerminalSupport.java index 1ca12cb73f..03004fea68 100644 --- a/src/jline/src/main/java/scala/tools/jline/TerminalSupport.java +++ b/src/jline/src/main/java/scala/tools/jline/TerminalSupport.java @@ -24,6 +24,10 @@ public abstract class TerminalSupport implements Terminal { public static String DEFAULT_KEYBINDINGS_PROPERTIES = "keybindings.properties"; + public static String DEFAULT_KEYBINDINGS_PROPERTIES_MAC = "macbindings.properties"; + public static boolean isMac() { + return System.getProperty("os.name").toLowerCase().startsWith("mac"); + } public static final String JLINE_SHUTDOWNHOOK = "jline.shutdownhook"; @@ -157,7 +161,11 @@ public abstract class TerminalSupport } public InputStream getDefaultBindings() { - return TerminalSupport.class.getResourceAsStream(DEFAULT_KEYBINDINGS_PROPERTIES); + // Mac bindings are slightly different from Unix/Linux. + // For instance, the Delete key behavior is different between them. + return TerminalSupport.class.getResourceAsStream( + isMac() ? DEFAULT_KEYBINDINGS_PROPERTIES_MAC : DEFAULT_KEYBINDINGS_PROPERTIES + ); } // diff --git a/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java b/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java index 10c98888d3..71659c5a42 100644 --- a/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java +++ b/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java @@ -166,6 +166,16 @@ public class UnixTerminal return DELETE.code; } } + else if (c == 'b') { // alt-b: go back a word + return CTRL_O.code; // PREV_WORD + } + else if (c == 'f') { // alt-f: go forward a word + return CTRL_T.code; // NEXT_WORD + } + else if (key == DEL) { // alt-backspace: delete previous word + return CTRL_W.code; // DELETE_PREV_WORD + } + } // handle unicode characters, thanks for a patch from amyi@inf.ed.ac.uk @@ -205,7 +215,10 @@ public class UnixTerminal DEL_THIRD(51), - DEL_SECOND(126),; + DEL_SECOND(126), + + DEL(127); + public final short code; diff --git a/src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java b/src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java index 861c2d58bd..5e6f5c166a 100644 --- a/src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java +++ b/src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java @@ -85,7 +85,7 @@ public class ConsoleReader { this.in = in; this.terminal = term != null ? term : TerminalFactory.get(); - this.out = new PrintWriter(terminal.wrapOutIfNeeded(out)); + this.out = new PrintWriter(getTerminal().wrapOutIfNeeded(out)); this.keyBindings = loadKeyBindings(bindings); setBellEnabled(!Configuration.getBoolean(JLINE_NOBELL, false)); @@ -555,9 +555,9 @@ public class ConsoleReader if (mask != null) { Arrays.fill(chars, mask); } - if (terminal.hasWeirdWrap()) { + if (getTerminal().hasWeirdWrap()) { // need to determine if wrapping will occur: - int width = terminal.getWidth(); + int width = getTerminal().getWidth(); int pos = getCursorPosition(); for (int i = 0; i < chars.length; i++) { print(chars[i]); @@ -570,7 +570,7 @@ public class ConsoleReader print(chars); } clearAhead(clear, chars.length); - if (terminal.isAnsiSupported()) { + if (getTerminal().isAnsiSupported()) { if (chars.length > 0) { back(chars.length); } @@ -578,8 +578,8 @@ public class ConsoleReader back(chars.length); } } - if (terminal.hasWeirdWrap()) { - int width = terminal.getWidth(); + if (getTerminal().hasWeirdWrap()) { + int width = getTerminal().getWidth(); // 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. @@ -614,8 +614,8 @@ public class ConsoleReader return; } - if (terminal.isAnsiSupported()) { - int width = terminal.getWidth(); + if (getTerminal().isAnsiSupported()) { + int width = getTerminal().getWidth(); int screenCursorCol = getCursorPosition() + delta; // clear current line printAnsiSequence("K"); @@ -652,7 +652,7 @@ public class ConsoleReader */ protected void back(final int num) throws IOException { if (num == 0) return; - if (terminal.isAnsiSupported()) { + if (getTerminal().isAnsiSupported()) { int width = getTerminal().getWidth(); int cursor = getCursorPosition(); int realCursor = cursor + num; @@ -700,7 +700,7 @@ public class ConsoleReader count = moveCursor(-1 * num) * -1; buf.buffer.delete(buf.cursor, buf.cursor + count); if (getCursorPosition() / termwidth != lines) { - if (terminal.isAnsiSupported()) { + if (getTerminal().isAnsiSupported()) { // debug("doing backspace redraw: " + getCursorPosition() + " on " + termwidth + ": " + lines); printAnsiSequence("K"); // if cursor+num wraps, then we need to clear the line(s) below too @@ -828,7 +828,7 @@ public class ConsoleReader // + buf.cursor + " => " + (buf.cursor + where) + ")"); buf.cursor += where; - if (terminal.isAnsiSupported()) { + if (getTerminal().isAnsiSupported()) { if (where < 0) { back(Math.abs(where)); } else { @@ -837,12 +837,12 @@ public class ConsoleReader int oldLine = (cursor - where) / width; int newLine = cursor / width; if (newLine > oldLine) { - if (terminal.hasWeirdWrap()) { + if (getTerminal().hasWeirdWrap()) { // scroll up if at bottom // note: - // on rxvt cywgin terminal.getHeight() is incorrect + // on rxvt cywgin getTerminal().getHeight() is incorrect // MacOs xterm does not seem to support scrolling - if (getCurrentAnsiRow() == terminal.getHeight()) { + if (getCurrentAnsiRow() == getTerminal().getHeight()) { printAnsiSequence((newLine - oldLine) + "S"); } } @@ -918,7 +918,7 @@ public class ConsoleReader * @return the character, or -1 if an EOF is received. */ public final int readVirtualKey() throws IOException { - int c = terminal.readVirtualKey(in); + int c = getTerminal().readVirtualKey(in); Log.trace("Keystroke: ", c); @@ -933,7 +933,7 @@ public class ConsoleReader */ private int clearEcho(final int c) throws IOException { // if the terminal is not echoing, then ignore - if (!terminal.isEchoEnabled()) { + if (!getTerminal().isEchoEnabled()) { return 0; } @@ -1171,7 +1171,7 @@ public class ConsoleReader } try { - if (!terminal.isSupported()) { + if (!getTerminal().isSupported()) { beforeReadLine(prompt, mask); } @@ -1181,7 +1181,7 @@ public class ConsoleReader } // if the terminal is unsupported, just use plain-java reading - if (!terminal.isSupported()) { + if (!getTerminal().isSupported()) { return readLine(in); } @@ -1283,7 +1283,7 @@ public class ConsoleReader if (buf.buffer.length() == 0) { return null; } else { - deleteCurrentCharacter(); + success = deleteCurrentCharacter(); } break; @@ -1428,7 +1428,7 @@ public class ConsoleReader } } finally { - if (!terminal.isSupported()) { + if (!getTerminal().isSupported()) { afterReadLine(); } } @@ -1756,7 +1756,7 @@ public class ConsoleReader * Clear the screen by issuing the ANSI "clear screen" code. */ public boolean clearScreen() throws IOException { - if (!terminal.isAnsiSupported()) { + if (!getTerminal().isAnsiSupported()) { return false; } @@ -2109,7 +2109,7 @@ public class ConsoleReader // return column position, reported by the terminal private int getCurrentPosition() { // check for ByteArrayInputStream to disable for unit tests - if (terminal.isAnsiSupported() && !(in instanceof ByteArrayInputStream)) { + if (getTerminal().isAnsiSupported() && !(in instanceof ByteArrayInputStream)) { try { printAnsiSequence("6n"); flush(); @@ -2136,7 +2136,7 @@ public class ConsoleReader // wrapping terminals - not tested for anything else private int getCurrentAnsiRow() { // check for ByteArrayInputStream to disable for unit tests - if (terminal.isAnsiSupported() && !(in instanceof ByteArrayInputStream)) { + if (getTerminal().isAnsiSupported() && !(in instanceof ByteArrayInputStream)) { try { printAnsiSequence("6n"); flush(); diff --git a/src/jline/src/main/java/scala/tools/jline/console/Key.java b/src/jline/src/main/java/scala/tools/jline/console/Key.java index 5c13d19860..26528555df 100644 --- a/src/jline/src/main/java/scala/tools/jline/console/Key.java +++ b/src/jline/src/main/java/scala/tools/jline/console/Key.java @@ -40,8 +40,14 @@ public enum Key CTRL_N(14), + CTRL_O(15), + CTRL_P(16), + CTRL_T(20), + + CTRL_W(23), + CTRL_OB(27), CTRL_QM(127), diff --git a/src/jline/src/main/resources/scala/tools/jline/keybindings.properties b/src/jline/src/main/resources/scala/tools/jline/keybindings.properties index 610a1626aa..ebb5c8818a 100644 --- a/src/jline/src/main/resources/scala/tools/jline/keybindings.properties +++ b/src/jline/src/main/resources/scala/tools/jline/keybindings.properties @@ -51,6 +51,9 @@ # CTRL-R: redraw the current line 18=SEARCH_PREV +# CTRL-T: move to next word +20=NEXT_WORD + # CTRL-U: delete all the characters before the cursor position 21=KILL_LINE_PREV diff --git a/src/jline/src/main/resources/scala/tools/jline/macbindings.properties b/src/jline/src/main/resources/scala/tools/jline/macbindings.properties new file mode 100644 index 0000000000..8e810a8364 --- /dev/null +++ b/src/jline/src/main/resources/scala/tools/jline/macbindings.properties @@ -0,0 +1,62 @@ +# Keybinding mapping for JLine. The format is: +# [key code]: [logical operation] + +# CTRL-B: move to the previous character +2: PREV_CHAR + +# CTRL-G: move to the previous word +7: PREV_WORD + +# CTRL-F: move to the next character +6: NEXT_CHAR + +# CTRL-A: move to the beginning of the line +1: MOVE_TO_BEG + +# CTRL-D: close out the input stream +4: EXIT + +# CTRL-E: move the cursor to the end of the line +5: MOVE_TO_END + +# BACKSPACE, CTRL-H: delete the previous character +# 8 is the ASCII code for backspace and therefor +# deleting the previous character +8: DELETE_PREV_CHAR + +# TAB, CTRL-I: signal that console completion should be attempted +9: COMPLETE + +# CTRL-J, CTRL-M: newline +10: NEWLINE + +# CTRL-K: erase the current line +11: KILL_LINE + +# ENTER: newline +13: NEWLINE + +# CTRL-L: clear screen +12: CLEAR_SCREEN + +# CTRL-N: scroll to the next element in the history buffer +14: NEXT_HISTORY + +# CTRL-P: scroll to the previous element in the history buffer +16: PREV_HISTORY + +# CTRL-R: redraw the current line +18: REDISPLAY + +# CTRL-U: delete all the characters before the cursor position +21: KILL_LINE_PREV + +# CTRL-V: paste the contents of the clipboard (useful for Windows terminal) +22: PASTE + +# CTRL-W: delete the word directly before the cursor +23: DELETE_PREV_WORD + +# DELETE, CTRL-?: delete the previous character +# 127 is the ASCII code for delete +127: DELETE_NEXT_CHAR -- cgit v1.2.3