|
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.
|
|
From: <ls...@us...> - 2007-08-04 12:50:07
|
Revision: 3382
http://jnode.svn.sourceforge.net/jnode/?rev=3382&view=rev
Author: lsantha
Date: 2007-08-04 05:50:02 -0700 (Sat, 04 Aug 2007)
Log Message:
-----------
Fixed the DEL key.
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-04 11:27:53 UTC (rev 3381)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-04 12:50:02 UTC (rev 3382)
@@ -210,11 +210,6 @@
refreshCurrentLine();
}
break;
- // if its a delete we want to remove one under the cursor
- case KeyEvent.VK_DELETE:
- currentLine.delete();
- refreshCurrentLine();
- break;
// if its an enter key we want to process the command, and then resume
// the thread
case '\n':
@@ -319,6 +314,11 @@
currentLine.moveEnd();
refreshCurrentLine();
break;
+ // if its a delete we want to remove one under the cursor
+ case KeyEvent.VK_DELETE:
+ currentLine.delete();
+ refreshCurrentLine();
+ break;
default:
// ignore other virtual keys.
return false;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2008-06-20 02:14:28
|
Revision: 4270
http://jnode.svn.sourceforge.net/jnode/?rev=4270&view=rev
Author: fduminy
Date: 2008-06-19 19:14:27 -0700 (Thu, 19 Jun 2008)
Log Message:
-----------
optimizations of TextScreen(Console) operations (sync/copy/update)
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 2008-06-19 20:11:16 UTC (rev 4269)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2008-06-20 02:14:27 UTC (rev 4270)
@@ -4,21 +4,12 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
-import javax.naming.NameNotFoundException;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.Device;
-import org.jnode.driver.DeviceListener;
-import org.jnode.driver.DeviceManager;
+
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.TextConsole;
-import org.jnode.driver.input.KeyboardAPI;
import org.jnode.driver.input.KeyboardEvent;
-import org.jnode.driver.input.KeyboardListener;
-import org.jnode.naming.InitialNaming;
-import org.jnode.system.BootLog;
import org.jnode.system.event.FocusEvent;
import org.jnode.system.event.FocusListener;
-import org.jnode.util.Queue;
/**
@@ -35,21 +26,21 @@
* <li>a "raw" mode in which characters and other keyboard events are delivered without line editing,
* <li>a "no echo" mode in which line editting occurs without echoing of input characters,
* <li>making the active characters and keycodes "soft",
- * <li>making completion and history context sensitive; e.g. when switching between a shell and
+ * <li>making completion and history context sensitive; e.g. when switching between a shell and
* an application, and
* <li>code refactoring to support classical terminal devices and remote consoles.
* </ul>
* <p/>
* Bugs:
* <ul>
- * <li>The current method of echoing the input is suboptimal, and is broken in the case where an
+ * <li>The current method of echoing the input is suboptimal, and is broken in the case where an
* application outputs a prompt string to stdout or stderr.
* </ul>
- *
+ *
* @author cr...@jn...
*/
public class KeyboardInputStream extends InputStream
- implements KeyboardListener, FocusListener, DeviceListener {
+ implements FocusListener {
public static final byte CTRL_L = 12;
public static final byte CTRL_D = 4;
@@ -62,25 +53,16 @@
private static final char NO_CHAR = 0;
- private KeyboardAPI api;
- private DeviceManager devMan;
-
- /**
- * The queue of keyboard events
- */
- private final Queue<KeyboardEvent> queue = new Queue<KeyboardEvent>();
-
private final Line currentLine;
private final TextConsole console;
private InputCompleter completer;
private final PrintStream out;
- private boolean hasFocus;
private String currentPrompt;
/**
- * Contains an index to the current history line, counting from zero. The value
- * -1 denotes the current line.
+ * Contains an index to the current history line, counting from zero. The
+ * value -1 denotes the current line.
*/
private int historyIndex = -1;
@@ -89,33 +71,20 @@
*/
private String savedCurrentLine;
- public KeyboardInputStream(KeyboardAPI api, TextConsole console) {
- if (api != null) {
- this.api = api;
- this.api.addKeyboardListener(this);
- } else {
- try {
- this.devMan = InitialNaming.lookup(DeviceManager.NAME);
- this.devMan.addListener(this);
- } catch (NameNotFoundException ex) {
- BootLog.error("DeviceManager not found", ex);
- }
- }
+ private final KeyboardHandler keyboardHandler;
+ private final FocusListener focusListener;
+
+ public KeyboardInputStream(KeyboardHandler kbHandler, TextConsole console) {
+ this.keyboardHandler = kbHandler;
this.console = console;
this.out = new PrintStream(console.getOut());
this.currentLine = new Line(console);
this.pos = this.lim = 0;
- }
- private void registerKeyboardApi(Device device) {
- if (this.api == null) {
- try {
- this.api = device.getAPI(KeyboardAPI.class);
- this.api.addKeyboardListener(this);
- } catch (ApiNotFoundException ex) {
- BootLog.error("KeyboardAPI not found", ex);
- }
- this.devMan.removeListener(this);
+ if (keyboardHandler instanceof FocusListener) {
+ this.focusListener = (FocusListener) keyboardHandler;
+ } else {
+ this.focusListener = null;
}
}
@@ -139,37 +108,20 @@
}
/**
- * @see org.jnode.driver.input.KeyboardListener#keyPressed(org.jnode.driver.input.KeyboardEvent)
- */
- public void keyPressed(KeyboardEvent event) {
- if (hasFocus) {
- queue.add(event);
- }
- }
-
- /**
- * @see org.jnode.driver.input.KeyboardListener#keyReleased(org.jnode.driver.input.KeyboardEvent)
- */
- public void keyReleased(KeyboardEvent event) {
- }
-
- /**
* @see java.io.InputStream#close()
*/
public void close() throws IOException {
- if (api != null) {
- api.removeKeyboardListener(this);
- }
+ keyboardHandler.close();
super.close();
}
/**
* Pull a keyboard event from the queue and process it.
- *
+ *
* @return true if the event was processed
*/
private boolean processEvent() {
- KeyboardEvent event = queue.get();
+ KeyboardEvent event = keyboardHandler.getEvent();
if (!event.isConsumed()) {
char ch = event.getKeyChar();
if (ch != NO_CHAR) {
@@ -190,23 +142,25 @@
/**
* Process a keystroke interpretted as a character.
- *
+ *
* @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.
+ * @return <code>true</code> if the character should cause the current
+ * line buffer contents to be returned to the user.
*/
private boolean processChar(char ch) {
boolean breakChar = false;
switch (ch) {
- // if its a backspace we want to remove one from the end of our current
+ // if its a backspace we want to remove one from the end of our
+ // current
// line
case KeyEvent.VK_BACK_SPACE:
if (currentLine.backspace()) {
refreshCurrentLine();
}
break;
- // if its an enter key we want to process the command, and then resume
- // the thread
+ // if its an enter key we want to process the command, and then
+ // resume
+ // the thread
case '\n':
currentLine.moveEnd();
refreshCurrentLine();
@@ -215,7 +169,7 @@
breakChar = true;
historyIndex = -1;
break;
- // if it's the tab key, we want to trigger command line completion
+ // if it's the tab key, we want to trigger command line completion
case '\t':
if (completer != null) {
if (currentLine.complete()) {
@@ -225,8 +179,8 @@
refreshCurrentLine();
}
break;
- // interpret ^D as a soft EOF
- // FIXME - behavior correct? cf bash's treatment of ^D
+ // interpret ^D as a soft EOF
+ // FIXME - behavior correct? cf bash's treatment of ^D
case CTRL_D:
currentLine.moveEnd();
refreshCurrentLine();
@@ -234,8 +188,8 @@
eof = true;
breakChar = true;
break;
- // ^L means kill current line and redraw screen.
- // FIXME - is this behavior useful?
+ // ^L means kill current line and redraw screen.
+ // FIXME - is this behavior useful?
case CTRL_L:
this.console.clear();
this.console.setCursor(0, 0);
@@ -254,8 +208,8 @@
/**
* Process a keystroke that doesn't have an associated char value.
- *
- * @param code key code
+ *
+ * @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.
@@ -314,7 +268,7 @@
currentLine.moveEnd();
refreshCurrentLine();
break;
- // if its a delete we want to remove one under the cursor
+ // if its a delete we want to remove one under the cursor
case KeyEvent.VK_DELETE:
currentLine.delete();
refreshCurrentLine();
@@ -350,7 +304,8 @@
currentPrompt = sb.toString();
currentLine.start();
- while (processEvent()) { /* */ }
+ while (processEvent()) { /* */
+ }
buffer = currentLine.consumeBytes();
lim = buffer.length;
pos = 0;
@@ -422,26 +377,14 @@
}
public void focusGained(FocusEvent event) {
- hasFocus = true;
+ if (focusListener != null) {
+ focusListener.focusGained(event);
+ }
}
public void focusLost(FocusEvent event) {
- hasFocus = false;
- }
-
- /**
- * @see org.jnode.driver.DeviceListener#deviceStarted(org.jnode.driver.Device)
- */
- public void deviceStarted(Device device) {
- if (device.implementsAPI(KeyboardAPI.class)) {
- registerKeyboardApi(device);
+ if (focusListener != null) {
+ focusListener.focusLost(event);
}
}
-
- /**
- * @see org.jnode.driver.DeviceListener#deviceStop(org.jnode.driver.Device)
- */
- public void deviceStop(Device device) {
- /* Do nothing */
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|