Skip to content

Commit

Permalink
Merge pull request #1 from termux/master
Browse files Browse the repository at this point in the history
Hello
  • Loading branch information
S D Rausty authored Sep 10, 2017
2 parents adc43c4 + 1e83ea3 commit 62b08b3
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android:
components:
- platform-tools
- tools
- build-tools-25.0.2
- build-tools-26.0.0
- android-25
- extra-android-m2repository

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Termux app

* [Termux on Google Play Store](https://play.google.com/store/apps/details?id=com.termux)
* [Termux on F-Droid](https://f-droid.org/repository/browse/?fdid=com.termux)
* [Termux Wiki](https://wiki.termux.com/wiki/)
* [Termux Help](http://termux.com/help/)
* [Termux Google+ community](http://termux.com/community/)

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "26.0.0"

dependencies {
compile 'com.android.support:support-annotations:25.3.1'
Expand All @@ -14,8 +14,8 @@ android {
applicationId "com.termux"
minSdkVersion 21
targetSdkVersion 25
versionCode 48
versionName "0.48"
versionCode 53
versionName "0.53"
}

buildTypes {
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:extractNativeLibs="false"
android:extractNativeLibs="true"
android:allowBackup="true"
android:fullBackupContent="@xml/backupscheme"
android:icon="@mipmap/ic_launcher"
Expand Down Expand Up @@ -76,6 +76,18 @@
</intent-filter>
</activity>

<activity-alias
android:name=".HomeActivity"
android:targetActivity="com.termux.app.TermuxActivity">

<!-- Launch activity automatically on boot on Android Things devices -->
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.IOT_LAUNCHER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity-alias>

<provider
android:name=".filepicker.TermuxDocumentsProvider"
android:authorities="com.termux.documents"
Expand All @@ -99,6 +111,7 @@
android:grantUriPermissions="true"
android:name="com.termux.app.TermuxOpenReceiver$ContentProvider" />

<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
</application>

</manifest>
3 changes: 2 additions & 1 deletion app/src/main/java/com/termux/app/BackgroundJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public static String[] buildEnvironment(boolean failSafe, String cwd) {
final String langEnv = "LANG=en_US.UTF-8";
final String pathEnv = "PATH=" + TermuxService.PREFIX_PATH + "/bin:" + TermuxService.PREFIX_PATH + "/bin/applets";
final String pwdEnv = "PWD=" + cwd;
final String tmpdirEnv = "TMPDIR=" + TermuxService.PREFIX_PATH + "/tmp";

return new String[]{termEnv, homeEnv, prefixEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv};
return new String[]{termEnv, homeEnv, prefixEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv};
}
}

Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/termux/app/TermuxActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ public void onSessionFinished(final TerminalSession finishedSession) {
@Override
public void onClipboardText(TerminalSession session, String text) {
if (!mIsVisible) return;
showToast("Clipboard:\n\"" + text + "\"", false);
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(text)));
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.3.3'
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Mon Mar 06 01:34:12 CET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"

warn ( ) {
warn () {
echo "$*"
}

die ( ) {
die () {
echo
echo "$*"
echo
Expand Down Expand Up @@ -155,7 +155,7 @@ if $cygwin ; then
fi

# Escape application args
save ( ) {
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
Expand Down
4 changes: 2 additions & 2 deletions terminal-emulator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ ext {
libraryDescription = 'The terminal emulator used in Termux'
siteUrl = 'https://github.com/termux/termux'
gitUrl = 'https://github.com/termux/termux.git'
libraryVersion = '0.49'
libraryVersion = '0.50'
}

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "26.0.0"

defaultConfig {
minSdkVersion 21
Expand Down
3 changes: 1 addition & 2 deletions terminal-emulator/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.termux.terminal">
<manifest package="com.termux.terminal">
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ public final class TerminalEmulator {

private byte mUtf8ToFollow, mUtf8Index;
private final byte[] mUtf8InputBuffer = new byte[4];
private int mLastEmittedCodePoint = -1;

public final TerminalColors mColors = new TerminalColors();

Expand Down Expand Up @@ -419,10 +420,11 @@ private void processByte(byte byteToProcess) {
mUtf8Index = mUtf8ToFollow = 0;

if (codePoint >= 0x80 && codePoint <= 0x9F) {
// Sequence decoded to a C1 control character which is the same as escape followed by
// ((code & 0x7F) + 0x40).
processCodePoint(/* escape (hexadecimal=0x1B, octal=033): */27);
processCodePoint((codePoint & 0x7F) + 0x40);
// Sequence decoded to a C1 control character which we ignore. They are
// not used nowadays and increases the risk of messing up the terminal state
// on binary input. XTerm does not allow them in utf-8:
// "It is not possible to use a C1 control obtained from decoding the
// UTF-8 text" - http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
} else {
switch (Character.getType(codePoint)) {
case Character.UNASSIGNED:
Expand Down Expand Up @@ -632,6 +634,7 @@ public void processCodePoint(int b) {
int bottom = Math.min(getArg(2, mRows, true) + 1, effectiveBottomMargin - 1) + effectiveTopMargin;
int right = Math.min(getArg(3, mColumns, true) + 1, effectiveRightMargin - 1) + effectiveLeftMargin;
if (mArgIndex >= 4) {
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
for (int i = 4; i <= mArgIndex; i++) {
int bits = 0;
boolean setOrClear = true; // True if setting, false if clearing.
Expand Down Expand Up @@ -965,6 +968,7 @@ private void doCsiQuestionMark(int b) {
break;
case 'h':
case 'l':
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
for (int i = 0; i <= mArgIndex; i++)
doDecSetOrReset(b == 'h', mArgs[i]);
break;
Expand All @@ -981,6 +985,7 @@ private void doCsiQuestionMark(int b) {
break;
case 'r':
case 's':
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
for (int i = 0; i <= mArgIndex; i++) {
int externalBit = mArgs[i];
int internalBit = mapDecSetBitToInternalBit(externalBit);
Expand Down Expand Up @@ -1307,6 +1312,8 @@ private void saveCursor() {
state.mSavedCursorRow = mCursorRow;
state.mSavedCursorCol = mCursorCol;
state.mSavedEffect = mEffect;
state.mSavedForeColor = mForeColor;
state.mSavedBackColor = mBackColor;
state.mSavedDecFlags = mCurrentDecSetFlags;
state.mUseLineDrawingG0 = mUseLineDrawingG0;
state.mUseLineDrawingG1 = mUseLineDrawingG1;
Expand All @@ -1318,6 +1325,8 @@ private void restoreCursor() {
SavedScreenState state = (mScreen == mMainBuffer) ? mSavedStateMain : mSavedStateAlt;
setCursorRowCol(state.mSavedCursorRow, state.mSavedCursorCol);
mEffect = state.mSavedEffect;
mForeColor = state.mSavedForeColor;
mBackColor = state.mSavedBackColor;
int mask = (DECSET_BIT_AUTOWRAP | DECSET_BIT_ORIGIN_MODE);
mCurrentDecSetFlags = (mCurrentDecSetFlags & ~mask) | (state.mSavedDecFlags & mask);
mUseLineDrawingG0 = state.mUseLineDrawingG0;
Expand Down Expand Up @@ -1501,6 +1510,11 @@ private void doCsi(int b) {
case '`': // Horizontal position absolute (HPA - http://www.vt100.net/docs/vt510-rm/HPA).
setCursorColRespectingOriginMode(getArg0(1) - 1);
break;
case 'b': // Repeat the preceding graphic character Ps times (REP).
if (mLastEmittedCodePoint == -1) break;
final int numRepeat = getArg0(1);
for (int i = 0; i < numRepeat; i++) emitCodePoint(mLastEmittedCodePoint);
break;
case 'c': // Primary Device Attributes (http://www.vt100.net/docs/vt510-rm/DA1) if argument is missing or zero.
// The important part that may still be used by some (tmux stores this value but does not currently use it)
// is the first response parameter identifying the terminal service class, where we send 64 for "vt420".
Expand Down Expand Up @@ -1566,6 +1580,7 @@ private void doCsi(int b) {
// Also require that top + 2 <= bottom.
mTopMargin = Math.max(0, Math.min(getArg0(1) - 1, mRows - 2));
mBottomMargin = Math.max(mTopMargin + 2, Math.min(getArg1(mRows), mRows));

// DECSTBM moves the cursor to column 1, line 1 of the page respecting origin mode.
setCursorPosition(0, 0);
}
Expand Down Expand Up @@ -1639,6 +1654,7 @@ private void doCsi(int b) {

/** Select Graphic Rendition (SGR) - see http://en.wikipedia.org/wiki/ANSI_escape_code#graphics. */
private void selectGraphicRendition() {
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
for (int i = 0; i <= mArgIndex; i++) {
int code = mArgs[i];
if (code < 0) {
Expand Down Expand Up @@ -2049,6 +2065,7 @@ private void logError(String errorType) {
buf.append(", escapeState=");
buf.append(mEscapeState);
boolean firstArg = true;
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
for (int i = 0; i <= mArgIndex; i++) {
int value = mArgs[i];
if (value >= 0) {
Expand Down Expand Up @@ -2081,6 +2098,7 @@ private void finishSequence() {
* @param codePoint The code point of the character to display
*/
private void emitCodePoint(int codePoint) {
mLastEmittedCodePoint = codePoint;
if (mUseLineDrawingUsesG0 ? mUseLineDrawingG0 : mUseLineDrawingG1) {
// http://www.vt100.net/docs/vt102-ug/table5-15.html.
switch (codePoint) {
Expand Down Expand Up @@ -2263,8 +2281,8 @@ public void reset() {
mBottomMargin = mRows;
mRightMargin = mColumns;
mAboutToAutoWrap = false;
mForeColor = TextStyle.COLOR_INDEX_FOREGROUND;
mBackColor = TextStyle.COLOR_INDEX_BACKGROUND;
mForeColor = mSavedStateMain.mSavedForeColor = mSavedStateAlt.mSavedForeColor = TextStyle.COLOR_INDEX_FOREGROUND;
mBackColor = mSavedStateMain.mSavedBackColor = mSavedStateAlt.mSavedBackColor = TextStyle.COLOR_INDEX_BACKGROUND;
setDefaultTabStops();

mUseLineDrawingG0 = mUseLineDrawingG1 = false;
Expand Down Expand Up @@ -2318,7 +2336,7 @@ public void paste(String text) {
static final class SavedScreenState {
/** Saved state of the cursor position, Used to implement the save/restore cursor position escape sequences. */
int mSavedCursorRow, mSavedCursorCol;
int mSavedEffect;
int mSavedEffect, mSavedForeColor, mSavedBackColor;
int mSavedDecFlags;
boolean mUseLineDrawingG0, mUseLineDrawingG1, mUseLineDrawingUsesG0 = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,21 @@ public void testCsiX() {
withTerminalSized(13, 2).enterString("abcdefghijkl\b\b\b\b\b\033[20X").assertLinesAre("abcdefg ", " ");
}

/** CSI Pm m Set SGR parameter(s) from semicolon-separated list Pm. */
public void testCsiSGRParameters() {
// Set more parameters (19) than supported (16). Additional parameters should be silently consumed.
withTerminalSized(3, 2).enterString("\033[0;38;2;255;255;255;48;2;0;0;0;1;2;3;4;5;7;8;9mabc").assertLinesAre("abc", " ");
}

/** CSI Ps b Repeat the preceding graphic character Ps times (REP). */
public void testRepeat() {
withTerminalSized(3, 2).enterString("a\033[b").assertLinesAre("aa ", " ");
withTerminalSized(3, 2).enterString("a\033[2b").assertLinesAre("aaa", " ");
// When no char has been output we ignore REP:
withTerminalSized(3, 2).enterString("\033[b").assertLinesAre(" ", " ");
// This shows that REP outputs the last emitted code point and not the one relative to the
// current cursor position:
withTerminalSized(5, 2).enterString("abcde\033[2G\033[2b\n").assertLinesAre("aeede", " ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,44 @@ public void testBackspaceAcrossWrappedLines() {
withTerminalSized(3, 3).enterString("\b\b\b\bhi").assertLinesAre("hi ", " ", " ");
}

public void testCursorSaveRestoreLocation() {
// DEC save/restore
withTerminalSized(4, 2).enterString("t\0337est\r\nme\0338ry ").assertLinesAre("try ", "me ");
// ANSI.SYS save/restore
withTerminalSized(4, 2).enterString("t\033[sest\r\nme\033[ury ").assertLinesAre("try ", "me ");
// Alternate screen enter/exit
withTerminalSized(4, 2).enterString("t\033[?1049h\033[Hest\r\nme").assertLinesAre("est ", "me ").enterString("\033[?1049lry").assertLinesAre("try ", " ");
}

public void testCursorSaveRestoreTextStyle() {
long s;

// DEC save/restore
withTerminalSized(4, 2).enterString("\033[31;42;4m..\0337\033[36;47;24m\0338..");
s = getStyleAt(0, 3);
Assert.assertEquals(1, TextStyle.decodeForeColor(s));
Assert.assertEquals(2, TextStyle.decodeBackColor(s));
Assert.assertEquals(TextStyle.CHARACTER_ATTRIBUTE_UNDERLINE, TextStyle.decodeEffect(s));

// ANSI.SYS save/restore
withTerminalSized(4, 2).enterString("\033[31;42;4m..\033[s\033[36;47;24m\033[u..");
s = getStyleAt(0, 3);
Assert.assertEquals(1, TextStyle.decodeForeColor(s));
Assert.assertEquals(2, TextStyle.decodeBackColor(s));
Assert.assertEquals(TextStyle.CHARACTER_ATTRIBUTE_UNDERLINE, TextStyle.decodeEffect(s));

// Alternate screen enter/exit
withTerminalSized(4, 2);
enterString("\033[31;42;4m..\033[?1049h\033[H\033[36;47;24m.");
s = getStyleAt(0, 0);
Assert.assertEquals(6, TextStyle.decodeForeColor(s));
Assert.assertEquals(7, TextStyle.decodeBackColor(s));
Assert.assertEquals(0, TextStyle.decodeEffect(s));
enterString("\033[?1049l..");
s = getStyleAt(0, 3);
Assert.assertEquals(1, TextStyle.decodeForeColor(s));
Assert.assertEquals(2, TextStyle.decodeBackColor(s));
Assert.assertEquals(TextStyle.CHARACTER_ATTRIBUTE_UNDERLINE, TextStyle.decodeEffect(s));
}

}
2 changes: 1 addition & 1 deletion terminal-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ext {

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
buildToolsVersion "26.0.0"

dependencies {
compile 'com.android.support:support-annotations:25.3.1'
Expand Down
3 changes: 1 addition & 2 deletions terminal-view/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.termux.view">
<manifest package="com.termux.view">
</manifest>
4 changes: 4 additions & 0 deletions terminal-view/src/main/java/com/termux/view/TerminalView.java
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,10 @@ public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
if (!mIsSelectingText) {
// Fix issue where the dialog is pressed while being dismissed.
return true;
}
switch (item.getItemId()) {
case 1:
String selectedText = mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2).trim();
Expand Down

0 comments on commit 62b08b3

Please sign in to comment.