public synchronized void documentChanged(DocumentEvent event) {
      if (!enabled) return;

      String text = event.getText();

      if (text.equals(COMMAND_TERMINATOR)) {
        if (buffer.length() > 0) { // If we just get a new-line token, execute the current 'thing'.
          buffer.append(COMMAND_TERMINATOR);
          String command = buffer.toString();
          reset();

          console.revertAndAppend(command);
        } else { // If there is no current 'thing', just execute the command terminator ('\n', '\r'
                 // or '\r\n') command.
          queue(COMMAND_TERMINATOR, console.getInputOffset());
          execute();
        }
        return;
      }

      int offset = event.getOffset();
      int length = event.getLength();

      int start = offset - console.getInputOffset();
      if (start >= 0) {
        buffer.replace(start, start + length, text);

        int commandStartOffset = console.getInputOffset();

        String rest = buffer.toString();
        boolean commandsQueued = false;
        do {
          int index = rest.indexOf(COMMAND_TERMINATOR);
          if (index == -1) {
            reset();
            buffer.append(rest);
            break;
          }

          String command = rest.substring(0, index);

          queue(command, commandStartOffset);
          commandStartOffset += index;
          commandsQueued = true;

          rest = rest.substring(index + COMMAND_TERMINATOR.length());
        } while (true);

        if (commandsQueued) execute();
      } else {
        buffer.insert(0, text);
        String toAppend = buffer.toString();
        reset();
        console.revertAndAppend(toAppend);
      }
    }
    public synchronized void write(int arg) throws IOException {
      if (!enabled) {
        backup.write(arg);
        return;
      }

      if (arg == '\n'
          || arg == '\r') { // If we encounter a new-line, print the content of the buffer.
        return;
      }
      console.writeToConsole(new String(new byte[] {(byte) arg}), false);
    }
 public synchronized void write(byte[] bytes, int offset, int length) throws IOException {
   if (!enabled) {
     backup.write(bytes, offset, length);
     return;
   }
   if (length > 0) {
     try {
       console.writeToConsole(new String(bytes, offset, length, "UTF16"), false);
     } catch (UnsupportedEncodingException e) {
     }
   }
 }
    public void run() {
      running = true;
      while (running) {
        lock.block();

        if (!running) return;

        if (commandQueue.size() > 0) {
          console.disableEditing();
          console.consoleOutputStream.enable();

          boolean completeCommand = true;
          int completeCommandStartOffset = -1;

          do {
            Command command = commandQueue.remove(0);
            if (completeCommandStartOffset == -1)
              completeCommandStartOffset = command.commandStartOffset;
            try {
              Timing tm = new Timing();
              tm.start();
              completeCommand = console.interpreter.execute(command.command);
              long duration = tm.duration();

              if (completeCommand) {
                console.printOutput(console.interpreter.getOutput());
                if (PRINTCOMMANDTIME) {
                  console.printOutput("Time taken: " + duration + "ms.\n");
                }
                completeCommandStartOffset = -1; // Reset offset.
              } else {
                console.printOutput();
              }
            } catch (CommandExecutionException ceex) {
              console.printOutput(ceex.getMessage());
              int errorOffset = ceex.getOffset();
              int errorLength = ceex.getLength();
              if (errorOffset != -1 && errorLength != -1) {
                console.setError(completeCommandStartOffset + errorOffset, errorLength);
              }
              completeCommand = true;
            } catch (TerminationException tex) {
              // Roll over and die.
              console.terminate();
              return;
            }
          } while (commandQueue.size() > 0);

          if (!running) return;

          console.consoleOutputStream.disable();

          if (completeCommand) {
            console.emitPrompt();
          } else {
            console.emitContinuationPrompt();
          }

          console.enableEditing();
        }
      }
    }
 public void deregisterListener() {
   IDocument doc = console.getDocument();
   doc.removeDocumentListener(this);
 }
 public void registerListener() {
   IDocument doc = console.getDocument();
   doc.addDocumentListener(this);
 }
 public void run() {
   console.interrupt();
 }
 public void run() {
   console.printTrace();
 }
 public void run() {
   console.terminate();
 }