diff options
author | Jeff Sharkey <jsharkey@android.com> | 2013-02-19 23:10:46 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2013-02-19 23:11:58 -0800 |
commit | 410e0da343fd581f3112037deb475db9fb0da850 (patch) | |
tree | b5abeb9de4fb1818c26b2be19aa842e65576d789 /src/com/android/terminal/Terminal.java | |
parent | 5d4b3955da5952d8ec2cb45e3aa5406294560798 (diff) | |
download | Terminal-410e0da343fd581f3112037deb475db9fb0da850.tar.gz |
TerminalView to draw session contents.
View sets terminal dimensions to match screen, and handles any draw
requests for dirty regions. damage() calls from below are translated
into normal View invalidates.
For now makes separate getCell() calls for each cell while drawing
across screen. This currently costs about 130ms for a 38x59 shell.
Change-Id: I2d106a8aeb18e9d6993f30cfb02438e85ee63c65
Diffstat (limited to 'src/com/android/terminal/Terminal.java')
-rw-r--r-- | src/com/android/terminal/Terminal.java | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/src/com/android/terminal/Terminal.java b/src/com/android/terminal/Terminal.java index 9f3016b..8067b9a 100644 --- a/src/com/android/terminal/Terminal.java +++ b/src/com/android/terminal/Terminal.java @@ -16,30 +16,88 @@ package com.android.terminal; -public class Terminal { - private TerminalCallbacks mCallbacks; +import android.graphics.Color; +/** + * Single terminal session backed by a pseudo terminal on the local device. + */ +public class Terminal { static { System.loadLibrary("jni_terminal"); } + public static class Cell { + char[] chars = new char[2]; + int width = 1; + + boolean bold; + int underline; + boolean blink; + boolean reverse; + boolean strike; + int font; + + int fgColor = Color.RED; + int bgColor = Color.BLUE; + } + + public interface TerminalClient { + public void damage(int startRow, int endRow, int startCol, int endCol); + public void bell(); + } + private final int mNativePtr; + private TerminalClient mClient; + + private final TerminalCallbacks mCallbacks = new TerminalCallbacks() { + @Override + public int damage(int startRow, int endRow, int startCol, int endCol) { + if (mClient != null) { + mClient.damage(startRow, endRow, startCol, endCol); + } + return 1; + } + + @Override + public int bell() { + if (mClient != null) { + mClient.bell(); + } + return 1; + } + }; public Terminal() { - mCallbacks = new TerminalCallbacks() { - }; mNativePtr = nativeInit(mCallbacks, 25, 80); } + public void setClient(TerminalClient client) { + mClient = client; + } + public void resize(int rows, int cols) { - nativeResize(mNativePtr, rows, cols); + if (nativeResize(mNativePtr, rows, cols) != 0) { + throw new IllegalStateException("resize failed"); + } } public int getRows() { return nativeGetRows(mNativePtr); } + public int getCols() { + return nativeGetCols(mNativePtr); + } + + public void getCell(int row, int col, Cell cell) { + if (nativeGetCell(mNativePtr, row, col, cell) != 0) { + throw new IllegalStateException("getCell failed"); + } + } + private static native int nativeInit(TerminalCallbacks callbacks, int rows, int cols); private static native int nativeResize(int ptr, int rows, int cols); + private static native int nativeGetCell(int ptr, int row, int col, Cell cell); private static native int nativeGetRows(int ptr); + private static native int nativeGetCols(int ptr); } |