/** * Set the terminal emulator's window size and start terminal emulation. * * @param columns The number of columns in the terminal window. * @param rows The number of rows in the terminal window. */ public void initializeEmulator(int columns, int rows) { mTranscriptScreen = new TranscriptScreen(columns, TRANSCRIPT_ROWS, rows, mColorScheme); mEmulator = new TerminalEmulator(this, mTranscriptScreen, columns, rows, mColorScheme); mEmulator.setDefaultUTF8Mode(mDefaultUTF8Mode); mEmulator.setKeyListener(mKeyListener); mIsRunning = true; mReaderThread.start(); mWriterThread.start(); }
/** * Get whether the terminal emulator is currently in UTF-8 mode. * * @return Whether the emulator is currently in UTF-8 mode. */ public boolean getUTF8Mode() { if (mEmulator == null) { return mDefaultUTF8Mode; } else { return mEmulator.getUTF8Mode(); } }
/** * Set whether the terminal emulator should be in UTF-8 mode by default. * * <p>In UTF-8 mode, the terminal will handle UTF-8 sequences, allowing the display of text in * most of the world's languages, but applications must encode C1 control characters and graphics * drawing characters as the corresponding UTF-8 sequences. * * @param utf8ByDefault Whether the terminal emulator should be in UTF-8 mode by default. */ public void setDefaultUTF8Mode(boolean utf8ByDefault) { mDefaultUTF8Mode = utf8ByDefault; if (mEmulator == null) { return; } mEmulator.setDefaultUTF8Mode(utf8ByDefault); }
/** * Change the terminal's window size. Will call {@link #initializeEmulator} if the emulator is not * yet running. * * <p>You should override this method if your application needs to be notified when the screen * size changes (for example, if you need to issue <code>TIOCSWINSZ</code> to a tty to adjust the * window size). <em>If you do override this method, you must call through to the superclass * implementation.</em> * * @param columns The number of columns in the terminal window. * @param rows The number of rows in the terminal window. */ public void updateSize(int columns, int rows) { if (mEmulator == null) { initializeEmulator(columns, rows); } else { mEmulator.updateSize(columns, rows); } }
/** * Set the terminal emulator's color scheme (default colors). * * @param scheme The {@link ColorScheme} to be used (use null for the default scheme). */ public void setColorScheme(ColorScheme scheme) { if (scheme == null) { scheme = BaseTextRenderer.defaultColorScheme; } mColorScheme = scheme; if (mEmulator == null) { return; } mEmulator.setColorScheme(scheme); }
/** * Finish this terminal session. Frees resources used by the terminal emulator and closes the * attached <code>InputStream</code> and <code>OutputStream</code>. */ public void finish() { mIsRunning = false; mEmulator.finish(); if (mTranscriptScreen != null) { mTranscriptScreen.finish(); } // Stop the reader and writer threads, and close the I/O streams if (mWriterHandler != null) { mWriterHandler.sendEmptyMessage(FINISH); } try { mTermIn.close(); mTermOut.close(); } catch (IOException e) { // We don't care if this fails } catch (NullPointerException e) { } if (mFinishCallback != null) { mFinishCallback.onSessionFinish(this); } }
/** Reset the terminal emulator's state. */ public void reset() { mEmulator.reset(); notifyUpdate(); }
/** * Set an {@link UpdateCallback} to be invoked when the terminal emulator goes into or out of * UTF-8 mode. * * @param utf8ModeNotify The {@link UpdateCallback} to be invoked. */ public void setUTF8ModeUpdateCallback(UpdateCallback utf8ModeNotify) { if (mEmulator != null) { mEmulator.setUTF8ModeUpdateCallback(utf8ModeNotify); } }
/** * Write something directly to the terminal emulator input, bypassing the emulation client, the * session's {@link InputStream}, and any processing being done by {@link #processInput * processInput}. * * @param data The data to be written to the terminal. * @param offset The starting offset into the buffer of the data. * @param count The length of the data to be written. */ protected final void appendToEmulator(byte[] data, int offset, int count) { mEmulator.append(data, offset, count); }
/** * Process input and send it to the terminal emulator. This method is invoked on the main thread * whenever new data is read from the InputStream. * * <p>The default implementation sends the data straight to the terminal emulator without * modifying it in any way. Subclasses can override it to modify the data before giving it to the * terminal. * * @param data A byte array containing the data read. * @param offset The offset into the buffer where the read data begins. * @param count The number of bytes read. */ protected void processInput(byte[] data, int offset, int count) { mEmulator.append(data, offset, count); }