|
From: <ls...@us...> - 2007-03-08 21:07:32
|
Revision: 3135
http://jnode.svn.sourceforge.net/jnode/?rev=3135&view=rev
Author: lsantha
Date: 2007-03-08 13:07:31 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
Added suupport for console stacking.
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java
trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java
trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java
Modified: trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134)
+++ trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135)
@@ -22,6 +22,7 @@
package org.jnode.driver.console;
import java.util.Set;
+import java.io.PrintStream;
import org.jnode.driver.input.KeyboardListener;
import org.jnode.driver.input.PointerListener;
@@ -101,18 +102,21 @@
public void setParent(ConsoleManager parent);
/**
- * Option constants for use in {@link #createConsole(String, int)}
+ * Option constants for use in {@link org.jnode.driver.console.ConsoleManager#createConsole(String, int)}
* @author Ewout Prangsma (ep...@us...)
*/
public static final class CreateOptions {
- /** Create a text console */
+ /** Create a text console. */
public static final int TEXT = 0x01;
- /** Create a scrollable console */
+ /** Create a scrollable console. */
public static final int SCROLLABLE = 0x02;
- /** Do not claim System.out, err, in when focused */
+ /** Do not claim System.out, err, in when focused. */
public static final int NO_SYSTEM_OUT_ERR_IN = 0x04;
+
+ /** Stack console on the current screen */
+ public static final int STACKED = 0x08;
}
/**
@@ -122,4 +126,6 @@
* @return
*/
public Console createConsole(String name, int options);
+
+ public void printConsoles(PrintStream ps);
}
Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java 2007-02-27 15:39:33 UTC (rev 3134)
+++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java 2007-03-08 21:07:31 UTC (rev 3135)
@@ -256,6 +256,8 @@
public void setAcceleratorKeyCode(int keyCode) {
this.acceleratorKeyCode = keyCode;
+ if(mgr instanceof AbstractConsoleManager)
+ ((AbstractConsoleManager)mgr).restack(this);
}
public int getAcceleratorKeyCode() {
Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134)
+++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135)
@@ -22,14 +22,9 @@
package org.jnode.driver.console.spi;
import java.awt.event.InputEvent;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
+import java.awt.event.KeyEvent;
+import java.util.*;
+import java.io.PrintStream;
import javax.naming.NameNotFoundException;
@@ -77,13 +72,16 @@
private AbstractConsoleManager parent;
+ private final Map<Integer, Stack<Console>> stackMap = new HashMap<Integer, Stack<Console>>();
+ private Stack<Console> currentStack;
+
/**
* Initialize a new instance
*/
public AbstractConsoleManager()
throws ConsoleException {
try {
- devMan = (DeviceManager) InitialNaming.lookup(DeviceManager.NAME);
+ devMan = InitialNaming.lookup(DeviceManager.NAME);
openInput(devMan);
} catch (NameNotFoundException ex) {
throw new ConsoleException("DeviceManager not found", ex);
@@ -93,7 +91,7 @@
protected final void initializeKeyboard(Device kbDev) {
try {
- this.kbApi = (KeyboardAPI) kbDev.getAPI(KeyboardAPI.class);
+ this.kbApi = kbDev.getAPI(KeyboardAPI.class);
this.kbApi.addKeyboardListener(this);
} catch (ApiNotFoundException ex) {
BootLog.error("KeyboardAPI not found", ex);
@@ -195,15 +193,54 @@
}
}
- public Console getConsoleByAccelerator(int keyCode) {
- for (Console console : consoles.values()) {
- if (console.getAcceleratorKeyCode() == keyCode) {
- return console;
+ public void printConsoles(PrintStream ps) {
+ ArrayList<Integer> list = new ArrayList<Integer>();
+ list.addAll(stackMap.keySet());
+ Collections.sort(list);
+ for(Integer key : list){
+ ps.println("Screen of " + KeyEvent.getKeyText(key) + ":");
+ Stack<Console> stack = stackMap.get(key);
+ int t_ind = stack.size();
+ for(int i = t_ind; i-- > 0;){
+ Console console = stack.get(i);
+ String prefix = console == current ? " > " :
+ i == t_ind - 1? " * " : " ";
+ ps.println(prefix + console.getConsoleName());
}
}
+ }
+
+ public Console getConsoleByAccelerator(int keyCode) {
+ Stack<Console> stack = stackMap.get(keyCode);
+ if(stack != null && !stack.empty()){
+ currentStack = stack;
+ return stack.peek();
+ }
+
return null;
}
+ protected void setAccelerator(Console console) {
+ for (int i = 0; i < 12; i++) {
+ final int keyCode = KeyEvent.VK_F1 + i;
+ Stack<Console> stack = stackMap.get(keyCode);
+ if (stack == null) {
+ stack = new Stack<Console>();
+ }
+
+ if (stack.empty()){
+ stackMap.put(keyCode, stack);
+ stack.push(console);
+ currentStack = stack;
+ return;
+ }
+ }
+ }
+
+ protected void stackConsole(Console console){
+ if(currentStack != null) currentStack.push(console);
+ }
+
/**
* Just keeping track of the One previous console will lead to lots of
* problems. We need a stack, at least. Currently it is the client's
@@ -219,13 +256,56 @@
if (current == console) {
console.focusLost(new FocusEvent(FocusEvent.FOCUS_LOST));
}
+
consoles.remove(console.getConsoleName());
+ if(currentStack != null && currentStack.peek() == console) {
+ currentStack.pop();
+ if(!currentStack.empty()) {
+ current = currentStack.peek();
+ focus(current);
+ } else {
+ Integer last_key = null;
+ for(Iterator<Map.Entry<Integer, Stack<Console>>> it = stackMap.entrySet().iterator(); it.hasNext(); ){
+ Map.Entry<Integer, Stack<Console>> entry = it.next();
+ if(entry.getValue().equals(currentStack)){
+ last_key = entry.getKey();
+ it.remove();
+ break;
+ }
+ }
+ if(!stackMap.isEmpty()){
+ Integer new_key = null;
+ List<Integer> keys = new ArrayList<Integer>(stackMap.keySet());
+ Collections.sort(keys);
+ if(last_key == null){
+ new_key = keys.get(0);
+ } else {
+ Collections.reverse(keys);
+ for(Integer k : keys){
+ if(k < last_key){
+ new_key = k;
+ break;
+ }
+ }
+ if(new_key == null){
+ new_key = keys.get(keys.size() - 1);
+ }
+ }
+
+ currentStack = stackMap.get(new_key);
+ current = currentStack.peek();
+ focus(current);
+ }
+ }
+ }
+
if (current == console) {
current = null;
if (!consoles.isEmpty()) {
- focus((Console)consoles.values().iterator().next());
+ focus(consoles.values().iterator().next());
}
}
+
if(parent != null && consoles.isEmpty()){
handleFocus();
}
@@ -320,6 +400,36 @@
this.parent = (AbstractConsoleManager) parent;
}
+ void restack(final AbstractConsole console){
+ int accel = console.getAcceleratorKeyCode();
+ if(accel == 0) return;
+
+ //remove console
+ for(Iterator<Integer> iter = stackMap.keySet().iterator(); iter.hasNext(); ){
+ Integer key = iter.next();
+ if(key == accel)
+ return; //no restack needed
+
+ Stack<Console> stack = stackMap.get(key);
+ if(stack.contains(console)){
+ stack.remove(console);
+
+ if(stack.empty())
+ iter.remove();
+
+ break;
+ }
+ }
+
+ //add the console to the specified screen
+ Stack<Console> stack = stackMap.get(accel);
+ if(stack == null){
+ stack = new Stack<Console>();
+ stackMap.put(accel, stack);
+ }
+ stack.push(console);
+ }
+
/**
* This listener looks for registration of a keyboard device.
*
@@ -349,5 +459,4 @@
}
}
}
-
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135)
@@ -68,8 +68,13 @@
final TextScreen screen;
screen = tsm.getSystemScreen().createCompatibleBufferScreen();
console = new TextScreenConsole(this, name, screen, options);
- }
- setAccelerator(console);
+ }
+ if ((options & CreateOptions.STACKED) != 0){
+ stackConsole(console);
+ } else {
+ setAccelerator(console);
+ }
+
registerConsole(console);
return console;
} else {
@@ -102,14 +107,16 @@
}
}
}
-
- private void setAccelerator(Console console) {
+
+ /*
+ protected void setAccelerator(Console console) {
for (int i = 0; i < 12; i++) {
final int keyCode = KeyEvent.VK_F1 + i;
if (getConsoleByAccelerator(keyCode) == null) {
console.setAcceleratorKeyCode(keyCode);
break;
}
- }
+ }
}
+ */
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-08-12 19:02:22
|
Revision: 3394
http://jnode.svn.sourceforge.net/jnode/?rev=3394&view=rev
Author: lsantha
Date: 2007-08-12 12:02:15 -0700 (Sun, 12 Aug 2007)
Log Message:
-----------
Console improvements by crawley
Modified Paths:
--------------
trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
Added Paths:
-----------
trunk/core/src/driver/org/jnode/driver/console/spi/ConsolePrintStream.java
Added: trunk/core/src/driver/org/jnode/driver/console/spi/ConsolePrintStream.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/spi/ConsolePrintStream.java (rev 0)
+++ trunk/core/src/driver/org/jnode/driver/console/spi/ConsolePrintStream.java 2007-08-12 19:02:15 UTC (rev 3394)
@@ -0,0 +1,17 @@
+package org.jnode.driver.console.spi;
+
+import java.io.PrintStream;
+
+public class ConsolePrintStream extends PrintStream {
+ public ConsolePrintStream(ConsoleOutputStream out) {
+ super(out);
+ }
+
+ public int getFgColor() {
+ return ((ConsoleOutputStream) out).getFgColor();
+ }
+
+ public void setFgColor(int color) {
+ ((ConsoleOutputStream) out).setFgColor(color);
+ }
+}
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-11 20:33:38 UTC (rev 3393)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/KeyboardInputStream.java 2007-08-12 19:02:15 UTC (rev 3394)
@@ -223,13 +223,15 @@
// if it's the tab key, we want to trigger command line completion
case '\t':
if (completer != null) {
- CompletionInfo completion = currentLine.complete(currentPrompt);
+ CompletionInfo completion = currentLine.complete();
if (completion.needNewPrompt()) {
currentLine.start(true);
}
refreshCurrentLine();
}
break;
+ // interpret ^D as a soft EOF
+ // FIXME - behavior correct? cf bash's treatment of ^D
case CTRL_D:
currentLine.moveEnd();
refreshCurrentLine();
@@ -237,6 +239,8 @@
eof = true;
breakChar = true;
break;
+ // ^L means kill current line and redraw screen.
+ // FIXME - is this behavior useful?
case CTRL_L:
this.console.clear();
this.console.setCursor(0, 0);
@@ -337,7 +341,7 @@
}
private void refreshCurrentLine() {
- currentLine.refreshCurrentLine(currentPrompt);
+ currentLine.refreshCurrentLine();
}
private boolean fillBuffer() throws IOException {
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-11 20:33:38 UTC (rev 3393)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/Line.java 2007-08-12 19:02:15 UTC (rev 3394)
@@ -22,12 +22,16 @@
package org.jnode.driver.console.textscreen;
import java.io.PrintStream;
+import java.util.Arrays;
import org.jnode.driver.console.CompletionInfo;
import org.jnode.driver.console.InputCompleter;
import org.jnode.driver.console.TextConsole;
+import org.jnode.driver.console.spi.ConsolePrintStream;
+import com.sun.tools.javac.code.Attribute.Array;
+
/**
* A class that handles the content of the current command line in the shell.
* That can be : - a new command that the user is beeing editing - an existing
@@ -61,14 +65,14 @@
private int oldLength = 0;
private int maxLength = 0;
-
+
private final TextConsole console;
- private PrintStream out;
+ private ConsolePrintStream out;
public Line(TextConsole console) {
this.console = console;
- this.out = console.getOut();
+ this.out = (ConsolePrintStream) console.getOut();
}
public void start() {
@@ -157,20 +161,20 @@
}
}
- public CompletionInfo complete(String currentPrompt) {
+ public CompletionInfo complete() {
CompletionInfo info = null;
InputCompleter completer = console.getCompleter();
if (posOnCurrentLine != currentLine.length()) {
String ending = currentLine.substring(posOnCurrentLine);
info = completer.complete(currentLine.substring(0, posOnCurrentLine));
- printList(info, currentPrompt);
+ printList(info);
if (info.getCompleted() != null) {
setContent(info.getCompleted() + ending);
posOnCurrentLine = currentLine.length() - ending.length();
}
} else {
info = completer.complete(currentLine.toString());
- printList(info, currentPrompt);
+ printList(info);
if (info.getCompleted() != null) {
setContent(info.getCompleted());
posOnCurrentLine = currentLine.length();
@@ -180,11 +184,11 @@
return info;
}
- protected void printList(CompletionInfo info, String currentPrompt) {
+ protected void printList(CompletionInfo info) {
if ((info != null) && info.hasItems()) {
int oldPosOnCurrentLine = posOnCurrentLine;
moveEnd();
- refreshCurrentLine(currentPrompt);
+ refreshCurrentLine();
out.println();
String[] list = info.getItems();
@@ -283,7 +287,19 @@
oldLength = 0;
}
- public void refreshCurrentLine(String currentPrompt) {
+ private volatile char[] mySpaces;
+
+ private char[] getSpaces(int count) {
+ char[] res = mySpaces;
+ if (res == null || res.length < count) {
+ res = new char[count];
+ Arrays.fill(res, ' ');
+ mySpaces = res;
+ }
+ return res;
+ }
+
+ public void refreshCurrentLine() {
try {
int x = consoleX;
int width = console.getWidth();
@@ -292,28 +308,48 @@
if (((x + maxLength) % width) != 0)
nbLines++;
- // if the line has not been shortened (delete, backspace...)
- if (!shortened)
- // scroll up the buffer if necessary, and get the new y
- console.ensureVisible(consoleY + nbLines - 1);
-
- for (int i = 0; i < nbLines; i++) {
- console.clearRow(consoleY + i);
+ // output the input line buffer contents with the screen cursor hidden
+ console.setCursorVisible(false);
+ console.setCursor(consoleX, consoleY);
+ out.print(currentLine);
+
+ // get position of end of line
+ // FIXME ... there's a problem here if some application simultaneously
+ // writes to console output.
+ int newConsoleX = console.getCursorX();
+ int newConsoleY = console.getCursorY();
+
+ // blank to the end of the screen region
+ if (newConsoleX > 0) {
+ int len = width - newConsoleX;
+ console.setChar(newConsoleX, newConsoleY, getSpaces(len),
+ 0, len, out.getFgColor());
+ newConsoleY++;
}
+ for (int i = newConsoleY; i < consoleY + nbLines; i++) {
+ console.clearRow(i);
+ }
- // print the input line
- console.setCursor(0, consoleY);
- out.print(currentPrompt + currentLine);
-
- int posCurX = x + posOnCurrentLine;
- int posCurY = consoleY;
- if (posCurX >= width) {
- posCurY += posCurX / width;
- posCurX = (posCurX % width);
+ // reset the screen cursor and reveal it
+ // FIXME ... there's a problem here if the input buffer contains
+ // characters that do not render as one screen character; e.g. \t or \n.
+ int inputCursorX = x + posOnCurrentLine;
+ int inputCursorY = consoleY;
+ if (inputCursorX >= width) {
+ inputCursorY += inputCursorX / width;
+ inputCursorX = (inputCursorX % width);
}
- console.setCursor(posCurX, posCurY);
+ console.setCursor(inputCursorX, inputCursorY);
+ console.setCursorVisible(true);
+
+ // if the line has not been shortened (delete, backspace...)
+ if (!shortened) {
+ // ensure that the location of the input cursor is included.
+ console.ensureVisible(inputCursorY);
+ }
} catch (Exception e) {
- //todo: why is it ignored?
+ // TODO - why ignore these exceptions? Are they due to the console methods
+ // not being thread-safe???
}
}
Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java
===================================================================
--- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-11 20:33:38 UTC (rev 3393)
+++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsole.java 2007-08-12 19:02:15 UTC (rev 3394)
@@ -31,6 +31,7 @@
import org.jnode.driver.console.TextConsole;
import org.jnode.driver.console.spi.AbstractConsole;
import org.jnode.driver.console.spi.ConsoleOutputStream;
+import org.jnode.driver.console.spi.ConsolePrintStream;
import org.jnode.driver.textscreen.TextScreen;
import org.jnode.system.event.FocusEvent;
import org.jnode.system.event.FocusListener;
@@ -62,11 +63,9 @@
private InputStream in;
- private final PrintStream out;
+ private final ConsolePrintStream out;
- private final PrintStream err;
-
- private InputStream savedIn;
+ private final ConsolePrintStream err;
private PrintStream savedOut;
@@ -89,9 +88,9 @@
this.screen = screen;
this.scrWidth = screen.getWidth();
this.scrHeight = screen.getHeight();
- this.savedOut = this.out = new PrintStream(new ConsoleOutputStream(
+ this.savedOut = this.out = new ConsolePrintStream(new ConsoleOutputStream(
this, 0x07));
- this.savedErr = this.err = new PrintStream(new ConsoleOutputStream(
+ this.savedErr = this.err = new ConsolePrintStream(new ConsoleOutputStream(
this, 0x04));
this.claimSystemOutErr = ((options & ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR) == 0);
this.myIsolate = VmIsolate.currentIsolate();
@@ -141,9 +140,11 @@
}
}
mark = i + 1;
- putChar(c, color);
+ doPutChar(c, color);
}
}
+ screen.ensureVisible(curY);
+ syncScreen();
}
/**
@@ -153,6 +154,12 @@
* @param color
*/
public void putChar(char v, int color) {
+ doPutChar(v, color);
+ screen.ensureVisible(curY);
+ syncScreen();
+ }
+
+ private void doPutChar(char v, int color) {
if (v == '\n') {
// Goto next line
// Clear till eol
@@ -185,9 +192,6 @@
curY--;
clearRow(curY);
}
- screen.ensureVisible(curY);
- syncScreen();
- //setCursor(curX, curY);
}
/**
@@ -315,7 +319,7 @@
}
void setIn(InputStream in) {
- this.savedIn = this.in = in;
+ this.in = in;
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|