diff options
author | Jack Palevich <jackpal@google.com> | 2012-09-22 21:23:14 -0700 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2012-09-22 22:36:11 -0700 |
commit | df74020c9deb33f8e0b687db035af8dc4f9d8dcc (patch) | |
tree | c532808dfd9b637ff8e815fa4fc391a7fc3fe7a3 | |
parent | c99140a22c1a3276b42980f61b1b1c760fb3a488 (diff) | |
download | AndroidTerm-df74020c9deb33f8e0b687db035af8dc4f9d8dcc.tar.gz |
Implement DECSCNM (reverse video).
6 files changed, 40 insertions, 7 deletions
diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/BaseTextRenderer.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/BaseTextRenderer.java index f1237a3..8e910a9 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/BaseTextRenderer.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/BaseTextRenderer.java @@ -17,6 +17,8 @@ package jackpal.androidterm.emulatorview; abstract class BaseTextRenderer implements TextRenderer { + protected boolean mReverseVideo; + protected int[] mPalette; protected static final int[] sXterm256Paint = { @@ -296,6 +298,10 @@ abstract class BaseTextRenderer implements TextRenderer { setDefaultColors(scheme.getForeColor(), scheme.getBackColor()); } + public void setReverseVideo(boolean reverseVideo) { + mReverseVideo = reverseVideo; + } + private void setDefaultColors(int forePaintColor, int backPaintColor) { mPalette = cloneDefaultColors(); mPalette[TextStyle.ciForeground] = forePaintColor; diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/Bitmap4x8FontRenderer.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/Bitmap4x8FontRenderer.java index 054700a..221eabd 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/Bitmap4x8FontRenderer.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/Bitmap4x8FontRenderer.java @@ -66,7 +66,8 @@ class Bitmap4x8FontRenderer extends BaseTextRenderer { int backColor = TextStyle.decodeBackColor(textStyle); int effect = TextStyle.decodeEffect(textStyle); - boolean inverse = (effect & (TextStyle.fxInverse | TextStyle.fxItalic)) != 0; + boolean inverse = mReverseVideo ^ + ((effect & (TextStyle.fxInverse | TextStyle.fxItalic)) != 0); if (inverse) { int temp = foreColor; foreColor = backColor; diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java index 0640f7c..388befd 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/EmulatorView.java @@ -117,6 +117,8 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe */ private Paint mCursorPaint; + private Paint mForegroundPaint; + private Paint mBackgroundPaint; private boolean mUseCookedIme; @@ -295,6 +297,7 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe mTextRenderer = null; mCursorPaint = new Paint(); mCursorPaint.setARGB(255,128,128,128); + mForegroundPaint = new Paint(); mBackgroundPaint = new Paint(); mTopRow = 0; mLeftColumn = 0; @@ -1074,6 +1077,8 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe else { mTextRenderer = new Bitmap4x8FontRenderer(getResources(), scheme); } + + mForegroundPaint.setColor(scheme.getForeColor()); mBackgroundPaint.setColor(scheme.getBackColor()); mCharacterWidth = mTextRenderer.getCharacterWidth(); mCharacterHeight = mTextRenderer.getCharacterHeight(); @@ -1153,7 +1158,12 @@ public class EmulatorView extends View implements GestureDetector.OnGestureListe int w = getWidth(); int h = getHeight(); - canvas.drawRect(0, 0, w, h, mBackgroundPaint); + boolean reverseVideo = mEmulator.getReverseVideo(); + mTextRenderer.setReverseVideo(reverseVideo); + + Paint backgroundPaint = + reverseVideo ? mForegroundPaint : mBackgroundPaint; + canvas.drawRect(0, 0, w, h, backgroundPaint); float x = -mLeftColumn * mCharacterWidth; float y = mCharacterHeight + mTopOfScreenMargin; int endLine = mTopRow + mRows; diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/PaintRenderer.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/PaintRenderer.java index 994ab86..1759efc 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/PaintRenderer.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/PaintRenderer.java @@ -43,7 +43,8 @@ class PaintRenderer extends BaseTextRenderer { int backColor = TextStyle.decodeBackColor(textStyle); int effect = TextStyle.decodeEffect(textStyle); - boolean inverse = (effect & (TextStyle.fxInverse | TextStyle.fxItalic)) != 0; + boolean inverse = mReverseVideo ^ + (effect & (TextStyle.fxInverse | TextStyle.fxItalic)) != 0; if (inverse) { int temp = foreColor; foreColor = backColor; diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java index a906046..30d7f5e 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TerminalEmulator.java @@ -179,6 +179,11 @@ class TerminalEmulator { private static final int K_132_COLUMN_MODE_MASK = 1 << 3; /** + * DECSCNM - set means reverse video (light background.) + */ + private static final int K_REVERSE_VIDEO_MASK = 1 << 5; + + /** * This mask indicates that origin mode is set. (Cursor addressing is * relative to the absolute screen size, rather than the currently set top * and bottom margins.) @@ -353,6 +358,10 @@ class TerminalEmulator { private CharsetDecoder mUTF8Decoder; private UpdateCallback mUTF8ModeNotify; + /** This is not accurate, but it makes the terminal more useful on + * small screens. + */ + private final static boolean DEFAULT_TO_AUTOWRAP_ENABLED = true; /** * Construct a terminal emulator that uses the supplied screen @@ -519,6 +528,10 @@ class TerminalEmulator { return mCursorCol; } + public final boolean getReverseVideo() { + return (mDecFlags & K_REVERSE_VIDEO_MASK) != 0; + } + public final boolean getKeypadApplicationMode() { return mbKeypadApplicationMode; } @@ -665,7 +678,7 @@ class TerminalEmulator { break; case ESC_LEFT_SQUARE_BRACKET_QUESTION_MARK: - doEscLSBQuest(b); + doEscLSBQuest(b); // CSI ? break; case ESC_PERCENT: @@ -1595,9 +1608,7 @@ class TerminalEmulator { } private boolean autoWrapEnabled() { - // Always enable auto wrap, because it's useful on a small screen - return true; - // return (mDecFlags & K_WRAPAROUND_MODE_MASK) != 0; + return (mDecFlags & K_WRAPAROUND_MODE_MASK) != 0; } /** @@ -1734,6 +1745,9 @@ class TerminalEmulator { mSavedCursorRow = 0; mSavedCursorCol = 0; mDecFlags = 0; + if (DEFAULT_TO_AUTOWRAP_ENABLED) { + mDecFlags |= K_WRAPAROUND_MODE_MASK; + } mSavedDecFlags = 0; mInsertMode = false; mAutomaticNewlineMode = false; diff --git a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TextRenderer.java b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TextRenderer.java index a484d15..07ee1b9 100644 --- a/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TextRenderer.java +++ b/libraries/emulatorview/src/jackpal/androidterm/emulatorview/TextRenderer.java @@ -23,6 +23,7 @@ import android.graphics.Canvas; */ interface TextRenderer { + void setReverseVideo(boolean reverseVideo); float getCharacterWidth(); int getCharacterHeight(); /** @return pixels above top row of text to avoid looking cramped. */ |