diff options
author | Paul Phillips <paulp@improving.org> | 2011-04-14 19:33:39 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-04-14 19:33:39 +0000 |
commit | a0909c05738489c72237852e3ec3f748fc1b53b6 (patch) | |
tree | 0f7e401e0ecb446995d06d98de5f1af0737bf03f /src/jline | |
parent | 09e192caea0fe2b8afaed96a7077e8cf52af2345 (diff) | |
download | scala-a0909c05738489c72237852e3ec3f748fc1b53b6.tar.gz scala-a0909c05738489c72237852e3ec3f748fc1b53b6.tar.bz2 scala-a0909c05738489c72237852e3ec3f748fc1b53b6.zip |
Some patches to jline, and new jar.
for improving the keybindings. No review.
Diffstat (limited to 'src/jline')
9 files changed, 120 insertions, 301 deletions
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 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.sonatype.forge</groupId> - <artifactId>forge-parent</artifactId> - <version>6</version> - </parent> - - <groupId>org.sonatype.jline</groupId> - <artifactId>jline</artifactId> - <name>JLine</name> - <version>2.6-SNAPSHOT</version> - - <organization> - <name>Sonatype</name> - <url>http://sonatype.org</url> - </organization> - - <licenses> - <license> - <name>The BSD License</name> - <url>http://www.opensource.org/licenses/bsd-license.php</url> - <distribution>repo</distribution> - </license> - </licenses> - - <scm> - <connection>scm:git:git://github.com/jdillon/jline2.git</connection> - <developerConnection>scm:git:ssh://git@github.com/jdillon/jline2.git</developerConnection> - <url>http://github.com/jdillon/jline2</url> - </scm> - - <ciManagement> - <system>Hudson</system> - <url>https://grid.sonatype.org/ci/job/JLine2</url> - </ciManagement> - - <developers> - <developer> - <id>jdillon</id> - <name>Jason Dillon</name> - <email>jason@planet57.com</email> - <roles> - <role>Build Master</role> - <role>Developer</role> - </roles> - </developer> - </developers> - - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - </properties> - - <!-- - <repositories> - <repository> - <id>jansi</id> - <url>http://jansi.fusesource.org/repo/snapshot</url> - <releases> - <enabled>false</enabled> - </releases> - <snapshots> - <enabled>true</enabled> - </snapshots> - </repository> - </repositories> - --> - - <dependencies> - <dependency> - <groupId>org.fusesource.jansi</groupId> - <artifactId>jansi</artifactId> - <version>1.4</version> - <!--<scope>provided</scope>--> - </dependency> - - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.8.1</version> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <defaultGoal>install</defaultGoal> - - <resources> - <resource> - <directory>${project.basedir}/src/main/resources</directory> - <filtering>false</filtering> - <includes> - <include>**/*</include> - </includes> - </resource> - - <resource> - <directory>${project.basedir}/src/main/filtered-resources</directory> - <filtering>true</filtering> - <includes> - <include>**/*</include> - </includes> - </resource> - </resources> - - <testResources> - <testResource> - <directory>${project.basedir}/src/test/resources</directory> - <filtering>false</filtering> - <includes> - <include>**/*</include> - </includes> - </testResource> - - <testResource> - <directory>${project.basedir}/src/test/filtered-resources</directory> - <filtering>true</filtering> - <includes> - <include>**/*</include> - </includes> - </testResource> - </testResources> - - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.6</version> - <configuration> - <redirectTestOutputToFile>true</redirectTestOutputToFile> - <forkMode>once</forkMode> - <argLine>-ea</argLine> - <failIfNoTests>false</failIfNoTests> - <workingDirectory>${project.build.directory}</workingDirectory> - <excludes> - <exclude>**/Abstract*.java</exclude> - <exclude>**/Test*.java</exclude> - </excludes> - <includes> - <include>**/*Test.java</include> - </includes> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <version>2.3.2</version> - <configuration> - <source>1.5</source> - <target>1.5</target> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <version>2.1.0</version> - <executions> - <execution> - <phase>process-classes</phase> - <goals> - <goal>manifest</goal> - </goals> - <configuration> - <instructions> - <Import-Package>!scala.tools.jline*,javax.swing;resolution:=optional,*</Import-Package> - <DynamicImport-Package>*</DynamicImport-Package> - </instructions> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-jar-plugin</artifactId> - <version>2.3.1</version> - <configuration> - <archive> - <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> - </archive> - </configuration> - <executions> - <execution> - <goals> - <goal>test-jar</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-scm-plugin</artifactId> - <version>1.4</version> - </plugin> - - <!-- include all the dependencies into the jar so it can run standalone --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>1.4</version> - <executions> - <execution> - <goals> - <goal>shade</goal> - </goals> - <configuration> - <artifactSet> - <excludes> - <exclude>junit:junit</exclude> - </excludes> - </artifactSet> - <filters> - <filter> - <artifact>org.fusesource.jansi:jansi</artifact> - <excludes> - <exclude>META-INF/maven/**</exclude> - <exclude>*.txt</exclude> - <exclude>junit/**</exclude> - <exclude>org/junit/**</exclude> - <exclude>org/hamcrest/**</exclude> - <exclude>org/fusesource/hawtjni/runtime/Jni*</exclude> - <exclude>org/fusesource/hawtjni/runtime/*Flag*</exclude> - <exclude>org/fusesource/hawtjni/runtime/T32*</exclude> - <exclude>org/fusesource/hawtjni/runtime/NativeStats*</exclude> - </excludes> - </filter> - </filters> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - - <profiles> - <profile> - <id>retro</id> - <activation> - <property> - <name>retro</name> - <value>true</value> - </property> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>retrotranslator-maven-plugin</artifactId> - <version>1.0-alpha-4</version> - <executions> - <execution> - <goals> - <goal>translate-project</goal> - </goals> - <configuration> - <classifier>jdk14</classifier> - <attach>true</attach> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - -</project>
\ 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 |