During the modularization for by the multisession patches, the lazy
initialization which used to ensure that the transcript wasn't allocated
until its final size was known was lost. This results in the transcript
always being allocated at least twice for a newly created session
(unless the final width of the window is exactly 80 columns).
To prevent this, delay allocation of the transcript in TermSession
until after the size is set with a call to updateSize(). This requires
some changes in the EmulatorView's initialization code to ensure that
the TranscriptScreen and TerminalEmulator objects aren't used before
they're allocated.
Signed-off-by: Jack Palevich <jackpal@google.com>
/**
* Text size. Zero means 4 x 8 font.
*/
/**
* Text size. Zero means 4 x 8 font.
*/
+ private int mTextSize = 10;
private int mCursorStyle;
private int mCursorBlink;
private int mCursorStyle;
private int mCursorBlink;
/**
* Foreground color.
*/
/**
* Foreground color.
*/
- private int mForeground;
+ private int mForeground = TermSettings.WHITE;
private int mForegroundIndex;
/**
* Background color.
*/
private int mForegroundIndex;
/**
* Background color.
*/
- private int mBackground;
+ private int mBackground = TermSettings.BLACK;
private int mBackgroundIndex;
/**
private int mBackgroundIndex;
/**
setFocusable(true);
setFocusableInTouchMode(true);
setFocusable(true);
setFocusableInTouchMode(true);
- initialize(session);
- session.setUpdateCallback(mUpdateNotify);
+ mTermSession = session;
// XXX We should really be able to fetch this from within TermSession
session.setProcessExitMessage(context.getString(R.string.process_exit_message));
// XXX We should really be able to fetch this from within TermSession
session.setProcessExitMessage(context.getString(R.string.process_exit_message));
+
+ mKeyListener = new TermKeyListener(session);
}
public void setWindowSizeCallback(WindowSizeCallback callback) {
}
public void setWindowSizeCallback(WindowSizeCallback callback) {
/**
* Call this to initialize the view.
/**
* Call this to initialize the view.
- *
- * @param session The terminal session this view will be displaying
- private void initialize(TermSession session) {
- mTermSession = session;
- mTranscriptScreen = session.getTranscriptScreen();
- mEmulator = session.getEmulator();
+ private void initialize() {
+ TermSession session = mTermSession;
- mKeyListener = new TermKeyListener(session);
- mTextSize = 10;
- mForeground = TermSettings.WHITE;
- mBackground = TermSettings.BLACK;
+ mTranscriptScreen = session.getTranscriptScreen();
+ mEmulator = session.getEmulator();
+ session.setUpdateCallback(mUpdateNotify);
+
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (!mKnownSize) {
mKnownSize = true;
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
if (!mKnownSize) {
mKnownSize = true;
+ initialize();
+ } else {
+ updateSize(false);
}
private void updateSize(int w, int h) {
}
private void updateSize(int w, int h) {
requestLayout();
mRedoLayout = false;
}
requestLayout();
mRedoLayout = false;
}
+
+ if (mEmulator == null) {
+ // Not ready yet
+ return;
+ }
+
int w = getWidth();
int h = getHeight();
int w = getWidth();
int h = getHeight();
private FileDescriptor mTermFd;
private FileOutputStream mTermOut;
private FileInputStream mTermIn;
private FileDescriptor mTermFd;
private FileOutputStream mTermOut;
private FileInputStream mTermIn;
+ private String mInitialCommand;
+ private Thread mWatcherThread;
private TranscriptScreen mTranscriptScreen;
private TerminalEmulator mEmulator;
private TranscriptScreen mTranscriptScreen;
private TerminalEmulator mEmulator;
private String mProcessExitMessage;
private String mProcessExitMessage;
- private static final int DEFAULT_COLUMNS = 80;
- private static final int DEFAULT_ROWS = 24;
-
// Number of rows in the transcript
private static final int TRANSCRIPT_ROWS = 10000;
// Number of rows in the transcript
private static final int TRANSCRIPT_ROWS = 10000;
mProcId = processId[0];
mTermOut = new FileOutputStream(mTermFd);
mTermIn = new FileInputStream(mTermFd);
mProcId = processId[0];
mTermOut = new FileOutputStream(mTermFd);
mTermIn = new FileInputStream(mTermFd);
+ mInitialCommand = initialCommand;
- int[] colorScheme = settings.getColorScheme();
- mTranscriptScreen = new TranscriptScreen(DEFAULT_COLUMNS, TRANSCRIPT_ROWS, DEFAULT_ROWS, colorScheme[0], colorScheme[2]);
- mEmulator = new TerminalEmulator(settings, mTranscriptScreen, DEFAULT_COLUMNS, DEFAULT_ROWS, mTermOut);
-
- mIsRunning = true;
-
- Thread watcher = new Thread() {
+ mWatcherThread = new Thread() {
@Override
public void run() {
Log.i(TermDebug.LOG_TAG, "waiting for: " + mProcId);
@Override
public void run() {
Log.i(TermDebug.LOG_TAG, "waiting for: " + mProcId);
mMsgHandler.sendMessage(mMsgHandler.obtainMessage(PROCESS_EXITED, result));
}
};
mMsgHandler.sendMessage(mMsgHandler.obtainMessage(PROCESS_EXITED, result));
}
};
- watcher.setName("Process watcher");
- watcher.start();
+ mWatcherThread.setName("Process watcher");
mWriteCharBuffer = CharBuffer.allocate(2);
mWriteByteBuffer = ByteBuffer.allocate(4);
mWriteCharBuffer = CharBuffer.allocate(2);
mWriteByteBuffer = ByteBuffer.allocate(4);
}
};
mPollingThread.setName("Input reader");
}
};
mPollingThread.setName("Input reader");
+ }
+
+ private void initializeEmulator(int columns, int rows) {
+ TermSettings settings = mSettings;
+ int[] colorScheme = settings.getColorScheme();
+ mTranscriptScreen = new TranscriptScreen(columns, TRANSCRIPT_ROWS, rows, colorScheme[0], colorScheme[2]);
+ mEmulator = new TerminalEmulator(settings, mTranscriptScreen, columns, rows, mTermOut);
+
+ mIsRunning = true;
+ mWatcherThread.start();
- sendInitialCommand(initialCommand);
+ sendInitialCommand(mInitialCommand);
}
private void sendInitialCommand(String initialCommand) {
}
private void sendInitialCommand(String initialCommand) {
public void updateSize(int columns, int rows) {
// Inform the attached pty of our new size:
Exec.setPtyWindowSize(mTermFd, rows, columns, 0, 0);
public void updateSize(int columns, int rows) {
// Inform the attached pty of our new size:
Exec.setPtyWindowSize(mTermFd, rows, columns, 0, 0);
- mEmulator.updateSize(columns, rows);
+
+ if (mEmulator == null) {
+ initializeEmulator(columns, rows);
+ } else {
+ mEmulator.updateSize(columns, rows);
+ }
}
public String getTranscriptText() {
}
public String getTranscriptText() {
public void updatePrefs(TermSettings settings) {
mSettings = settings;
public void updatePrefs(TermSettings settings) {
mSettings = settings;
+ if (mEmulator == null) {
+ // Not initialized yet, we'll pick up the settings then
+ return;
+ }
+
mEmulator.updatePrefs(settings);
int[] colorScheme = settings.getColorScheme();
mEmulator.updatePrefs(settings);
int[] colorScheme = settings.getColorScheme();