@Override public void keyTyped(KeyEvent event) { // We handle most things we are interested in here. The InputMap filters out // most other unwanted actions (but allows copy/paste). char ch = event.getKeyChar(); if ((!isMacOs) && handleFontsizeKeys(event, ch)) { // Note: On Mac OS with Java 7+, we don't see command+= / command+- as a // key-typed event and so we handle it in keyReleased instead. return; } if ((event.getModifiers() & Event.META_MASK) != 0) { return; // return without consuming the event } if (isActive) { switch (ch) { case 4: // CTRL-D (unix/Mac EOF) case 26: // CTRL-Z (DOS/Windows EOF) buffer.signalEOF(); writeToTerminal("\n"); event.consume(); break; case '\b': // backspace if (buffer.backSpace()) { try { int length = text.getDocument().getLength(); text.replaceRange("", length - 1, length); } catch (Exception exc) { Debug.reportError("bad location " + exc); } } event.consume(); break; case '\r': // carriage return case '\n': // newline if (buffer.putChar('\n')) { writeToTerminal(String.valueOf(ch)); buffer.notifyReaders(); } event.consume(); break; default: if (ch >= 32) { if (buffer.putChar(ch)) { writeToTerminal(String.valueOf(ch)); } event.consume(); } break; } } }
/** Write some text to the terminal. */ private void writeToPane(boolean stdout, String s) { prepare(); if (!stdout) showErrorPane(); // The form-feed character should clear the screen. int n = s.lastIndexOf('\f'); if (n != -1) { clear(); s = s.substring(n + 1); } TermTextArea tta = stdout ? text : errorText; tta.append(s); tta.setCaretPosition(tta.getDocument().getLength()); }