summaryrefslogtreecommitdiff
path: root/src/jline
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-05-26 15:02:37 +0000
committerPaul Phillips <paulp@improving.org>2011-05-26 15:02:37 +0000
commit4f54ab68fec84e9312567e52e58cf1769de6e5bc (patch)
treecc1107f75248994bad3770ef7f92ed8f1ce0a203 /src/jline
parent3f192157811eb268d46f3a71011a5b2b966faa14 (diff)
downloadscala-4f54ab68fec84e9312567e52e58cf1769de6e5bc.tar.gz
scala-4f54ab68fec84e9312567e52e58cf1769de6e5bc.tar.bz2
scala-4f54ab68fec84e9312567e52e58cf1769de6e5bc.zip
Rebuilt jline with some navigation improvements...
Rebuilt jline with some navigation improvements (ctrl-T jumps forward a word, ctrl-X deletes the word in front of the cursor), thanks to Kenji Matsuoka for portions of this patch. Note to OSX users: TIL learned that ctrl-O is swallowed by the terminal and that unless you have some need for weird flow-control over serial connection control chars, you can recover it with stty discard undef And then you have ctrl-O for previous word and ctrl-T for next word. No review.
Diffstat (limited to 'src/jline')
-rw-r--r--src/jline/TEST-NOTE.txt4
-rw-r--r--src/jline/project/build.properties6
-rw-r--r--src/jline/project/plugins/project/build.properties2
-rw-r--r--src/jline/src/main/java/scala/tools/jline/UnixTerminal.java3
-rw-r--r--src/jline/src/main/java/scala/tools/jline/console/ConsoleReader.java30
-rw-r--r--src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java15
-rw-r--r--src/jline/src/main/java/scala/tools/jline/console/Key.java2
-rw-r--r--src/jline/src/main/java/scala/tools/jline/console/Operation.java6
-rw-r--r--src/jline/src/main/resources/scala/tools/jline/keybindings.properties5
-rw-r--r--src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java48
10 files changed, 102 insertions, 19 deletions
diff --git a/src/jline/TEST-NOTE.txt b/src/jline/TEST-NOTE.txt
new file mode 100644
index 0000000000..04f5de8dc1
--- /dev/null
+++ b/src/jline/TEST-NOTE.txt
@@ -0,0 +1,4 @@
+Apparently the jline bundled with sbt interferes with testing some changes: for instance after changing the keybindings I kept seeing failures until I realized what was happening, and bypassed sbt, e.g.
+
+% java -cp ./lib_managed/scala_2.9.0/compile/jansi-1.4.jar:./lib_managed/scala_2.9.0/test/'*':./target/scala_2.9.0/classes:./target/scala_2.9.0/test-classes:./target/scala_2.9.0/resources org.junit.runner.JUnitCore scala.tools.jline.console.EditLineTest
+
diff --git a/src/jline/project/build.properties b/src/jline/project/build.properties
index 89d3b4a498..0c2795bca5 100644
--- a/src/jline/project/build.properties
+++ b/src/jline/project/build.properties
@@ -2,7 +2,7 @@
#Wed Mar 23 21:05:24 PDT 2011
project.organization=org.improving
project.name=jline
-sbt.version=0.7.6.RC0
-project.version=0.98
-build.scala.versions=2.8.1
+sbt.version=0.7.7
+project.version=0.99-SNAPSHOT
+build.scala.versions=2.9.0
project.initialize=false
diff --git a/src/jline/project/plugins/project/build.properties b/src/jline/project/plugins/project/build.properties
index 218ed2577f..7a06683cda 100644
--- a/src/jline/project/plugins/project/build.properties
+++ b/src/jline/project/plugins/project/build.properties
@@ -1,3 +1,3 @@
#Project properties
-#Wed Mar 23 21:05:33 PDT 2011
+#Wed May 25 15:08:22 PDT 2011
plugin.uptodate=true
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 71659c5a42..94a1b98c0d 100644
--- a/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java
+++ b/src/jline/src/main/java/scala/tools/jline/UnixTerminal.java
@@ -175,6 +175,9 @@ public class UnixTerminal
else if (key == DEL) { // alt-backspace: delete previous word
return CTRL_W.code; // DELETE_PREV_WORD
}
+ else if (c == 'd') { // alt-d: delete next word
+ return CTRL_X.code; // DELETE_NEXT_WORD
+ }
}
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 f493619bcd..7882fcc1db 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
@@ -754,11 +754,11 @@ public class ConsoleReader
}
private boolean previousWord() throws IOException {
- while (isDelimiter(buf.current()) && (moveCursor(-1) != 0)) {
+ while (isDelimiter(buf.charLeftOfCursor()) && (moveCursor(-1) != 0)) {
// nothing
}
- while (!isDelimiter(buf.current()) && (moveCursor(-1) != 0)) {
+ while (!isDelimiter(buf.charLeftOfCursor()) && (moveCursor(-1) != 0)) {
// nothing
}
@@ -766,11 +766,11 @@ public class ConsoleReader
}
private boolean nextWord() throws IOException {
- while (isDelimiter(buf.current()) && (moveCursor(1) != 0)) {
+ while (isDelimiter(buf.charAtCursor()) && (moveCursor(1) != 0)) {
// nothing
}
- while (!isDelimiter(buf.current()) && (moveCursor(1) != 0)) {
+ while (!isDelimiter(buf.charAtCursor()) && (moveCursor(1) != 0)) {
// nothing
}
@@ -778,11 +778,23 @@ public class ConsoleReader
}
private boolean deletePreviousWord() throws IOException {
- while (isDelimiter(buf.current()) && backspace()) {
+ while (isDelimiter(buf.charLeftOfCursor()) && backspace()) {
// nothing
}
- while (!isDelimiter(buf.current()) && backspace()) {
+ while (!isDelimiter(buf.charLeftOfCursor()) && backspace()) {
+ // nothing
+ }
+
+ return true;
+ }
+
+ private boolean deleteNextWord() throws IOException {
+ while (isDelimiter(buf.charAtCursor()) && deleteCurrentCharacter()) {
+ // nothing
+ }
+
+ while (!isDelimiter(buf.charAtCursor()) && deleteCurrentCharacter()) {
// nothing
}
@@ -1283,7 +1295,7 @@ public class ConsoleReader
if (buf.buffer.length() == 0) {
return null;
} else {
- deleteCurrentCharacter();
+ success = deleteCurrentCharacter();
}
break;
@@ -1353,6 +1365,10 @@ public class ConsoleReader
success = deletePreviousWord();
break;
+ case DELETE_NEXT_WORD:
+ success = deleteNextWord();
+ break;
+
case PREV_WORD:
success = previousWord();
break;
diff --git a/src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java b/src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java
index d9cdbec124..7993def002 100644
--- a/src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java
+++ b/src/jline/src/main/java/scala/tools/jline/console/CursorBuffer.java
@@ -34,7 +34,10 @@ public class CursorBuffer
return buffer.length();
}
- public char current() {
+ /**
+ * Gets the character to the left of the cursor.
+ */
+ public char charLeftOfCursor() {
if (cursor <= 0) {
return 0;
}
@@ -43,6 +46,16 @@ public class CursorBuffer
}
/**
+ * Gets the character at the cursor.
+ */
+ public char charAtCursor() {
+ if (cursor < 0 || cursor >= buffer.length()) {
+ return 0;
+ }
+ return buffer.charAt(cursor);
+ }
+
+ /**
* Write the specific character into the buffer, setting the cursor position
* ahead one. The text may overwrite or insert based on the current setting
* of {@link #isOverTyping}.
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 26528555df..2e713a7da2 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
@@ -48,6 +48,8 @@ public enum Key
CTRL_W(23),
+ CTRL_X(24),
+
CTRL_OB(27),
CTRL_QM(127),
diff --git a/src/jline/src/main/java/scala/tools/jline/console/Operation.java b/src/jline/src/main/java/scala/tools/jline/console/Operation.java
index 17b216be57..59ee878d45 100644
--- a/src/jline/src/main/java/scala/tools/jline/console/Operation.java
+++ b/src/jline/src/main/java/scala/tools/jline/console/Operation.java
@@ -259,6 +259,12 @@ public enum Operation
* Cancel search
*/
ABORT(-64),
+
+ /**
+ * Delete next word
+ */
+ DELETE_NEXT_WORD(-65),
+
;
public final short code;
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 ebb5c8818a..ad932d2a80 100644
--- a/src/jline/src/main/resources/scala/tools/jline/keybindings.properties
+++ b/src/jline/src/main/resources/scala/tools/jline/keybindings.properties
@@ -48,7 +48,7 @@
# CTRL-P: scroll to the previous element in the history buffer
16=PREV_HISTORY
-# CTRL-R: redraw the current line
+# CTRL-R: search history
18=SEARCH_PREV
# CTRL-T: move to next word
@@ -63,6 +63,9 @@
# CTRL-W: delete the word directly before the cursor
23=DELETE_PREV_WORD
+# CTRL-X: delete the word directly after the cursor
+24=DELETE_NEXT_WORD
+
# DELETE, CTRL-?: delete the next character
# 127 is the ASCII code for delete
127=DELETE_NEXT_CHAR
diff --git a/src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java b/src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java
index be70979563..6f5d46121e 100644
--- a/src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java
+++ b/src/jline/src/test/java/scala/tools/jline/console/EditLineTest.java
@@ -8,9 +8,7 @@ package scala.tools.jline.console;
import org.junit.Test;
-import static scala.tools.jline.console.Operation.DELETE_PREV_WORD;
-import static scala.tools.jline.console.Operation.MOVE_TO_END;
-import static scala.tools.jline.console.Operation.PREV_WORD;
+import static scala.tools.jline.console.Operation.*;
/**
* Tests various features of editing lines.
@@ -29,7 +27,19 @@ public class EditLineTest
assertBuffer("This ", b = b.op(DELETE_PREV_WORD));
assertBuffer("", b = b.op(DELETE_PREV_WORD));
assertBuffer("", b = b.op(DELETE_PREV_WORD));
- assertBuffer("", b = b.op(DELETE_PREV_WORD));
+ assertBuffer("", b.op(DELETE_PREV_WORD));
+ }
+
+ @Test
+ public void testDeleteNextWord() throws Exception {
+ Buffer b = new Buffer("This is a test ");
+
+ assertBuffer(" is a test ", b = b.op(MOVE_TO_BEG).op(DELETE_NEXT_WORD));
+ assertBuffer(" a test ", b = b.op(DELETE_NEXT_WORD));
+ assertBuffer(" test ", b = b.op(DELETE_NEXT_WORD));
+ assertBuffer(" ", b = b.op(DELETE_NEXT_WORD));
+ assertBuffer("", b = b.op(DELETE_NEXT_WORD));
+ assertBuffer("", b.op(DELETE_NEXT_WORD));
}
@Test
@@ -96,6 +106,32 @@ public class EditLineTest
}
@Test
+ public void testNextWord() throws Exception {
+ assertBuffer("ThisX is a test",
+ new Buffer("This is a test").op(MOVE_TO_BEG)
+ .op(NEXT_WORD)
+ .append('X'));
+ assertBuffer("This isX a test",
+ new Buffer("This is a test").op(MOVE_TO_BEG)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .append('X'));
+ assertBuffer("This is aX test",
+ new Buffer("This is a test").op(MOVE_TO_BEG)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .append('X'));
+ assertBuffer("This is a testX ",
+ new Buffer("This is a test ").op(MOVE_TO_BEG)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .op(NEXT_WORD)
+ .append('X'));
+ }
+
+ @Test
public void testLineStart() throws Exception {
assertBuffer("XThis is a test",
new Buffer("This is a test").ctrlA().append('X'));
@@ -139,7 +175,7 @@ public class EditLineTest
assertBuffer("est", b = b.back());
assertBuffer("est", b = b.back());
assertBuffer("est", b = b.back());
- assertBuffer("est", b = b.back());
+ assertBuffer("est", b.back());
}
@Test
@@ -162,7 +198,7 @@ public class EditLineTest
assertBuffer("", b = b.back());
assertBuffer("", b = b.back());
assertBuffer("", b = b.back());
- assertBuffer("", b = b.back());
+ assertBuffer("", b.back());
}
@Test