|
From: <ls...@us...> - 2007-08-02 19:30:49
|
Revision: 3375
http://jnode.svn.sourceforge.net/jnode/?rev=3375&view=rev
Author: lsantha
Date: 2007-08-02 12:30:46 -0700 (Thu, 02 Aug 2007)
Log Message:
-----------
Fixed broken command history.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-02 18:15:27 UTC (rev 3374)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-02 19:30:46 UTC (rev 3375)
@@ -85,13 +85,13 @@
* -1 denotes the current line.
*/
private int historyIndex = -1;
-
+
/**
* Contains the current line; i.e. the text being entered by the user.
*/
- private String newestLine = "";
+ private String savedCurrentLine;
- public KeyboardInputStream(KeyboardAPI api, TextConsole console) {
+ public KeyboardInputStream(KeyboardAPI api, TextConsole console) {
if (api != null) {
this.api = api;
this.api.addKeyboardListener(this);
@@ -171,6 +171,7 @@
/**
* Pull a keyboard event from the queue and process it.
+ * @return true if the event was processed
*/
private boolean processEvent() {
KeyboardEvent event = queue.get();
@@ -179,8 +180,7 @@
if (ch != NO_CHAR) {
event.consume();
return !processChar(ch);
- }
- else {
+ } else {
int kc = event.getKeyCode();
int mods = event.getModifiers();
if (processVirtualKeystroke(kc, mods)) {
@@ -188,8 +188,7 @@
}
return true;
}
- }
- else {
+ } else {
return true;
}
}
@@ -197,7 +196,7 @@
/**
* Process a keystroke interpretted as a character.
*
- * @param ch
+ * @param ch the character to process
* @return <code>true</code> if the character should cause the current line
* buffer contents to be returned to the user.
*/
@@ -224,6 +223,7 @@
out.println();
currentLine.appendChar(ch);
breakChar = true;
+ historyIndex = -1;
break;
// if it's the tab key, we want to trigger command line completion
case '\t':
@@ -253,14 +253,15 @@
// otherwise add it to our current line
currentLine.appendChar(ch);
refreshCurrentLine();
+ historyIndex = -1;
}
return breakChar;
}
/**
* Process a keystroke that doesn't have an associated char value.
- * @param code
- * @param modifiers
+ * @param code key code
+ * @param modifiers key modifiers
* @return <code>true</code> if the keystroke has been recognized and
* acted on, <code>false</code> otherwise.
*/
@@ -273,22 +274,27 @@
// Previous history item
if (completer != null) {
if (historyIndex == -1) {
- newestLine = currentLine.getContent();
historyIndex = completer.getCommandHistory().size();
- }
+ savedCurrentLine = currentLine.getContent();
+ }
historyIndex--;
- redisplay();
+
+ updateCurrentLine();
}
break;
case KeyEvent.VK_DOWN:
// Next history item
if (completer != null) {
- if (historyIndex == completer.getCommandHistory().size() - 1)
+ if (historyIndex == -1)
+ savedCurrentLine = currentLine.getContent();
+
+ if (historyIndex == completer.getCommandHistory().size() - 1)
historyIndex = -2;
- else if (historyIndex == -1)
- newestLine = currentLine.getContent();
+
historyIndex++;
- redisplay();
+
+ updateCurrentLine();
+
}
break;
case KeyEvent.VK_LEFT:
@@ -320,21 +326,20 @@
return true;
}
+ private void updateCurrentLine() {
+ if (historyIndex > -1) {
+ currentLine.setContent(completer.getCommandHistory().getCommand(historyIndex));
+ } else {
+ currentLine.setContent(savedCurrentLine);
+ }
+ refreshCurrentLine();
+ currentLine.moveEnd();
+ }
+
private void refreshCurrentLine() {
currentLine.refreshCurrentLine(currentPrompt);
}
- private void redisplay() {
- if (historyIndex == -1) {
- currentLine.setContent(newestLine);
- }
- else {
- currentLine.setContent(completer.getCommandHistory().getCommand(historyIndex));
- }
- refreshCurrentLine();
- currentLine.moveEnd();
- }
-
private boolean fillBuffer() throws IOException {
int x = console.getCursorX();
int y = console.getCursorY();
@@ -425,7 +430,6 @@
}
/**
- * @param device
* @see org.jnode.driver.DeviceListener#deviceStarted(org.jnode.driver.Device)
*/
public void deviceStarted(Device device) {
@@ -435,7 +439,6 @@
}
/**
- * @param device
* @see org.jnode.driver.DeviceListener#deviceStop(org.jnode.driver.Device)
*/
public void deviceStop(Device device) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|