예제 #1
0
  /**
   * Read a character from the console.
   *
   * @return the character, or -1 if an EOF is received.
   */
  public final int readVirtualKey() throws IOException {
    int c = terminal.readVirtualKey(in);

    if (debugger != null) {
      debug("keystroke: " + c + "");
    }

    // clear any echo characters
    clearEcho(c);

    return c;
  }
예제 #2
0
  /** Reads the console input and returns an array of the form [raw, key binding]. */
  private int[] readBinding() throws IOException {
    int c = readVirtualKey();

    if (c == -1) {
      return null;
    }

    // extract the appropriate key binding
    short code = keybindings[c];

    if (debugger != null) {
      debug("    translated: " + (int) c + ": " + code);
    }

    return new int[] {c, code};
  }
예제 #3
0
  /**
   * Paste the contents of the clipboard into the console buffer
   *
   * @return true if clipboard contents pasted
   */
  public boolean paste() throws IOException {
    Clipboard clipboard;
    try { // May throw ugly exception on system without X
      clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    } catch (Exception e) {
      return false;
    }

    if (clipboard == null) {
      return false;
    }

    Transferable transferable = clipboard.getContents(null);

    if (transferable == null) {
      return false;
    }

    try {
      Object content = transferable.getTransferData(DataFlavor.plainTextFlavor);

      /*
       * This fix was suggested in bug #1060649 at
       * http://sourceforge.net/tracker/index.php?func=detail&aid=1060649&group_id=64033&atid=506056
       * to get around the deprecated DataFlavor.plainTextFlavor, but it
       * raises a UnsupportedFlavorException on Mac OS X
       */
      if (content == null) {
        try {
          content = new DataFlavor().getReaderForText(transferable);
        } catch (Exception e) {
        }
      }

      if (content == null) {
        return false;
      }

      String value;

      if (content instanceof Reader) {
        // TODO: we might want instead connect to the input stream
        // so we can interpret individual lines
        value = "";

        String line = null;

        for (BufferedReader read = new BufferedReader((Reader) content);
            (line = read.readLine()) != null; ) {
          if (value.length() > 0) {
            value += "\n";
          }

          value += line;
        }
      } else {
        value = content.toString();
      }

      if (value == null) {
        return true;
      }

      putString(value);

      return true;
    } catch (UnsupportedFlavorException ufe) {
      if (debugger != null) debug(ufe + "");

      return false;
    }
  }