Revision: 5606
          http://jnode.svn.sourceforge.net/jnode/?rev=5606&view=rev
Author:   crawley
Date:     2009-07-14 13:45:58 +0000 (Tue, 14 Jul 2009)

Log Message:
-----------
Improve command history support for multi-line commands.

Modified Paths:
--------------
    trunk/shell/src/shell/org/jnode/shell/CommandShell.java
    trunk/shell/src/shell/org/jnode/shell/CommandShellReader.java

Modified: trunk/shell/src/shell/org/jnode/shell/CommandShell.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShell.java     2009-07-12 
20:10:54 UTC (rev 5605)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShell.java     2009-07-14 
13:45:58 UTC (rev 5606)
@@ -322,7 +322,7 @@
                 if (e.startsWith(COMMAND_KEY)) {
                     final String cmd = e.substring(COMMAND_KEY.length());
                     outPW.println(prompt() + cmd);
-                    runCommand(cmd, false, this.interpreter);
+                    runCommand(cmd);
                 }
             } catch (Throwable ex) {
                 errPW.println("Error while processing bootarg commands: "
@@ -373,13 +373,24 @@
 
         while (!isExited() && !VmSystem.isShuttingDown()) {
             String input = null;
+            CommandShellReader reader = null;
             try {
                 clearEof();
                 outPW.print(prompt());
                 readingCommand = true;
                 input = readInputLine();
                 if (input.length() > 0) {
-                    runCommand(input, true, this.interpreter);
+                    try {
+                        clearEof();
+                        readingCommand = false;
+                        // Each interactive command is launched with a fresh 
history
+                        // for input completion
+                        applicationHistory.set(new InputHistory());
+                        reader = new CommandShellReader(input, interpreter, 
outPW, in);
+                        interpreter.interpret(this, reader, false, null, null);
+                    } finally {
+                        applicationHistory.set(null);
+                    }
                 }
             } catch (ShellException ex) {
                 diagnose(ex, null);
@@ -393,10 +404,8 @@
                         + ex.getMessage());
                 stackTrace(ex);
             } finally {
-                // FIXME ...
-                if (input != null && input.trim().length() > 0) {
-                    String lines[] = input.split("\\n");
-                    for (String line : lines) {
+                if (reader != null) {
+                    for (String line : reader.getLines()) {
                         addToCommandHistory(line);
                     }
                 }
@@ -530,26 +539,6 @@
             ((KeyboardReader) in).clearSoftEOF();
         }
     }
-        
-    private int runCommand(String command, boolean interactive, 
CommandInterpreter interpreter) 
-        throws ShellException {
-        try {
-            if (interactive) {
-                clearEof();
-                readingCommand = false;
-                // Each interactive command is launched with a fresh history
-                // for input completion
-                applicationHistory.set(new InputHistory());
-            }
-            Reader reader = interactive ? new CommandShellReader(command, 
interpreter, outPW, in) :
-                new StringReader(command);
-            return interpreter.interpret(this, reader, !interactive, null, 
null);
-        } finally {
-            if (interactive) {
-                applicationHistory.set(null);
-            }
-        }
-    }
 
     /**
      * Parse and run a command line using the CommandShell's current
@@ -559,7 +548,7 @@
      * @throws ShellException
      */
     public int runCommand(String command) throws ShellException {
-        return runCommand(command, false, this.interpreter);
+        return interpreter.interpret(this, new StringReader(command), true, 
null, null);
     }
 
     /**

Modified: trunk/shell/src/shell/org/jnode/shell/CommandShellReader.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/CommandShellReader.java       
2009-07-12 20:10:54 UTC (rev 5605)
+++ trunk/shell/src/shell/org/jnode/shell/CommandShellReader.java       
2009-07-14 13:45:58 UTC (rev 5606)
@@ -24,6 +24,8 @@
 import java.io.Reader;
 import java.io.StringReader;
 import java.nio.CharBuffer;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * This Reader class handles CommandShell line buffering in interactive mode.
@@ -36,10 +38,13 @@
     private final Reader in;
     private final PrintWriter out;
     private final MultilineInterpreter interpreter;
+    private final List<String> lines = new ArrayList<String>(1);
 
     public CommandShellReader(String command, CommandInterpreter interpreter, 
PrintWriter out, Reader in) {
         this.interpreter = (interpreter instanceof MultilineInterpreter) ?
                 (MultilineInterpreter) interpreter : null;
+
+        this.lines.add(command);
         if (interpreter != null) {
             command += "\n";
         }
@@ -67,6 +72,7 @@
                     sb.append((char) ch);
                 }
             }
+            this.lines.add(sb.toString());
             sb.append('\n');
             reader = new StringReader(sb.toString());
             return true;
@@ -148,5 +154,9 @@
     public long skip(long n) throws IOException {
         throw new UnsupportedOperationException("skip is not supported");
     }
+
+    public List<String> getLines() {
+        return lines;
+    }
     
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to