[Mulgara-svn] r457 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql

pag at mulgara.org pag at mulgara.org
Wed Sep 26 05:14:48 UTC 2007


Author: pag
Date: 2007-09-26 00:14:48 -0500 (Wed, 26 Sep 2007)
New Revision: 457

Modified:
   branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java
Log:
Enabled simple processing of stdin to the UI

Modified: branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java
===================================================================
--- branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java	2007-09-26 04:51:33 UTC (rev 456)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/TqlSessionUI.java	2007-09-26 05:14:48 UTC (rev 457)
@@ -381,7 +381,6 @@
    * @return length of the current text buffer.
    */
   private int textLength() {
-
     return text.getDocument().getLength();
   }
 
@@ -393,7 +392,6 @@
    * @param end the end position.
    */
   private void replaceText(String newString, int start, int end) {
-
     text.select(start, end);
     text.replaceSelection(newString);
   }
@@ -402,22 +400,17 @@
    * When the enter key has been pressed process the current command.
    */
   private void enterPressed() {
-
     String command = getCommand();
 
     // Create null command.
     if (command.length() != 0) {
-
       // Put the command at the end of the array.
       history.add(command);
       command = command + NEWLINE;
 
       // If the array gets too large remove the last entry.
-      if (history.size() > 30) {
-
-        history.remove(0);
-      }
-
+      if (history.size() > 30) history.remove(0);
+      
       // Indicate that we are running a command.
       runningCommand = true;
 
@@ -425,7 +418,6 @@
       ExecutionThread execThread = new ExecutionThread("execThread", command);
       execThread.start();
     } else {
-
       // We've just hit enter so print the prompt.
       printPrompt();
     }
@@ -435,9 +427,7 @@
    * Prints out the prompt.
    */
   public void printPrompt() {
-
-    println();
-    print(ItqlSession.PROMPT);
+    print(NEWLINE + ItqlSession.PROMPT);
     historyIndex = 0;
     text.repaint();
   }
@@ -448,17 +438,12 @@
    * @return the current command.
    */
   private String getCommand() {
-
     String command = "";
     try {
-
       command = text.getText(cursorPosition, textLength() - cursorPosition);
     } catch (BadLocationException e) {
-
-      log.error("Failed to get text command at position: " + cursorPosition,
-          e);
+      log.error("Failed to get text command at position: " + cursorPosition, e);
     }
-
     return command;
   }
 
@@ -466,11 +451,8 @@
    * Display the next command in the history buffer.
    */
   private void historyUp() {
-
-    // Ensure there's a history and that the index never goes above the array
-    // size.
+    // Ensure there's a history and that the index never goes above the array size.
     if ((history.size() != 0) && (historyIndex != history.size())) {
-
       historyIndex++;
       displayHistoryLine();
     }
@@ -493,7 +475,6 @@
    * Displays the history line to the screen.
    */
   private void displayHistoryLine() {
-
     String showline = (String) history.get(history.size() - historyIndex);
     replaceText(showline, cursorPosition, textLength());
     text.setCaretPosition(textLength());
@@ -534,6 +515,21 @@
 
 
   /**
+   * Adds a text to the UI. Sends a little "closure" to the UI thread.
+   * @param message the message to display.
+   */
+  public void injectCommand(final String cmd) {
+    invokeAndWait(new Runnable() {
+      public void run() {
+        append(cmd);
+        text.setCaretPosition(cursorPosition);
+        if (cmd.endsWith(";") || cmd.endsWith("\n")) enterPressed();
+      }
+    });
+  }
+
+
+  /**
    * Print out an error message to the UI.
    * @param errorMessage the error message to display.
    */
@@ -628,7 +624,9 @@
       byte[] buffer = new byte[255];
       int read;
       log.info("Starting input reader");
-      while ((read = inPipe.read(buffer)) != -1) print(new String(buffer, 0, read));
+      while ((read = inPipe.read(buffer)) != -1) {
+        injectCommand(new String(buffer, 0, read));
+      }
     } catch (IOException e) {
       log.error("Error reading input", e);
     }




More information about the Mulgara-svn mailing list