|
From: <cr...@us...> - 2008-10-10 13:01:43
|
Revision: 4618
http://jnode.svn.sourceforge.net/jnode/?rev=4618&view=rev
Author: crawley
Date: 2008-10-10 13:01:27 +0000 (Fri, 10 Oct 2008)
Log Message:
-----------
Implemented a new 'bindkeys' command. At the moment it just lists
the current KR key bindings.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java
trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/TextConsole.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java
trunk/shell/descriptors/org.jnode.shell.command.xml
Added Paths:
-----------
trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
Modified: trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/ActiveTextConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -4,7 +4,10 @@
import java.io.Reader;
import java.io.Writer;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+
+
/**
* This virtual console class operates on the console that has the current focus.
* The {@link #getOut()} and {@link #getErr()} return Writers that track changes
@@ -91,12 +94,12 @@
}
@Override
- public KeyEventBindings getKeyEventBindings() {
+ public ConsoleKeyEventBindings getKeyEventBindings() {
throw new UnsupportedOperationException();
}
@Override
- public void setKeyEventBindings(KeyEventBindings bindings) {
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
throw new UnsupportedOperationException();
}
Modified: trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/KeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -22,6 +22,7 @@
import java.awt.event.KeyEvent;
import java.util.HashMap;
+import java.util.Set;
import org.jnode.driver.input.KeyboardEvent;
@@ -31,30 +32,30 @@
*
* @author cr...@jn...
*/
-public class KeyEventBindings {
+public abstract class KeyEventBindings<T extends Enum<?>> {
- private final int defaultCharAction;
- private final int defaultVKAction;
- private CodeMap charMap;
- private CodeMap vkMap;
+ private final T defaultCharAction;
+ private final T defaultVKAction;
+ private CodeMap<T> charMap;
+ private CodeMap<T> vkMap;
/**
* Create empty bindings.
* @param defaultCharAction the default action for a character-valued event
* @param defaultVKAction the default action for a VK-valued event.
*/
- public KeyEventBindings(int defaultCharAction, int defaultVKAction) {
+ public KeyEventBindings(T defaultCharAction, T defaultVKAction) {
this.defaultCharAction = defaultCharAction;
this.defaultVKAction = defaultVKAction;
- this.charMap = new CodeMap(defaultCharAction);
- this.vkMap = new CodeMap(defaultVKAction);
+ this.charMap = new CodeMap<T>(defaultCharAction);
+ this.vkMap = new CodeMap<T>(defaultVKAction);
}
/**
* Create a copy of an existing KeyEventBindings object.
* @param bindings the bindings to be copied.
*/
- public KeyEventBindings(KeyEventBindings bindings) {
+ public KeyEventBindings(KeyEventBindings<T> bindings) {
this.defaultCharAction = bindings.defaultCharAction;
this.defaultVKAction = bindings.defaultVKAction;
this.charMap = new CodeMap(bindings.charMap);
@@ -75,7 +76,7 @@
* @param ch the character
* @return the corresponding action.
*/
- public int getKeyboardEventAction(KeyboardEvent event) {
+ public T getKeyboardEventAction(KeyboardEvent event) {
char ch = event.getKeyChar();
if (ch == KeyEvent.CHAR_UNDEFINED) {
return getVKAction(event.getKeyCode(), event.getModifiers());
@@ -90,7 +91,7 @@
* @param ch the character
* @return the corresponding action.
*/
- public int getCharAction(char ch) {
+ public T getCharAction(char ch) {
return charMap.get(ch);
}
@@ -101,7 +102,7 @@
* @param modifiers the modifier set
* @return the corresponding action.
*/
- public int getVKAction(int vk, int modifiers) {
+ public T getVKAction(int vk, int modifiers) {
checkVK(vk, modifiers);
return vkMap.get(vk | (modifiers << 16));
}
@@ -114,6 +115,10 @@
throw new IllegalArgumentException("modifiers range error");
}
}
+
+ public T getVKAction(VirtualKey vk) {
+ return vkMap.get(vk.value);
+ }
/**
* Set the action for a given character
@@ -121,7 +126,7 @@
* @param ch the character
* @param action the action
*/
- public void setCharAction(char ch, int action) {
+ public void setCharAction(char ch, T action) {
charMap.put(ch, action);
}
@@ -131,7 +136,7 @@
* @param vk the virtual key code
* @param action the action
*/
- public void setVKAction(int vk, int action) {
+ public void setVKAction(int vk, T action) {
checkVK(vk, 0);
vkMap.put(vk, action);
}
@@ -143,7 +148,7 @@
* @param modifiers the modifier set
* @param action the action
*/
- public void setVKAction(int vk, int modifiers, int action) {
+ public void setVKAction(int vk, int modifiers, T action) {
checkVK(vk, modifiers);
vkMap.put(vk | (modifiers << 16), action);
}
@@ -155,7 +160,7 @@
* @param chHi the last character in the range
* @param action the action
*/
- public void setCharAction(char chLo, char chHi, int action) {
+ public void setCharAction(char chLo, char chHi, T action) {
charMap.put(chLo, chHi, action);
}
@@ -167,7 +172,7 @@
* @param modifiers the modifier set
* @param action the action
*/
- public void setVKAction(int vkLo, int vkHi, int modifiers, int action) {
+ public void setVKAction(int vkLo, int vkHi, int modifiers, T action) {
checkVK(vkLo, modifiers);
checkVK(vkHi, modifiers);
if (modifiers == 0) {
@@ -181,27 +186,47 @@
}
}
}
+
+ public char[] getBoundChars() {
+ Set<Integer> charSet = charMap.getKeys();
+ char[] res = new char[charSet.size()];
+ int i = 0;
+ for (int ch : charSet) {
+ res[i++] = (char) ch;
+ }
+ return res;
+ }
+ public VirtualKey[] getBoundVKs() {
+ Set<Integer> vkSet = vkMap.getKeys();
+ VirtualKey[] res = new VirtualKey[vkSet.size()];
+ int i = 0;
+ for (int vk : vkSet) {
+ res[i++] = new VirtualKey(vk);
+ }
+ return res;
+ }
+
/**
* This class implements a sparse representation of an int to int
* mapping using a HashMap and a default value.
*/
- private static class CodeMap {
- private final HashMap<Integer, Integer> map;
- private final int defaultValue;
+ private static class CodeMap<T extends Enum<?>> {
+ private final HashMap<Integer, T> map;
+ private final T defaultValue;
- public CodeMap(int defaultValue) {
+ public CodeMap(T defaultValue) {
this.defaultValue = defaultValue;
- this.map = new HashMap<Integer, Integer>();
+ this.map = new HashMap<Integer, T>();
}
- public CodeMap(CodeMap codeMap) {
+ public CodeMap(CodeMap<T> codeMap) {
this.defaultValue = codeMap.defaultValue;
- this.map = new HashMap<Integer, Integer>(codeMap.map);
+ this.map = new HashMap<Integer, T>(codeMap.map);
}
- public int get(int key) {
- Integer value = this.map.get(key);
+ public T get(int key) {
+ T value = this.map.get(key);
if (value != null) {
return value;
} else {
@@ -209,7 +234,7 @@
}
}
- public void put(int key, int value) {
+ public void put(int key, T value) {
if (value == this.defaultValue) {
this.map.remove(key);
} else {
@@ -217,7 +242,7 @@
}
}
- public void put(int keyLo, int keyHi, int value) {
+ public void put(int keyLo, int keyHi, T value) {
if (keyLo > keyHi) {
throw new IllegalArgumentException("keyLo > keyHi");
}
@@ -231,5 +256,9 @@
}
}
}
+
+ public Set<Integer> getKeys() {
+ return map.keySet();
+ }
}
}
Modified: trunk/core/src/driver/org/jnode/driver/console/TextConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/TextConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,7 +24,10 @@
import java.io.Reader;
import java.io.Writer;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+
+
/**
* @author Ewout Prangsma (ep...@us...)
* @author Levente S\u00e1ntha (ls...@us...)
@@ -210,13 +213,13 @@
*
* @return a copy of the current bindings.
*/
- public KeyEventBindings getKeyEventBindings();
+ public ConsoleKeyEventBindings getKeyEventBindings();
/**
* Set the console's key event bindings.
*
* @param bindings the new bindings.
*/
- public void setKeyEventBindings(KeyEventBindings bindings);
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings);
}
Added: trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/console/VirtualKey.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -0,0 +1,64 @@
+/*
+ * $Id: TextConsole.java 4613 2008-10-08 13:56:25Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+package org.jnode.driver.console;
+
+/**
+ * This class is used to represent a VK code / modifier pair in the context of
+ * the KeyEventBindings.
+ *
+ * @author cr...@jn...
+ */
+public class VirtualKey {
+
+ public final int value;
+
+ public VirtualKey(int value) {
+ this.value = value;
+ }
+
+ public int getVKCode() {
+ return value & 0xffff;
+ }
+
+ public int getModifiers() {
+ return value >>> 16;
+ }
+
+ @Override
+ public int hashCode() {
+ return value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || this.getClass() != obj.getClass()) {
+ return false;
+ }
+ final VirtualKey other = (VirtualKey) obj;
+ if (value != other.value) {
+ return false;
+ }
+ return true;
+ }
+}
\ No newline at end of file
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/ConsoleKeyEventBindings.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,143 +24,52 @@
import org.jnode.driver.console.KeyEventBindings;
+
/**
* KeyEventBinding class for the Console system.
*
* @author cr...@jn...
*/
-public class ConsoleKeyEventBindings extends KeyEventBindings {
-
- /**
- * This KR code causes the event's character (or in some circumstances its
- * VK code) to be inserted into to the input buffer at the position of the
- * cursor. The cursor is then advanced to after the inserted character.
- */
- public static final byte KR_INSERT = 0;
+public class ConsoleKeyEventBindings extends KeyEventBindings<KeyboardReaderAction> {
/**
- * This KR code causes the event to be consumed with no other action.
- */
- public static final byte KR_CONSUME = 1;
-
- /**
- * This KR code causes the event to be ignored without consuming it.
- * (This KR code may go away.)
- */
- public static final byte KR_IGNORE = 2;
-
- /**
- * This KR code causes the input buffer to be terminated with
- * a '\n' and send to the input stream for reading.
- */
- public static final byte KR_ENTER = 3;
-
- /**
- * This KR code causes the input buffer to be cleared. All characters
- * are removed and the input cursor is set to the start of the buffer.
- */
- public static final byte KR_KILL_LINE = 4;
-
- /**
- * This KR code causes the input completion to be performed.
- */
- public static final byte KR_COMPLETE = 5;
-
- /**
- * This KR code causes the input line to be refreshed to the
- * console.
- */
- public static final byte KR_REDRAW = 6;
-
- /**
- * This KR code denotes a 'soft eof' marker.
- */
- public static final byte KR_SOFT_EOF = 7;
-
- /**
- * This KR code causes the input cursor to be moved one
- * character to the left. If the cursor is already at the start of the
- * input buffer, it is not moved. No characters are added or removed.
- */
- public static final byte KR_CURSOR_LEFT = 8;
-
- /**
- * This KR code causes the input cursor to be moved one
- * character to the right. If the cursor is already at the end of the
- * input buffer, it is not moved. No characters are added or removed.
- */
- public static final byte KR_CURSOR_RIGHT = 9;
-
- /**
- * This KR code causes the input cursor to be moved to the before the
- * first character in the input buffer. No characters are added or removed.
- */
- public static final byte KR_CURSOR_TO_START = 10;
-
- /**
- * This KR code causes the input buffer cursor to be moved to after the
- * last character in the input buffer. No characters are added or removed.
- */
- public static final byte KR_CURSOR_TO_END = 11;
-
- /**
- * This KR code causes one character to the left of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_BEFORE = 12;
-
- /**
- * This KR code causes one character to the right of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_AFTER = 13;
-
- /**
- * This KR code causes all characters to the right of the input cursor to be
- * deleted from the input buffer.
- */
- public static final byte KR_DELETE_TO_END = 14;
-
- /**
- * This KR code causes the previous history line to be selected.
- */
- public static final byte KR_HISTORY_UP = 15;
-
- /**
- * This KR code causes the next history line to be selected.
- */
- public static final byte KR_HISTORY_DOWN = 16;
-
- /**
* Create empty bindings. The default action for characters is to insert
* the character. The default action for virtual keys is to ignore the key.
*/
public ConsoleKeyEventBindings() {
- super(KR_INSERT, KR_IGNORE);
+ super(KeyboardReaderAction.KR_INSERT, KeyboardReaderAction.KR_IGNORE);
}
/**
- * Create KeyEventBindings initialized to the hard-wired defaults.
+ * Create a copy of an existing ConsoleKeyEventBindings object.
+ * @param bindings the bindings to be copied.
+ */
+ public ConsoleKeyEventBindings(ConsoleKeyEventBindings bindings) {
+ super(bindings);
+ }
+
+ /**
+ * Create a ConsoleKeyEventBindings object initialized to the hard-wired defaults.
* @return the default bindings.
*/
public static ConsoleKeyEventBindings createDefault() {
ConsoleKeyEventBindings res = new ConsoleKeyEventBindings();
- res.setVKAction(KeyEvent.VK_BACK_SPACE, KR_DELETE_BEFORE);
- res.setCharAction('\b', KR_DELETE_BEFORE);
- res.setVKAction(KeyEvent.VK_ENTER, KR_ENTER);
- res.setCharAction('\n', KR_ENTER);
- res.setVKAction(KeyEvent.VK_TAB, KR_COMPLETE);
- res.setCharAction('\t', KR_COMPLETE);
- res.setCharAction('\004', KR_SOFT_EOF);
- res.setCharAction('\014', KR_KILL_LINE);
- res.setVKAction(KeyEvent.VK_UP, KR_HISTORY_UP);
- res.setVKAction(KeyEvent.VK_DOWN, KR_HISTORY_DOWN);
- res.setVKAction(KeyEvent.VK_LEFT, KR_CURSOR_LEFT);
- res.setVKAction(KeyEvent.VK_RIGHT, KR_CURSOR_RIGHT);
- res.setVKAction(KeyEvent.VK_HOME, KR_CURSOR_TO_START);
- res.setVKAction(KeyEvent.VK_END, KR_CURSOR_TO_END);
- res.setCharAction('\177', KR_DELETE_AFTER);
- res.setVKAction(KeyEvent.VK_DELETE, KR_DELETE_AFTER);
+ res.setVKAction(KeyEvent.VK_BACK_SPACE, KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setCharAction('\b', KeyboardReaderAction.KR_DELETE_BEFORE);
+ res.setVKAction(KeyEvent.VK_ENTER, KeyboardReaderAction.KR_ENTER);
+ res.setCharAction('\n', KeyboardReaderAction.KR_ENTER);
+ res.setVKAction(KeyEvent.VK_TAB, KeyboardReaderAction.KR_COMPLETE);
+ res.setCharAction('\t', KeyboardReaderAction.KR_COMPLETE);
+ res.setCharAction('\004', KeyboardReaderAction.KR_SOFT_EOF);
+ res.setCharAction('\014', KeyboardReaderAction.KR_KILL_LINE);
+ res.setVKAction(KeyEvent.VK_UP, KeyboardReaderAction.KR_HISTORY_UP);
+ res.setVKAction(KeyEvent.VK_DOWN, KeyboardReaderAction.KR_HISTORY_DOWN);
+ res.setVKAction(KeyEvent.VK_LEFT, KeyboardReaderAction.KR_CURSOR_LEFT);
+ res.setVKAction(KeyEvent.VK_RIGHT, KeyboardReaderAction.KR_CURSOR_RIGHT);
+ res.setVKAction(KeyEvent.VK_HOME, KeyboardReaderAction.KR_CURSOR_TO_START);
+ res.setVKAction(KeyEvent.VK_END, KeyboardReaderAction.KR_CURSOR_TO_END);
+ res.setCharAction('\177', KeyboardReaderAction.KR_DELETE_AFTER);
+ res.setVKAction(KeyEvent.VK_DELETE, KeyboardReaderAction.KR_DELETE_AFTER);
return res;
}
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReader.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -1,27 +1,11 @@
package org.jnode.driver.console.textscreen;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_COMPLETE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CONSUME;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_LEFT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_RIGHT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_TO_END;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_CURSOR_TO_START;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_DELETE_AFTER;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_DELETE_BEFORE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_ENTER;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_HISTORY_UP;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_IGNORE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_INSERT;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_KILL_LINE;
-import static org.jnode.driver.console.textscreen.ConsoleKeyEventBindings.KR_SOFT_EOF;
-
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import org.jnode.driver.console.InputCompleter;
-import org.jnode.driver.console.KeyEventBindings;
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.input.KeyboardEvent;
import org.jnode.system.event.FocusEvent;
@@ -80,7 +64,7 @@
private InputCompleter completer;
private final Writer out;
- private KeyEventBindings bindings = ConsoleKeyEventBindings.createDefault();
+ private ConsoleKeyEventBindings bindings = ConsoleKeyEventBindings.createDefault();
private String currentPrompt;
@@ -135,8 +119,8 @@
*
* @return a copy of the current bindings.
*/
- public KeyEventBindings getKeyEventBindings() {
- return new KeyEventBindings(bindings);
+ public ConsoleKeyEventBindings getKeyEventBindings() {
+ return new ConsoleKeyEventBindings(bindings);
}
/**
@@ -144,8 +128,8 @@
*
* @param bindings the new bindings.
*/
- public void setKeyEventBindings(KeyEventBindings bindings) {
- this.bindings = new KeyEventBindings(bindings);
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
+ this.bindings = new ConsoleKeyEventBindings(bindings);
}
@Override
@@ -169,7 +153,7 @@
private boolean processEvent() throws IOException {
KeyboardEvent event = keyboardHandler.getEvent();
if (!event.isConsumed()) {
- int action = bindings.getKeyboardEventAction(event);
+ KeyboardReaderAction action = bindings.getKeyboardEventAction(event);
boolean breakChar = false;
boolean consume = true;
switch (action) {
Added: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardReaderAction.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -0,0 +1,113 @@
+package org.jnode.driver.console.textscreen;
+
+public enum KeyboardReaderAction {
+
+ /**
+ * This action causes the event's character (or in some circumstances its
+ * VK code) to be inserted into to the input buffer at the position of the
+ * cursor. The cursor is then advanced to after the inserted character.
+ */
+ KR_INSERT,
+
+ /**
+ * This action causes the event to be consumed with no other action.
+ */
+ KR_CONSUME,
+
+ /**
+ * This action causes the event to be ignored without consuming it.
+ * (This action may go away.)
+ */
+ KR_IGNORE,
+
+ /**
+ * This action causes the input buffer to be terminated with
+ * a '\n' and send to the input stream for reading.
+ */
+ KR_ENTER,
+
+ /**
+ * This action causes the input buffer to be cleared. All characters
+ * are removed and the input cursor is set to the start of the buffer.
+ */
+ KR_KILL_LINE,
+
+ /**
+ * This action causes the input completion to be performed.
+ */
+ KR_COMPLETE,
+
+ /**
+ * This action causes the input line to be refreshed to the
+ * console.
+ */
+ KR_REDRAW,
+
+ /**
+ * This action denotes a 'soft eof' marker.
+ */
+ KR_SOFT_EOF,
+
+ /**
+ * This action causes the input cursor to be moved one
+ * character to the left. If the cursor is already at the start of the
+ * input buffer, it is not moved. No characters are added or removed.
+ */
+ KR_CURSOR_LEFT,
+
+ /**
+ * This action causes the input cursor to be moved one
+ * character to the right. If the cursor is already at the end of the
+ * input buffer, it is not moved. No characters are added or removed.
+ */
+ KR_CURSOR_RIGHT,
+
+ /**
+ * This action causes the input cursor to be moved to the before the
+ * first character in the input buffer. No characters are added or removed.
+ */
+ KR_CURSOR_TO_START,
+
+ /**
+ * This action causes the input buffer cursor to be moved to after the
+ * last character in the input buffer. No characters are added or removed.
+ */
+ KR_CURSOR_TO_END,
+
+ /**
+ * This action causes one character to the left of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_BEFORE,
+
+ /**
+ * This action causes one character to the right of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_AFTER,
+
+ /**
+ * This action causes all characters to the right of the input cursor to be
+ * deleted from the input buffer.
+ */
+ KR_DELETE_TO_END,
+
+ /**
+ * This action causes the previous history line to be selected.
+ */
+ KR_HISTORY_UP,
+
+ /**
+ * This action causes the next history line to be selected.
+ */
+ KR_HISTORY_DOWN;
+
+
+ public static KeyboardReaderAction getDefaultCharAction() {
+ return KR_INSERT;
+ }
+
+ public static KeyboardReaderAction getDefaultVKAction() {
+ return KR_IGNORE;
+ }
+}
\ No newline at end of file
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.SortedSet;
+
import org.jnode.driver.console.CompletionInfo;
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.ScrollableTextConsole;
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -341,7 +341,7 @@
}
@Override
- public KeyEventBindings getKeyEventBindings() {
+ public ConsoleKeyEventBindings getKeyEventBindings() {
if (in instanceof KeyboardReader) {
return ((KeyboardReader) in).getKeyEventBindings();
} else {
@@ -350,7 +350,7 @@
}
@Override
- public void setKeyEventBindings(KeyEventBindings bindings) {
+ public void setKeyEventBindings(ConsoleKeyEventBindings bindings) {
if (in instanceof KeyboardReader) {
((KeyboardReader) in).setKeyEventBindings(bindings);
} else {
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsolePlugin.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -22,7 +22,9 @@
package org.jnode.driver.console.textscreen;
import java.io.PrintStream;
+
import javax.naming.NamingException;
+
import org.jnode.driver.console.ConsoleException;
import org.jnode.driver.console.ConsoleManager;
import org.jnode.driver.console.TextConsole;
Modified: trunk/shell/descriptors/org.jnode.shell.command.xml
===================================================================
--- trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-08 21:38:55 UTC (rev 4617)
+++ trunk/shell/descriptors/org.jnode.shell.command.xml 2008-10-10 13:01:27 UTC (rev 4618)
@@ -19,6 +19,7 @@
<extension point="org.jnode.shell.aliases">
<alias name="alias" class="org.jnode.shell.command.AliasCommand"/>
+ <alias name="bindkeys" class="org.jnode.shell.command.BindKeysCommand"/>
<alias name="class" class="org.jnode.shell.command.ClassCommand"/>
<alias name="classpath" class="org.jnode.shell.command.ClasspathCommand" internal="yes"/>
<alias name="compile" class="org.jnode.shell.command.CompileCommand"/>
@@ -54,6 +55,8 @@
<argument argLabel="className"/>
</sequence>
</syntax>
+ <syntax alias="bindkeys" description="Show the key bindings">
+ </syntax>
<syntax alias="class" description="Show details of a Java class">
<argument argLabel="className"/>
</syntax>
Added: trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/command/BindKeysCommand.java 2008-10-10 13:01:27 UTC (rev 4618)
@@ -0,0 +1,176 @@
+/*
+ * $Id: AliasCommand.java 4198 2008-06-05 10:54:46Z crawley $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+ package org.jnode.shell.command;
+
+import static java.awt.event.KeyEvent.*;
+
+import java.awt.event.KeyEvent;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jnode.driver.console.Console;
+import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.VirtualKey;
+import org.jnode.driver.console.textscreen.ConsoleKeyEventBindings;
+import org.jnode.driver.console.textscreen.KeyboardReaderAction;
+import org.jnode.shell.AbstractCommand;
+import org.jnode.shell.ShellUtils;
+
+/**
+ * This command allows the user to examine and change JNode's key bindings.
+ *
+ * @author cr...@jn...
+ */
+public class BindKeysCommand extends AbstractCommand {
+ private PrintWriter out;
+ private PrintWriter err;
+
+ public BindKeysCommand() {
+ super("display or change the keyboard bindings");
+ }
+
+ @Override
+ public void execute() throws Exception {
+ out = getOutput().getPrintWriter();
+ err = getError().getPrintWriter();
+ Console console = ShellUtils.getCurrentShell().getConsole();
+ if (!(console instanceof TextConsole)) {
+ err.println("The current console is not a TextConsole");
+ }
+ TextConsole textConsole = (TextConsole) console;
+ displayBindings(textConsole);
+ }
+
+ private void displayBindings(TextConsole console) {
+ ConsoleKeyEventBindings bindings = console.getKeyEventBindings();
+
+ // Build a map from actions to the characters that map to them.
+ char[] boundChars = bindings.getBoundChars();
+ Map<KeyboardReaderAction, List<Character>> charMap =
+ new HashMap<KeyboardReaderAction, List<Character>>();
+ for (char ch : boundChars) {
+ KeyboardReaderAction action = bindings.getCharAction(ch);
+ List<Character> list = charMap.get(action);
+ if (list == null) {
+ list = new ArrayList<Character>();
+ charMap.put(action, list);
+ }
+ list.add(ch);
+ }
+
+ // Build a map from actions to the virtual keys that map to them.
+ VirtualKey[] boundKeys = bindings.getBoundVKs();
+ Map<KeyboardReaderAction, List<VirtualKey>> vkMap =
+ new HashMap<KeyboardReaderAction, List<VirtualKey>>();
+ for (VirtualKey vk : boundKeys) {
+ KeyboardReaderAction action = bindings.getVKAction(vk);
+ List<VirtualKey> list = vkMap.get(action);
+ if (list == null) {
+ list = new ArrayList<VirtualKey>();
+ vkMap.put(action, list);
+ }
+ list.add(vk);
+ }
+
+ for (KeyboardReaderAction action : KeyboardReaderAction.values()) {
+ List<Character> chars = charMap.get(action);
+ List<VirtualKey> vks = vkMap.get(action);
+ if (chars == null && vks == null &&
+ (action == KeyboardReaderAction.getDefaultCharAction() ||
+ action == KeyboardReaderAction.getDefaultVKAction())) {
+ continue;
+ }
+ StringBuilder sb = new StringBuilder(40);
+ sb.append(describe(action)).append(" : ");
+ if (chars == null && vks == null) {
+ sb.append("not bound");
+ } else {
+ boolean first = true;
+ if (chars != null) {
+ for (char ch : chars) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(describe(ch));
+ }
+ }
+ if (vks != null) {
+ for (VirtualKey vk : vks) {
+ if (first) {
+ first = false;
+ } else {
+ sb.append(", ");
+ }
+ sb.append(describe(vk));
+ }
+ }
+ }
+ out.println(sb);
+
+ }
+ }
+
+ private String describe(KeyboardReaderAction action) {
+ return action.toString();
+ }
+
+ private KeyboardReaderAction getAction(String name) {
+ return KeyboardReaderAction.valueOf(name);
+ }
+
+ private static final String[] ASCII_NAMES = new String[] {
+ "NUL", "SOH", "STC", "ETX", "EOT", "ENQ", "ACK", "BEL",
+ "BS", "HT", "NL", "VT", "FF", "CR", "SO", "SI",
+ "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
+ "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
+ };
+
+ private String describe(char ch) {
+ StringBuilder sb = new StringBuilder();
+ if (ch < 0x1f) {
+ sb.append("CTRL-" + (char)(ch + 0x40));
+ sb.append(" (").append(ASCII_NAMES[ch]).append(")");
+ } else if (ch == ' ') {
+ sb.append("SPACE");
+ } else if (ch == '\177') {
+ sb.append("DEL");
+ } else if (ch < '\177') {
+ sb.append(ch);
+ } else {
+ sb.append(ch).append("(0x" + Integer.toHexString(ch)).append(')');
+ }
+ return sb.toString();
+ }
+
+ private String describe(VirtualKey vk) {
+ if (vk.getModifiers() != 0) {
+ return (KeyEvent.getKeyModifiersText(vk.getModifiers()) + " " +
+ KeyEvent.getKeyText(vk.getVKCode()));
+ } else {
+ return KeyEvent.getKeyText(vk.getVKCode());
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|