Compare commits
136 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4080f41cc7 | ||
|
|
b4e2c99d46 | ||
|
|
c5923201a4 | ||
|
|
bafd21bb39 | ||
|
|
0f20fab02c | ||
|
|
c5ae5bb06a | ||
|
|
bbd46a763c | ||
|
|
dc145d65f8 | ||
|
|
ce2d1c0d88 | ||
|
|
f2f7f963e6 | ||
|
|
2e53ef038e | ||
|
|
8c82f43dce | ||
|
|
3a16f461e7 | ||
|
|
594a5dfe25 | ||
|
|
d5e007dbb3 | ||
|
|
f4335d3824 | ||
|
|
90b6f93697 | ||
|
|
17c4a45212 | ||
|
|
6d9ffb6922 | ||
|
|
8472fce8ba | ||
|
|
69d954a583 | ||
|
|
ec1087d56f | ||
|
|
be6a73d862 | ||
|
|
80c81b274d | ||
|
|
cd9dbac548 | ||
|
|
0c837796f0 | ||
|
|
3417e37e8d | ||
|
|
31ba36e0fa | ||
|
|
c444f1fd28 | ||
|
|
9f36ed06b8 | ||
|
|
c2ab5bcd50 | ||
|
|
48fab33b79 | ||
|
|
8d7a67645b | ||
|
|
186b49d429 | ||
|
|
40a2775f52 | ||
|
|
f802d6001d | ||
|
|
50f66a12da | ||
|
|
d8e6fd21d1 | ||
|
|
0964d83572 | ||
|
|
cee0466dd7 | ||
|
|
de4f334e24 | ||
|
|
ab205ae05b | ||
|
|
b29b24f507 | ||
|
|
b3472e9e62 | ||
|
|
ab59e08959 | ||
|
|
8b566485e8 | ||
|
|
231c02a0c7 | ||
|
|
65f30e77ba | ||
|
|
686677ae45 | ||
|
|
85037a75a6 | ||
|
|
6025afc2c0 | ||
|
|
a4e4f76775 | ||
|
|
02af113dda | ||
|
|
fc4ef838bf | ||
|
|
86bd3ca21b | ||
|
|
367398bafb | ||
|
|
dd502e55f8 | ||
|
|
798125ef7a | ||
|
|
5126f06e06 | ||
|
|
0bdbf314ef | ||
|
|
2deb9899bd | ||
|
|
694ccc38c4 | ||
|
|
c949940374 | ||
|
|
d09f70de1e | ||
|
|
ac338ce2c5 | ||
|
|
092a83a688 | ||
|
|
3533b13de8 | ||
|
|
d68a0f05be | ||
|
|
9e5293a08e | ||
|
|
3f04a0a0d5 | ||
|
|
e558f824c5 | ||
|
|
8ff72ddd8b | ||
|
|
3e05356a69 | ||
|
|
82673d3f82 | ||
|
|
f2757fdb76 | ||
|
|
81fb669d0e | ||
|
|
4a45b1b617 | ||
|
|
62b08b3cf1 | ||
|
|
1e83ea3151 | ||
|
|
9c42fdb3d6 | ||
|
|
42e3163e92 | ||
|
|
68912139f6 | ||
|
|
edc92bbcbb | ||
|
|
d7520642de | ||
|
|
adae111d5c | ||
|
|
dc9272790b | ||
|
|
05ea2ea238 | ||
|
|
ad293562bc | ||
|
|
f9a565d1e0 | ||
|
|
5b3909cb73 | ||
|
|
7913e765d5 | ||
|
|
ed3a3269d8 | ||
|
|
dc3994d2cf | ||
|
|
c972377bd1 | ||
|
|
d4be782c03 | ||
|
|
c29909726c | ||
|
|
45bac89298 | ||
|
|
c06770c353 | ||
|
|
52a627efc8 | ||
|
|
2e9383720c | ||
|
|
58f9f1be71 | ||
|
|
058441dda6 | ||
|
|
888802a519 | ||
|
|
1a09b6d2a6 | ||
|
|
9d3f7734a1 | ||
|
|
61f766b59f | ||
|
|
3f08376881 | ||
|
|
cf06e70429 | ||
|
|
0714e435cb | ||
|
|
c26315185f | ||
|
|
1be5139253 | ||
|
|
adc43c40c5 | ||
|
|
779b1ca1f8 | ||
|
|
e375f99b0c | ||
|
|
0ac55cd77a | ||
|
|
4aefa5049b | ||
|
|
5b14124258 | ||
|
|
1a9c38374c | ||
|
|
eefd504f08 | ||
|
|
19f838e3d1 | ||
|
|
63adb2b132 | ||
|
|
7d3a988d2f | ||
|
|
5cd705d6d1 | ||
|
|
af8b269b51 | ||
|
|
8c220eaaea | ||
|
|
0142e1ed0e | ||
|
|
ac0a349ed9 | ||
|
|
548b0916b6 | ||
|
|
009de5a3ee | ||
|
|
41d0d60017 | ||
|
|
12ac0fa73c | ||
|
|
835dfc0276 | ||
|
|
f60316835f | ||
|
|
f74a091be6 | ||
|
|
dd6cb5221d | ||
|
|
cab6df5c0e |
2
.gitignore
vendored
@@ -33,6 +33,8 @@ local.properties
|
|||||||
.idea/scopes/scope_settings.xml
|
.idea/scopes/scope_settings.xml
|
||||||
.idea/vcs.xml
|
.idea/vcs.xml
|
||||||
.idea/dictionaries/
|
.idea/dictionaries/
|
||||||
|
.idea/caches/
|
||||||
|
.idea/codeStyles/
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
# OS-specific files
|
# OS-specific files
|
||||||
|
|||||||
2
.idea/gradle.xml
generated
@@ -10,6 +10,8 @@
|
|||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/app" />
|
<option value="$PROJECT_DIR$/app" />
|
||||||
|
<option value="$PROJECT_DIR$/terminal-emulator" />
|
||||||
|
<option value="$PROJECT_DIR$/terminal-view" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveModulePerSourceSet" value="false" />
|
<option name="resolveModulePerSourceSet" value="false" />
|
||||||
|
|||||||
@@ -12,13 +12,14 @@ android:
|
|||||||
components:
|
components:
|
||||||
- platform-tools
|
- platform-tools
|
||||||
- tools
|
- tools
|
||||||
- build-tools-25.0.2
|
- build-tools-27.0.3
|
||||||
- android-25
|
- android-27
|
||||||
- extra-android-m2repository
|
- extra-android-m2repository
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- git clone https://github.com/urho3d/android-ndk.git $HOME/android-ndk
|
- git clone https://github.com/urho3d/android-ndk.git $HOME/android-ndk
|
||||||
- export ANDROID_NDK_HOME=$HOME/android-ndk
|
- export ANDROID_NDK_HOME=$HOME/android-ndk
|
||||||
|
- yes | sdkmanager "platforms;android-27"
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./gradlew testDebugUnitTest
|
- ./gradlew testDebugUnitTest
|
||||||
|
|||||||
3
LICENSE.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Released under [the GPLv3 license](https://www.gnu.org/licenses/gpl.html).
|
||||||
|
|
||||||
|
Contains code from `Terminal Emulator for Android` by which is released under [the Apache License 2.0](https://www.apache.org/licenses/).
|
||||||
@@ -7,15 +7,14 @@ Termux app
|
|||||||
|
|
||||||
* [Termux on Google Play Store](https://play.google.com/store/apps/details?id=com.termux)
|
* [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 on F-Droid](https://f-droid.org/repository/browse/?fdid=com.termux)
|
||||||
* [Termux Help](http://termux.com/help/)
|
* [Termux Facebook](https://facebook.com/termux/)
|
||||||
* [Termux Google+ community](http://termux.com/community/)
|
* [Termux Google+ community](http://termux.com/community/)
|
||||||
|
* [Termux Help](http://termux.com/help/)
|
||||||
|
* [Termux Twitter](http://twitter.com/termux/)
|
||||||
|
* [Termux Wiki](https://wiki.termux.com/wiki/)
|
||||||
|
|
||||||
Note that this repository is for the app itself (the user interface and the terminal emulation). For the packages installable inside the app, see [termux/termux-packages](https://github.com/termux/termux-packages)
|
Note that this repository is for the app itself (the user interface and the terminal emulation). For the packages installable inside the app, see [termux/termux-packages](https://github.com/termux/termux-packages)
|
||||||
|
|
||||||
License
|
|
||||||
=======
|
|
||||||
Released under [the GPLv3 license](https://www.gnu.org/licenses/gpl.html). Contains code from `Terminal Emulator for Android` which is released under [the Apache License 2.0](https://www.apache.org/licenses/).
|
|
||||||
|
|
||||||
Terminal resources
|
Terminal resources
|
||||||
==================
|
==================
|
||||||
* [XTerm control sequences](http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
|
* [XTerm control sequences](http://invisible-island.net/xterm/ctlseqs/ctlseqs.html)
|
||||||
|
|||||||
@@ -1,30 +1,20 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion 27
|
||||||
buildToolsVersion "25.0.2"
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.android.support:support-annotations:25.1.0'
|
implementation 'com.android.support:support-annotations:27.1.1'
|
||||||
compile "com.android.support:support-v4:25.1.0"
|
implementation "com.android.support:support-core-ui:27.1.1"
|
||||||
|
implementation project(":terminal-view")
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.termux"
|
applicationId "com.termux"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 27
|
||||||
versionCode 48
|
versionCode 62
|
||||||
versionName "0.48"
|
versionName "0.62"
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ndk {
|
|
||||||
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -34,14 +24,8 @@ android {
|
|||||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
externalNativeBuild {
|
|
||||||
ndkBuild {
|
|
||||||
path "src/main/jni/Android.mk"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testCompile 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
}
|
}
|
||||||
|
|||||||
10
app/proguard-rules.pro
vendored
@@ -7,11 +7,5 @@
|
|||||||
# For more details, see
|
# For more details, see
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
# Add any project specific keep options here:
|
-renamesourcefileattribute SourceFile
|
||||||
|
-keepattributes SourceFile,LineNumberTable
|
||||||
# If your project uses WebView with JS, uncomment the following
|
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
|
||||||
# class:
|
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
||||||
# public *;
|
|
||||||
#}
|
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package com.termux;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import android.test.ApplicationTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTest extends ApplicationTestCase<Application> {
|
|
||||||
public ApplicationTest() {
|
|
||||||
super(Application.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.termux"
|
package="com.termux"
|
||||||
android:installLocation="internalOnly"
|
android:installLocation="internalOnly"
|
||||||
android:sharedUserId="com.termux"
|
android:sharedUserId="com.termux"
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
<uses-permission android:name="android.permission.VIBRATE" />
|
<uses-permission android:name="android.permission.VIBRATE" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
|
android:extractNativeLibs="true"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:fullBackupContent="@xml/backupscheme"
|
android:fullBackupContent="@xml/backupscheme"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
@@ -22,10 +24,15 @@
|
|||||||
android:theme="@style/Theme.Termux"
|
android:theme="@style/Theme.Termux"
|
||||||
android:supportsRtl="false" >
|
android:supportsRtl="false" >
|
||||||
|
|
||||||
|
<!-- This (or rather, value 2.1 or higher) is needed to make the Samsung Galaxy S8
|
||||||
|
mark the app with "This app is optimized to run in full screen." -->
|
||||||
|
<meta-data android:name="android.max_aspect" android:value="10.0" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.termux.app.TermuxActivity"
|
android:name="com.termux.app.TermuxActivity"
|
||||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||||
android:launchMode="singleTask"
|
android:launchMode="singleTask"
|
||||||
|
android:resizeableActivity="true"
|
||||||
android:windowSoftInputMode="adjustResize|stateAlwaysVisible" >
|
android:windowSoftInputMode="adjustResize|stateAlwaysVisible" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -43,6 +50,7 @@
|
|||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:theme="@android:style/Theme.Material.Light.DarkActionBar"
|
android:theme="@android:style/Theme.Material.Light.DarkActionBar"
|
||||||
android:parentActivityName=".app.TermuxActivity"
|
android:parentActivityName=".app.TermuxActivity"
|
||||||
|
android:resizeableActivity="true"
|
||||||
android:label="@string/application_name" />
|
android:label="@string/application_name" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
@@ -50,6 +58,7 @@
|
|||||||
android:label="@string/application_name"
|
android:label="@string/application_name"
|
||||||
android:taskAffinity="com.termux.filereceiver"
|
android:taskAffinity="com.termux.filereceiver"
|
||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
|
android:resizeableActivity="true"
|
||||||
android:noHistory="true">
|
android:noHistory="true">
|
||||||
<!-- Accept multiple file types when sending. -->
|
<!-- Accept multiple file types when sending. -->
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
@@ -64,7 +73,7 @@
|
|||||||
<data android:mimeType="video/*" />
|
<data android:mimeType="video/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
<!-- Be more restrictive for viewing files, restricting ourselves to text files. -->
|
<!-- Be more restrictive for viewing files, restricting ourselves to text files. -->
|
||||||
<intent-filter>
|
<intent-filter tools:ignore="AppLinkUrlError">
|
||||||
<action android:name="android.intent.action.VIEW"/>
|
<action android:name="android.intent.action.VIEW"/>
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
<data android:mimeType="text/*" />
|
<data android:mimeType="text/*" />
|
||||||
@@ -75,6 +84,18 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</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
|
<provider
|
||||||
android:name=".filepicker.TermuxDocumentsProvider"
|
android:name=".filepicker.TermuxDocumentsProvider"
|
||||||
android:authorities="com.termux.documents"
|
android:authorities="com.termux.documents"
|
||||||
@@ -98,6 +119,7 @@
|
|||||||
android:grantUriPermissions="true"
|
android:grantUriPermissions="true"
|
||||||
android:name="com.termux.app.TermuxOpenReceiver$ContentProvider" />
|
android:name="com.termux.app.TermuxOpenReceiver$ContentProvider" />
|
||||||
|
|
||||||
|
<meta-data android:name="com.sec.android.support.multiwindow" android:value="true" />
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -111,13 +111,13 @@ public final class BackgroundJob {
|
|||||||
final String pathEnv = "PATH=" + System.getenv("PATH");
|
final String pathEnv = "PATH=" + System.getenv("PATH");
|
||||||
return new String[]{termEnv, homeEnv, prefixEnv, androidRootEnv, androidDataEnv, pathEnv, externalStorageEnv};
|
return new String[]{termEnv, homeEnv, prefixEnv, androidRootEnv, androidDataEnv, pathEnv, externalStorageEnv};
|
||||||
} else {
|
} else {
|
||||||
final String ps1Env = "PS1=$ ";
|
|
||||||
final String ldEnv = "LD_LIBRARY_PATH=" + TermuxService.PREFIX_PATH + "/lib";
|
final String ldEnv = "LD_LIBRARY_PATH=" + TermuxService.PREFIX_PATH + "/lib";
|
||||||
final String langEnv = "LANG=en_US.UTF-8";
|
final String langEnv = "LANG=en_US.UTF-8";
|
||||||
final String pathEnv = "PATH=" + TermuxService.PREFIX_PATH + "/bin:" + TermuxService.PREFIX_PATH + "/bin/applets";
|
final String pathEnv = "PATH=" + TermuxService.PREFIX_PATH + "/bin:" + TermuxService.PREFIX_PATH + "/bin/applets";
|
||||||
final String pwdEnv = "PWD=" + cwd;
|
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, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +158,6 @@ public final class BackgroundJob {
|
|||||||
if (c == ' ' || c == '\n') {
|
if (c == ' ' || c == '\n') {
|
||||||
if (builder.length() == 0) {
|
if (builder.length() == 0) {
|
||||||
// Skip whitespace after shebang.
|
// Skip whitespace after shebang.
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
// End of shebang.
|
// End of shebang.
|
||||||
String executable = builder.toString();
|
String executable = builder.toString();
|
||||||
|
|||||||
@@ -2,11 +2,19 @@ package com.termux.app;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
|
import android.view.HapticFeedbackConstants;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.GridLayout;
|
import android.widget.GridLayout;
|
||||||
|
import android.widget.PopupWindow;
|
||||||
import android.widget.ToggleButton;
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
import com.termux.R;
|
import com.termux.R;
|
||||||
@@ -20,6 +28,8 @@ import com.termux.view.TerminalView;
|
|||||||
public final class ExtraKeysView extends GridLayout {
|
public final class ExtraKeysView extends GridLayout {
|
||||||
|
|
||||||
private static final int TEXT_COLOR = 0xFFFFFFFF;
|
private static final int TEXT_COLOR = 0xFFFFFFFF;
|
||||||
|
private static final int BUTTON_COLOR = 0xFF000000;
|
||||||
|
private static final int BUTTON_PRESSED_COLOR = 0xFF888888;
|
||||||
|
|
||||||
public ExtraKeysView(Context context, AttributeSet attrs) {
|
public ExtraKeysView(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -37,16 +47,28 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
case "TAB":
|
case "TAB":
|
||||||
keyCode = KeyEvent.KEYCODE_TAB;
|
keyCode = KeyEvent.KEYCODE_TAB;
|
||||||
break;
|
break;
|
||||||
case "▲":
|
case "HOME":
|
||||||
|
keyCode = KeyEvent.KEYCODE_MOVE_HOME;
|
||||||
|
break;
|
||||||
|
case "END":
|
||||||
|
keyCode = KeyEvent.KEYCODE_MOVE_END;
|
||||||
|
break;
|
||||||
|
case "PGUP":
|
||||||
|
keyCode = KeyEvent.KEYCODE_PAGE_UP;
|
||||||
|
break;
|
||||||
|
case "PGDN":
|
||||||
|
keyCode = KeyEvent.KEYCODE_PAGE_DOWN;
|
||||||
|
break;
|
||||||
|
case "↑":
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_UP;
|
keyCode = KeyEvent.KEYCODE_DPAD_UP;
|
||||||
break;
|
break;
|
||||||
case "◀":
|
case "←":
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
|
keyCode = KeyEvent.KEYCODE_DPAD_LEFT;
|
||||||
break;
|
break;
|
||||||
case "▶":
|
case "→":
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
|
keyCode = KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||||
break;
|
break;
|
||||||
case "▼":
|
case "↓":
|
||||||
keyCode = KeyEvent.KEYCODE_DPAD_DOWN;
|
keyCode = KeyEvent.KEYCODE_DPAD_DOWN;
|
||||||
break;
|
break;
|
||||||
case "―":
|
case "―":
|
||||||
@@ -56,11 +78,11 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
chars = keyName;
|
chars = keyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TerminalView terminalView = view.findViewById(R.id.terminal_view);
|
||||||
if (keyCode > 0) {
|
if (keyCode > 0) {
|
||||||
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, keyCode));
|
terminalView.onKeyDown(keyCode, new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||||
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
// view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, keyCode));
|
||||||
} else {
|
} else {
|
||||||
TerminalView terminalView = (TerminalView) view.findViewById(R.id.terminal_view);
|
|
||||||
TerminalSession session = terminalView.getCurrentSession();
|
TerminalSession session = terminalView.getCurrentSession();
|
||||||
if (session != null) session.write(chars);
|
if (session != null) session.write(chars);
|
||||||
}
|
}
|
||||||
@@ -69,6 +91,9 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
private ToggleButton controlButton;
|
private ToggleButton controlButton;
|
||||||
private ToggleButton altButton;
|
private ToggleButton altButton;
|
||||||
private ToggleButton fnButton;
|
private ToggleButton fnButton;
|
||||||
|
private ScheduledExecutorService scheduledExecutor;
|
||||||
|
private PopupWindow popupWindow;
|
||||||
|
private int longPressCount;
|
||||||
|
|
||||||
public boolean readControlButton() {
|
public boolean readControlButton() {
|
||||||
if (controlButton.isPressed()) return true;
|
if (controlButton.isPressed()) return true;
|
||||||
@@ -100,24 +125,47 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void popup(View view, String text) {
|
||||||
|
int width = view.getMeasuredWidth();
|
||||||
|
int height = view.getMeasuredHeight();
|
||||||
|
Button button = new Button(getContext(), null, android.R.attr.buttonBarButtonStyle);
|
||||||
|
button.setText(text);
|
||||||
|
button.setTextColor(TEXT_COLOR);
|
||||||
|
button.setPadding(0, 0, 0, 0);
|
||||||
|
button.setMinHeight(0);
|
||||||
|
button.setMinWidth(0);
|
||||||
|
button.setMinimumWidth(0);
|
||||||
|
button.setMinimumHeight(0);
|
||||||
|
button.setWidth(width);
|
||||||
|
button.setHeight(height);
|
||||||
|
button.setBackgroundColor(BUTTON_PRESSED_COLOR);
|
||||||
|
popupWindow = new PopupWindow(this);
|
||||||
|
popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
|
||||||
|
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
|
||||||
|
popupWindow.setContentView(button);
|
||||||
|
popupWindow.setOutsideTouchable(true);
|
||||||
|
popupWindow.setFocusable(false);
|
||||||
|
popupWindow.showAsDropDown(view, 0, -2 * height);
|
||||||
|
}
|
||||||
|
|
||||||
void reload() {
|
void reload() {
|
||||||
altButton = controlButton = null;
|
altButton = controlButton = null;
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
|
|
||||||
String[][] buttons = {
|
String[][] buttons = {
|
||||||
{"ESC", "CTRL", "ALT", "TAB", "―", "/", "|"}
|
{"ESC", "/", "―", "HOME", "↑", "END", "PGUP"},
|
||||||
|
{"TAB", "CTRL", "ALT", "←", "↓", "→", "PGDN"}
|
||||||
};
|
};
|
||||||
|
|
||||||
final int rows = buttons.length;
|
final int rows = buttons.length;
|
||||||
final int cols = buttons[0].length;
|
final int[] cols = {buttons[0].length, buttons[1].length};
|
||||||
|
|
||||||
setRowCount(rows);
|
setRowCount(rows);
|
||||||
setColumnCount(cols);
|
setColumnCount(cols[0]);
|
||||||
|
|
||||||
for (int row = 0; row < rows; row++) {
|
for (int row = 0; row < rows; row++) {
|
||||||
for (int col = 0; col < cols; col++) {
|
for (int col = 0; col < cols[row]; col++) {
|
||||||
final String buttonText = buttons[row][col];
|
final String buttonText = buttons[row][col];
|
||||||
|
|
||||||
Button button;
|
Button button;
|
||||||
switch (buttonText) {
|
switch (buttonText) {
|
||||||
case "CTRL":
|
case "CTRL":
|
||||||
@@ -139,11 +187,13 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
|
|
||||||
button.setText(buttonText);
|
button.setText(buttonText);
|
||||||
button.setTextColor(TEXT_COLOR);
|
button.setTextColor(TEXT_COLOR);
|
||||||
|
button.setPadding(0, 0, 0, 0);
|
||||||
|
|
||||||
final Button finalButton = button;
|
final Button finalButton = button;
|
||||||
button.setOnClickListener(new OnClickListener() {
|
button.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
finalButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
|
||||||
View root = getRootView();
|
View root = getRootView();
|
||||||
switch (buttonText) {
|
switch (buttonText) {
|
||||||
case "CTRL":
|
case "CTRL":
|
||||||
@@ -160,12 +210,69 @@ public final class ExtraKeysView extends GridLayout {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
GridLayout.LayoutParams param = new GridLayout.LayoutParams();
|
button.setOnTouchListener(new OnTouchListener() {
|
||||||
param.height = param.width = 0;
|
@Override
|
||||||
param.rightMargin = param.topMargin = 0;
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
final View root = getRootView();
|
||||||
|
switch (event.getAction()) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
longPressCount = 0;
|
||||||
|
v.setBackgroundColor(BUTTON_PRESSED_COLOR);
|
||||||
|
if ("↑↓←→".contains(buttonText)) {
|
||||||
|
scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
scheduledExecutor.scheduleWithFixedDelay(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
longPressCount++;
|
||||||
|
sendKey(root, buttonText);
|
||||||
|
}
|
||||||
|
}, 400, 80, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
if ("―/".contains(buttonText)) {
|
||||||
|
if (popupWindow == null && event.getY() < 0) {
|
||||||
|
v.setBackgroundColor(BUTTON_COLOR);
|
||||||
|
String text = "―".equals(buttonText) ? "|" : "\\";
|
||||||
|
popup(v, text);
|
||||||
|
}
|
||||||
|
if (popupWindow != null && event.getY() > 0) {
|
||||||
|
v.setBackgroundColor(BUTTON_PRESSED_COLOR);
|
||||||
|
popupWindow.dismiss();
|
||||||
|
popupWindow = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
v.setBackgroundColor(BUTTON_COLOR);
|
||||||
|
if (scheduledExecutor != null) {
|
||||||
|
scheduledExecutor.shutdownNow();
|
||||||
|
scheduledExecutor = null;
|
||||||
|
}
|
||||||
|
if (longPressCount == 0) {
|
||||||
|
if (popupWindow != null && "―/".contains(buttonText)) {
|
||||||
|
popupWindow.setContentView(null);
|
||||||
|
popupWindow.dismiss();
|
||||||
|
popupWindow = null;
|
||||||
|
sendKey(root, "―".equals(buttonText) ? "|" : "\\");
|
||||||
|
} else {
|
||||||
|
v.performClick();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
LayoutParams param = new GridLayout.LayoutParams();
|
||||||
|
param.width = param.height = 0;
|
||||||
|
param.setMargins(0, 0, 0, 0);
|
||||||
param.setGravity(Gravity.LEFT);
|
param.setGravity(Gravity.LEFT);
|
||||||
float weight = "▲▼◀▶".contains(buttonText) ? 0.7f : 1.f;
|
param.columnSpec = GridLayout.spec(col, GridLayout.FILL, 1.f);
|
||||||
param.columnSpec = GridLayout.spec(col, GridLayout.FILL, weight);
|
|
||||||
param.rowSpec = GridLayout.spec(row, GridLayout.FILL, 1.f);
|
param.rowSpec = GridLayout.spec(row, GridLayout.FILL, 1.f);
|
||||||
button.setLayoutParams(param);
|
button.setLayoutParams(param);
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
package com.termux.app;
|
|
||||||
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.termux.R;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility to manage full screen immersive mode.
|
|
||||||
* <p/>
|
|
||||||
* See https://code.google.com/p/android/issues/detail?id=5497
|
|
||||||
*/
|
|
||||||
final class FullScreenHelper {
|
|
||||||
|
|
||||||
private boolean mEnabled = false;
|
|
||||||
final TermuxActivity mActivity;
|
|
||||||
|
|
||||||
public FullScreenHelper(TermuxActivity activity) {
|
|
||||||
this.mActivity = activity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setImmersive(boolean enabled) {
|
|
||||||
if (enabled == mEnabled) return;
|
|
||||||
mEnabled = enabled;
|
|
||||||
|
|
||||||
View decorView = mActivity.getWindow().getDecorView();
|
|
||||||
|
|
||||||
if (enabled) {
|
|
||||||
decorView.setOnSystemUiVisibilityChangeListener
|
|
||||||
(new View.OnSystemUiVisibilityChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onSystemUiVisibilityChange(int visibility) {
|
|
||||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
|
||||||
if (mActivity.mSettings.isShowExtraKeys()) {
|
|
||||||
mActivity.findViewById(R.id.viewpager).setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
setImmersiveMode();
|
|
||||||
} else {
|
|
||||||
mActivity.findViewById(R.id.viewpager).setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setImmersiveMode();
|
|
||||||
} else {
|
|
||||||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
|
||||||
decorView.setOnSystemUiVisibilityChangeListener(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isColorLight(int color) {
|
|
||||||
double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
|
|
||||||
return darkness < 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setImmersiveMode() {
|
|
||||||
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
||||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
|
||||||
| View.SYSTEM_UI_FLAG_FULLSCREEN;
|
|
||||||
int color = ((ColorDrawable) mActivity.getWindow().getDecorView().getBackground()).getColor();
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isColorLight(color))
|
|
||||||
flags |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
|
|
||||||
mActivity.getWindow().getDecorView().setSystemUiVisibility(flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -49,8 +49,6 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.View.OnLongClickListener;
|
import android.view.View.OnLongClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.Animation;
|
|
||||||
import android.view.animation.AnimationUtils;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
@@ -75,6 +73,7 @@ import java.io.InputStream;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -97,7 +96,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
private static final int CONTEXTMENU_KILL_PROCESS_ID = 4;
|
private static final int CONTEXTMENU_KILL_PROCESS_ID = 4;
|
||||||
private static final int CONTEXTMENU_RESET_TERMINAL_ID = 5;
|
private static final int CONTEXTMENU_RESET_TERMINAL_ID = 5;
|
||||||
private static final int CONTEXTMENU_STYLING_ID = 6;
|
private static final int CONTEXTMENU_STYLING_ID = 6;
|
||||||
private static final int CONTEXTMENU_TOGGLE_FULLSCREEN_ID = 7;
|
|
||||||
private static final int CONTEXTMENU_HELP_ID = 8;
|
private static final int CONTEXTMENU_HELP_ID = 8;
|
||||||
|
|
||||||
private static final int MAX_SESSIONS = 8;
|
private static final int MAX_SESSIONS = 8;
|
||||||
@@ -113,8 +111,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
ExtraKeysView mExtraKeysView;
|
ExtraKeysView mExtraKeysView;
|
||||||
|
|
||||||
final FullScreenHelper mFullScreenHelper = new FullScreenHelper(this);
|
|
||||||
|
|
||||||
TermuxPreferences mSettings;
|
TermuxPreferences mSettings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -159,7 +155,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
void checkForFontAndColors() {
|
void checkForFontAndColors() {
|
||||||
try {
|
try {
|
||||||
// Hard-coded paths since this file is used also in Termux:Float.
|
|
||||||
@SuppressLint("SdCardPath") File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
|
@SuppressLint("SdCardPath") File fontFile = new File("/data/data/com.termux/files/home/.termux/font.ttf");
|
||||||
@SuppressLint("SdCardPath") File colorsFile = new File("/data/data/com.termux/files/home/.termux/colors.properties");
|
@SuppressLint("SdCardPath") File colorsFile = new File("/data/data/com.termux/files/home/.termux/colors.properties");
|
||||||
|
|
||||||
@@ -214,14 +209,13 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
mSettings = new TermuxPreferences(this);
|
mSettings = new TermuxPreferences(this);
|
||||||
|
|
||||||
setContentView(R.layout.drawer_layout);
|
setContentView(R.layout.drawer_layout);
|
||||||
mTerminalView = (TerminalView) findViewById(R.id.terminal_view);
|
mTerminalView = findViewById(R.id.terminal_view);
|
||||||
mTerminalView.setOnKeyListener(new TermuxKeyListener(this));
|
mTerminalView.setOnKeyListener(new TermuxViewClient(this));
|
||||||
|
|
||||||
mTerminalView.setTextSize(mSettings.getFontSize());
|
mTerminalView.setTextSize(mSettings.getFontSize());
|
||||||
mFullScreenHelper.setImmersive(mSettings.isFullScreen());
|
|
||||||
mTerminalView.requestFocus();
|
mTerminalView.requestFocus();
|
||||||
|
|
||||||
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
final ViewPager viewPager = findViewById(R.id.viewpager);
|
||||||
if (mSettings.isShowExtraKeys()) viewPager.setVisibility(View.VISIBLE);
|
if (mSettings.isShowExtraKeys()) viewPager.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
viewPager.setAdapter(new PagerAdapter() {
|
viewPager.setAdapter(new PagerAdapter() {
|
||||||
@@ -231,19 +225,20 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isViewFromObject(View view, Object object) {
|
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
|
||||||
return view == object;
|
return view == object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Object instantiateItem(ViewGroup collection, int position) {
|
public Object instantiateItem(@NonNull ViewGroup collection, int position) {
|
||||||
LayoutInflater inflater = LayoutInflater.from(TermuxActivity.this);
|
LayoutInflater inflater = LayoutInflater.from(TermuxActivity.this);
|
||||||
View layout;
|
View layout;
|
||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
layout = mExtraKeysView = (ExtraKeysView) inflater.inflate(R.layout.extra_keys_main, collection, false);
|
layout = mExtraKeysView = (ExtraKeysView) inflater.inflate(R.layout.extra_keys_main, collection, false);
|
||||||
} else {
|
} else {
|
||||||
layout = inflater.inflate(R.layout.extra_keys_right, collection, false);
|
layout = inflater.inflate(R.layout.extra_keys_right, collection, false);
|
||||||
final EditText editText = (EditText) layout.findViewById(R.id.text_input);
|
final EditText editText = layout.findViewById(R.id.text_input);
|
||||||
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
||||||
@@ -267,7 +262,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroyItem(ViewGroup collection, int position, Object view) {
|
public void destroyItem(@NonNull ViewGroup collection, int position, @NonNull Object view) {
|
||||||
collection.removeView((View) view);
|
collection.removeView((View) view);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -278,7 +273,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
if (position == 0) {
|
if (position == 0) {
|
||||||
mTerminalView.requestFocus();
|
mTerminalView.requestFocus();
|
||||||
} else {
|
} else {
|
||||||
final EditText editText = (EditText) viewPager.findViewById(R.id.text_input);
|
final EditText editText = viewPager.findViewById(R.id.text_input);
|
||||||
if (editText != null) editText.requestFocus();
|
if (editText != null) editText.requestFocus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -342,7 +337,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
|
|
||||||
void toggleShowExtraKeys() {
|
void toggleShowExtraKeys() {
|
||||||
final ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
|
final ViewPager viewPager = findViewById(R.id.viewpager);
|
||||||
final boolean showNow = mSettings.toggleShowExtraKeys(TermuxActivity.this);
|
final boolean showNow = mSettings.toggleShowExtraKeys(TermuxActivity.this);
|
||||||
viewPager.setVisibility(showNow ? View.VISIBLE : View.GONE);
|
viewPager.setVisibility(showNow ? View.VISIBLE : View.GONE);
|
||||||
if (showNow && viewPager.getCurrentItem() == 1) {
|
if (showNow && viewPager.getCurrentItem() == 1) {
|
||||||
@@ -399,7 +394,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
@Override
|
@Override
|
||||||
public void onClipboardText(TerminalSession session, String text) {
|
public void onClipboardText(TerminalSession session, String text) {
|
||||||
if (!mIsVisible) return;
|
if (!mIsVisible) return;
|
||||||
showToast("Clipboard:\n\"" + text + "\"", false);
|
|
||||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(text)));
|
clipboard.setPrimaryClip(new ClipData(null, new String[]{"text/plain"}, new ClipData.Item(text)));
|
||||||
}
|
}
|
||||||
@@ -428,7 +422,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ListView listView = (ListView) findViewById(R.id.left_drawer_list);
|
ListView listView = findViewById(R.id.left_drawer_list);
|
||||||
mListViewAdapter = new ArrayAdapter<TerminalSession>(getApplicationContext(), R.layout.line_in_drawer, mTermService.getSessions()) {
|
mListViewAdapter = new ArrayAdapter<TerminalSession>(getApplicationContext(), R.layout.line_in_drawer, mTermService.getSessions()) {
|
||||||
final StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
|
final StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
|
||||||
final StyleSpan italicSpan = new StyleSpan(Typeface.ITALIC);
|
final StyleSpan italicSpan = new StyleSpan(Typeface.ITALIC);
|
||||||
@@ -445,7 +439,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
TerminalSession sessionAtRow = getItem(position);
|
TerminalSession sessionAtRow = getItem(position);
|
||||||
boolean sessionRunning = sessionAtRow.isRunning();
|
boolean sessionRunning = sessionAtRow.isRunning();
|
||||||
|
|
||||||
TextView firstLineView = (TextView) row.findViewById(R.id.row_line);
|
TextView firstLineView = row.findViewById(R.id.row_line);
|
||||||
|
|
||||||
String name = sessionAtRow.mSessionName;
|
String name = sessionAtRow.mSessionName;
|
||||||
String sessionTitle = sessionAtRow.getTitle();
|
String sessionTitle = sessionAtRow.getTitle();
|
||||||
@@ -541,10 +535,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected(ComponentName name) {
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
if (mTermService != null) {
|
// Respect being stopped from the TermuxService notification action.
|
||||||
// Respect being stopped from the TermuxService notification action.
|
finish();
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -648,7 +640,7 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
final int indexOfSession = mTermService.getSessions().indexOf(session);
|
final int indexOfSession = mTermService.getSessions().indexOf(session);
|
||||||
showToast(toToastTitle(session), false);
|
showToast(toToastTitle(session), false);
|
||||||
mListViewAdapter.notifyDataSetChanged();
|
mListViewAdapter.notifyDataSetChanged();
|
||||||
final ListView lv = ((ListView) findViewById(R.id.left_drawer_list));
|
final ListView lv = findViewById(R.id.left_drawer_list);
|
||||||
lv.setItemChecked(indexOfSession, true);
|
lv.setItemChecked(indexOfSession, true);
|
||||||
lv.smoothScrollToPosition(indexOfSession);
|
lv.smoothScrollToPosition(indexOfSession);
|
||||||
}
|
}
|
||||||
@@ -662,7 +654,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
menu.add(Menu.NONE, CONTEXTMENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.select_all_and_share);
|
menu.add(Menu.NONE, CONTEXTMENU_SHARE_TRANSCRIPT_ID, Menu.NONE, R.string.select_all_and_share);
|
||||||
menu.add(Menu.NONE, CONTEXTMENU_RESET_TERMINAL_ID, Menu.NONE, R.string.reset_terminal);
|
menu.add(Menu.NONE, CONTEXTMENU_RESET_TERMINAL_ID, Menu.NONE, R.string.reset_terminal);
|
||||||
menu.add(Menu.NONE, CONTEXTMENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.kill_process, getCurrentTermSession().getPid())).setEnabled(currentSession.isRunning());
|
menu.add(Menu.NONE, CONTEXTMENU_KILL_PROCESS_ID, Menu.NONE, getResources().getString(R.string.kill_process, getCurrentTermSession().getPid())).setEnabled(currentSession.isRunning());
|
||||||
menu.add(Menu.NONE, CONTEXTMENU_TOGGLE_FULLSCREEN_ID, Menu.NONE, R.string.toggle_fullscreen).setCheckable(true).setChecked(mSettings.isFullScreen());
|
|
||||||
menu.add(Menu.NONE, CONTEXTMENU_STYLING_ID, Menu.NONE, R.string.style_terminal);
|
menu.add(Menu.NONE, CONTEXTMENU_STYLING_ID, Menu.NONE, R.string.style_terminal);
|
||||||
menu.add(Menu.NONE, CONTEXTMENU_HELP_ID, Menu.NONE, R.string.help);
|
menu.add(Menu.NONE, CONTEXTMENU_HELP_ID, Menu.NONE, R.string.help);
|
||||||
}
|
}
|
||||||
@@ -796,11 +787,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
}).setNegativeButton(android.R.string.cancel, null).show();
|
}).setNegativeButton(android.R.string.cancel, null).show();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case CONTEXTMENU_TOGGLE_FULLSCREEN_ID:
|
|
||||||
toggleImmersive();
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
case CONTEXTMENU_HELP_ID:
|
case CONTEXTMENU_HELP_ID:
|
||||||
startActivity(new Intent(this, TermuxHelpActivity.class));
|
startActivity(new Intent(this, TermuxHelpActivity.class));
|
||||||
return true;
|
return true;
|
||||||
@@ -816,12 +804,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleImmersive() {
|
|
||||||
boolean newValue = !mSettings.isFullScreen();
|
|
||||||
mSettings.setFullScreen(this, newValue);
|
|
||||||
mFullScreenHelper.setImmersive(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
void changeFontSize(boolean increase) {
|
void changeFontSize(boolean increase) {
|
||||||
mSettings.changeFontSize(this, increase);
|
mSettings.changeFontSize(this, increase);
|
||||||
mTerminalView.setTextSize(mSettings.getFontSize());
|
mTerminalView.setTextSize(mSettings.getFontSize());
|
||||||
@@ -840,9 +822,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection
|
|||||||
public TerminalSession getStoredCurrentSessionOrLast() {
|
public TerminalSession getStoredCurrentSessionOrLast() {
|
||||||
TerminalSession stored = TermuxPreferences.getCurrentSession(this);
|
TerminalSession stored = TermuxPreferences.getCurrentSession(this);
|
||||||
if (stored != null) return stored;
|
if (stored != null) return stored;
|
||||||
int numberOfSessions = mTermService.getSessions().size();
|
List<TerminalSession> sessions = mTermService.getSessions();
|
||||||
if (numberOfSessions == 0) return null;
|
return sessions.isEmpty() ? null : sessions.get(sessions.size() - 1);
|
||||||
return mTermService.getSessions().get(numberOfSessions - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Show a toast and dismiss the last one if still visible. */
|
/** Show a toast and dismiss the last one if still visible. */
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public final class TermuxHelpActivity extends Activity {
|
|||||||
mWebView.setWebViewClient(new WebViewClient() {
|
mWebView.setWebViewClient(new WebViewClient() {
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||||
if (url.startsWith("https://termux.com")) {
|
if (url.startsWith("https://wiki.termux.com")) {
|
||||||
// Inline help.
|
// Inline help.
|
||||||
setContentView(progressLayout);
|
setContentView(progressLayout);
|
||||||
return false;
|
return false;
|
||||||
@@ -60,7 +60,7 @@ public final class TermuxHelpActivity extends Activity {
|
|||||||
setContentView(mWebView);
|
setContentView(mWebView);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mWebView.loadUrl("https://termux.com/help.html");
|
mWebView.loadUrl("https://wiki.termux.com/wiki/Main_Page");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
* (4) The architecture is determined and an appropriate bootstrap zip url is determined in {@link #determineZipUrl()}.
|
* (4) The architecture is determined and an appropriate bootstrap zip url is determined in {@link #determineZipUrl()}.
|
||||||
* <p/>
|
* <p/>
|
||||||
* (5) The zip, containing entries relative to the $PREFIX, is is downloaded and extracted by a zip input stream
|
* (5) The zip, containing entries relative to the $PREFIX, is is downloaded and extracted by a zip input stream
|
||||||
* continously encountering zip file entries:
|
* continuously encountering zip file entries:
|
||||||
* <p/>
|
* <p/>
|
||||||
* (5.1) If the zip entry encountered is SYMLINKS.txt, go through it and remember all symlinks to setup.
|
* (5.1) If the zip entry encountered is SYMLINKS.txt, go through it and remember all symlinks to setup.
|
||||||
* <p/>
|
* <p/>
|
||||||
@@ -228,9 +228,13 @@ final class TermuxInstaller {
|
|||||||
try {
|
try {
|
||||||
File storageDir = new File(TermuxService.HOME_PATH, "storage");
|
File storageDir = new File(TermuxService.HOME_PATH, "storage");
|
||||||
|
|
||||||
if (storageDir.exists() && !storageDir.delete()) {
|
if (storageDir.exists()) {
|
||||||
Log.e(LOG_TAG, "Could not delete old $HOME/storage");
|
try {
|
||||||
return;
|
deleteFolder(storageDir);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "Could not delete old $HOME/storage, " + e.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!storageDir.mkdirs()) {
|
if (!storageDir.mkdirs()) {
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import android.content.Intent;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
|
||||||
@@ -17,6 +19,7 @@ import com.termux.terminal.EmulatorDebug;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class TermuxOpenReceiver extends BroadcastReceiver {
|
public class TermuxOpenReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
@@ -28,23 +31,10 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean isExternalUrl = data.getScheme() != null && !data.getScheme().equals("file");
|
|
||||||
if (isExternalUrl) {
|
|
||||||
Intent viewIntent = new Intent(Intent.ACTION_VIEW, data);
|
|
||||||
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
try {
|
|
||||||
context.startActivity(viewIntent);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "termux-open: No app handles the url " + data);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String filePath = data.getPath();
|
final String filePath = data.getPath();
|
||||||
final String contentTypeExtra = intent.getStringExtra("content-type");
|
final String contentTypeExtra = intent.getStringExtra("content-type");
|
||||||
final boolean useChooser = intent.getBooleanExtra("chooser", false);
|
final boolean useChooser = intent.getBooleanExtra("chooser", false);
|
||||||
final String intentAction = intent.getAction() == null ? Intent.ACTION_VIEW : intent.getAction();
|
final String intentAction = intent.getAction() == null ? Intent.ACTION_VIEW : intent.getAction();
|
||||||
|
|
||||||
switch (intentAction) {
|
switch (intentAction) {
|
||||||
case Intent.ACTION_SEND:
|
case Intent.ACTION_SEND:
|
||||||
case Intent.ACTION_VIEW:
|
case Intent.ACTION_VIEW:
|
||||||
@@ -55,6 +45,24 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final boolean isExternalUrl = data.getScheme() != null && !data.getScheme().equals("file");
|
||||||
|
if (isExternalUrl) {
|
||||||
|
Intent urlIntent = new Intent(intentAction, data);
|
||||||
|
if (intentAction.equals(Intent.ACTION_SEND)) {
|
||||||
|
urlIntent.putExtra(Intent.EXTRA_TEXT, data.toString());
|
||||||
|
urlIntent.setData(null);
|
||||||
|
} else if (contentTypeExtra != null) {
|
||||||
|
urlIntent.setDataAndType(data, contentTypeExtra);
|
||||||
|
}
|
||||||
|
urlIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
try {
|
||||||
|
context.startActivity(urlIntent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Log.e(EmulatorDebug.LOG_TAG, "termux-open: No app handles the url " + data);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final File fileToShare = new File(filePath);
|
final File fileToShare = new File(filePath);
|
||||||
if (!(fileToShare.isFile() && fileToShare.canRead())) {
|
if (!(fileToShare.isFile() && fileToShare.canRead())) {
|
||||||
Log.e(EmulatorDebug.LOG_TAG, "termux-open: Not a readable file: '" + fileToShare.getAbsolutePath() + "'");
|
Log.e(EmulatorDebug.LOG_TAG, "termux-open: Not a readable file: '" + fileToShare.getAbsolutePath() + "'");
|
||||||
@@ -106,7 +114,7 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||||
File file = new File(uri.getPath());
|
File file = new File(uri.getPath());
|
||||||
|
|
||||||
if (projection == null) {
|
if (projection == null) {
|
||||||
@@ -143,28 +151,38 @@ public class TermuxOpenReceiver extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(@NonNull Uri uri) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues values) {
|
public Uri insert(@NonNull Uri uri, ContentValues values) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
|
||||||
File file = new File(uri.getPath());
|
File file = new File(uri.getPath());
|
||||||
|
try {
|
||||||
|
String path = file.getCanonicalPath();
|
||||||
|
String storagePath = Environment.getExternalStorageDirectory().getCanonicalPath();
|
||||||
|
// See https://support.google.com/faqs/answer/7496913:
|
||||||
|
if (!(path.startsWith(TermuxService.FILES_PATH) || path.startsWith(storagePath))) {
|
||||||
|
throw new IllegalArgumentException("Invalid path: " + path);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,12 +32,10 @@ final class TermuxPreferences {
|
|||||||
private final int MIN_FONTSIZE;
|
private final int MIN_FONTSIZE;
|
||||||
private static final int MAX_FONTSIZE = 256;
|
private static final int MAX_FONTSIZE = 256;
|
||||||
|
|
||||||
private static final String FULLSCREEN_KEY = "fullscreen";
|
|
||||||
private static final String SHOW_EXTRA_KEYS_KEY = "show_extra_keys";
|
private static final String SHOW_EXTRA_KEYS_KEY = "show_extra_keys";
|
||||||
private static final String FONTSIZE_KEY = "fontsize";
|
private static final String FONTSIZE_KEY = "fontsize";
|
||||||
private static final String CURRENT_SESSION_KEY = "current_session";
|
private static final String CURRENT_SESSION_KEY = "current_session";
|
||||||
|
|
||||||
private boolean mFullScreen;
|
|
||||||
private int mFontSize;
|
private int mFontSize;
|
||||||
|
|
||||||
@AsciiBellBehaviour
|
@AsciiBellBehaviour
|
||||||
@@ -56,7 +54,6 @@ final class TermuxPreferences {
|
|||||||
// to prevent invisible text due to zoom be mistake:
|
// to prevent invisible text due to zoom be mistake:
|
||||||
MIN_FONTSIZE = (int) (4f * dipInPixels);
|
MIN_FONTSIZE = (int) (4f * dipInPixels);
|
||||||
|
|
||||||
mFullScreen = prefs.getBoolean(FULLSCREEN_KEY, false);
|
|
||||||
mShowExtraKeys = prefs.getBoolean(SHOW_EXTRA_KEYS_KEY, false);
|
mShowExtraKeys = prefs.getBoolean(SHOW_EXTRA_KEYS_KEY, false);
|
||||||
|
|
||||||
// http://www.google.com/design/spec/style/typography.html#typography-line-height
|
// http://www.google.com/design/spec/style/typography.html#typography-line-height
|
||||||
@@ -72,15 +69,6 @@ final class TermuxPreferences {
|
|||||||
mFontSize = Math.max(MIN_FONTSIZE, Math.min(mFontSize, MAX_FONTSIZE));
|
mFontSize = Math.max(MIN_FONTSIZE, Math.min(mFontSize, MAX_FONTSIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFullScreen() {
|
|
||||||
return mFullScreen;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setFullScreen(Context context, boolean newValue) {
|
|
||||||
mFullScreen = newValue;
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(FULLSCREEN_KEY, newValue).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean isShowExtraKeys() {
|
boolean isShowExtraKeys() {
|
||||||
return mShowExtraKeys;
|
return mShowExtraKeys;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.termux.app;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@@ -11,10 +12,10 @@ import android.content.res.Resources;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.support.v4.content.WakefulBroadcastReceiver;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
|
||||||
@@ -41,6 +42,8 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public final class TermuxService extends Service implements SessionChangedCallback {
|
public final class TermuxService extends Service implements SessionChangedCallback {
|
||||||
|
|
||||||
|
private static final String NOTIFICATION_CHANNEL_ID = "termux_notification_channel";
|
||||||
|
|
||||||
/** Note that this is a symlink on the Android M preview. */
|
/** Note that this is a symlink on the Android M preview. */
|
||||||
@SuppressLint("SdCardPath")
|
@SuppressLint("SdCardPath")
|
||||||
public static final String FILES_PATH = "/data/data/com.termux/files";
|
public static final String FILES_PATH = "/data/data/com.termux/files";
|
||||||
@@ -104,7 +107,8 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, EmulatorDebug.LOG_TAG);
|
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, EmulatorDebug.LOG_TAG);
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
|
|
||||||
WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
// http://tools.android.com/tech-docs/lint-in-studio-2-3#TOC-WifiManager-Leak
|
||||||
|
WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||||
mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, EmulatorDebug.LOG_TAG);
|
mWifiLock = wm.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, EmulatorDebug.LOG_TAG);
|
||||||
mWifiLock.acquire();
|
mWifiLock.acquire();
|
||||||
|
|
||||||
@@ -152,11 +156,6 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
Log.e(EmulatorDebug.LOG_TAG, "Unknown TermuxService action: '" + action + "'");
|
Log.e(EmulatorDebug.LOG_TAG, "Unknown TermuxService action: '" + action + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & START_FLAG_REDELIVERY) == 0) {
|
|
||||||
// Service is started by WBR, not restarted by system, so release the WakeLock from WBR.
|
|
||||||
WakefulBroadcastReceiver.completeWakefulIntent(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this service really do get killed, there is no point restarting it automatically - let the user do on next
|
// If this service really do get killed, there is no point restarting it automatically - let the user do on next
|
||||||
// start of {@link Term):
|
// start of {@link Term):
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
@@ -169,11 +168,12 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
|
setupNotificationChannel();
|
||||||
startForeground(NOTIFICATION_ID, buildNotification());
|
startForeground(NOTIFICATION_ID, buildNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the shown foreground service notification after making any changes that affect it. */
|
/** Update the shown foreground service notification after making any changes that affect it. */
|
||||||
private void updateNotification() {
|
void updateNotification() {
|
||||||
if (mWakeLock == null && mTerminalSessions.isEmpty() && mBackgroundTasks.isEmpty()) {
|
if (mWakeLock == null && mTerminalSessions.isEmpty() && mBackgroundTasks.isEmpty()) {
|
||||||
// Exit if we are updating after the user disabled all locks with no sessions or tasks running.
|
// Exit if we are updating after the user disabled all locks with no sessions or tasks running.
|
||||||
stopSelf();
|
stopSelf();
|
||||||
@@ -207,8 +207,8 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
builder.setOngoing(true);
|
builder.setOngoing(true);
|
||||||
|
|
||||||
// If holding a wake or wifi lock consider the notification of high priority since it's using power,
|
// If holding a wake or wifi lock consider the notification of high priority since it's using power,
|
||||||
// otherwise use a minimal priority since this is just a background service notification:
|
// otherwise use a low priority
|
||||||
builder.setPriority((wakeLockHeld) ? Notification.PRIORITY_HIGH : Notification.PRIORITY_MIN);
|
builder.setPriority((wakeLockHeld) ? Notification.PRIORITY_HIGH : Notification.PRIORITY_LOW);
|
||||||
|
|
||||||
// No need to show a timestamp:
|
// No need to show a timestamp:
|
||||||
builder.setShowWhen(false);
|
builder.setShowWhen(false);
|
||||||
@@ -216,6 +216,10 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
// Background color for small notification icon:
|
// Background color for small notification icon:
|
||||||
builder.setColor(0xFF000000);
|
builder.setColor(0xFF000000);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
builder.setChannelId(NOTIFICATION_CHANNEL_ID);
|
||||||
|
}
|
||||||
|
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
Intent exitIntent = new Intent(this, TermuxService.class).setAction(ACTION_STOP_SERVICE);
|
Intent exitIntent = new Intent(this, TermuxService.class).setAction(ACTION_STOP_SERVICE);
|
||||||
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));
|
builder.addAction(android.R.drawable.ic_delete, res.getString(R.string.notification_action_exit), PendingIntent.getService(this, 0, exitIntent, 0));
|
||||||
@@ -240,7 +244,6 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
|
|
||||||
for (int i = 0; i < mTerminalSessions.size(); i++)
|
for (int i = 0; i < mTerminalSessions.size(); i++)
|
||||||
mTerminalSessions.get(i).finishIfRunning();
|
mTerminalSessions.get(i).finishIfRunning();
|
||||||
mTerminalSessions.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TerminalSession> getSessions() {
|
public List<TerminalSession> getSessions() {
|
||||||
@@ -340,4 +343,17 @@ public final class TermuxService extends Service implements SessionChangedCallba
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupNotificationChannel() {
|
||||||
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return;
|
||||||
|
|
||||||
|
String channelName = "Termux";
|
||||||
|
String channelDescription = "Notifications from Termux";
|
||||||
|
int importance = NotificationManager.IMPORTANCE_LOW;
|
||||||
|
|
||||||
|
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName,importance);
|
||||||
|
channel.setDescription(channelDescription);
|
||||||
|
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
manager.createNotificationChannel(channel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,18 +12,18 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import com.termux.terminal.KeyHandler;
|
import com.termux.terminal.KeyHandler;
|
||||||
import com.termux.terminal.TerminalEmulator;
|
import com.termux.terminal.TerminalEmulator;
|
||||||
import com.termux.terminal.TerminalSession;
|
import com.termux.terminal.TerminalSession;
|
||||||
import com.termux.view.TerminalKeyListener;
|
import com.termux.view.TerminalViewClient;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class TermuxKeyListener implements TerminalKeyListener {
|
public final class TermuxViewClient implements TerminalViewClient {
|
||||||
|
|
||||||
final TermuxActivity mActivity;
|
final TermuxActivity mActivity;
|
||||||
|
|
||||||
/** Keeping track of the special keys acting as Ctrl and Fn for the soft keyboard and other hardware keys. */
|
/** Keeping track of the special keys acting as Ctrl and Fn for the soft keyboard and other hardware keys. */
|
||||||
boolean mVirtualControlKeyDown, mVirtualFnKeyDown;
|
boolean mVirtualControlKeyDown, mVirtualFnKeyDown;
|
||||||
|
|
||||||
public TermuxKeyListener(TermuxActivity activity) {
|
public TermuxViewClient(TermuxActivity activity) {
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,8 +73,6 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
mActivity.getDrawer().openDrawer(Gravity.LEFT);
|
mActivity.getDrawer().openDrawer(Gravity.LEFT);
|
||||||
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
|
} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
|
||||||
mActivity.getDrawer().closeDrawers();
|
mActivity.getDrawer().closeDrawers();
|
||||||
} else if (unicodeChar == 'f'/* full screen */) {
|
|
||||||
mActivity.toggleImmersive();
|
|
||||||
} else if (unicodeChar == 'k'/* keyboard */) {
|
} else if (unicodeChar == 'k'/* keyboard */) {
|
||||||
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
|
||||||
@@ -256,6 +254,11 @@ public final class TermuxKeyListener implements TerminalKeyListener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongPress(MotionEvent event) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/** Handle dedicated volume buttons as virtual keys if applicable. */
|
/** Handle dedicated volume buttons as virtual keys if applicable. */
|
||||||
private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
|
private boolean handleVirtualKeys(int keyCode, KeyEvent event, boolean down) {
|
||||||
InputDevice inputDevice = event.getDevice();
|
InputDevice inputDevice = event.getDevice();
|
||||||
@@ -195,7 +195,7 @@ public class TermuxDocumentsProvider extends DocumentsProvider {
|
|||||||
final String name = file.getName();
|
final String name = file.getName();
|
||||||
final int lastDot = name.lastIndexOf('.');
|
final int lastDot = name.lastIndexOf('.');
|
||||||
if (lastDot >= 0) {
|
if (lastDot >= 0) {
|
||||||
final String extension = name.substring(lastDot + 1);
|
final String extension = name.substring(lastDot + 1).toLowerCase();
|
||||||
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||||
if (mime != null) return mime;
|
if (mime != null) return mime;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
<!-- Screen border. -->
|
<!-- Screen border. -->
|
||||||
<path android:fillColor="#00000000"
|
<path android:fillColor="#00000000"
|
||||||
android:strokeColor="#000"
|
android:strokeColor="#FFF"
|
||||||
android:strokeWidth="3"
|
android:strokeWidth="3"
|
||||||
android:pathData="M7,4
|
android:pathData="M7,4
|
||||||
l34,0
|
l34,0
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- Block cursor. -->
|
<!-- Block cursor. -->
|
||||||
<path android:fillColor="#000"
|
<path android:fillColor="#FFF"
|
||||||
android:pathData="M14,14
|
android:pathData="M14,14
|
||||||
l5,0
|
l5,0
|
||||||
l0,10
|
l0,10
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
<android.support.v4.widget.DrawerLayout
|
<android.support.v4.widget.DrawerLayout
|
||||||
android:id="@+id/drawer_layout"
|
android:id="@+id/drawer_layout"
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
android:id="@+id/viewpager"
|
android:id="@+id/viewpager"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="75dp"
|
||||||
android:background="@android:drawable/screen_background_dark_transparent"
|
android:background="@android:drawable/screen_background_dark_transparent"
|
||||||
android:layout_alignParentBottom="true" />
|
android:layout_alignParentBottom="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
<string name="toggle_soft_keyboard">Keyboard</string>
|
<string name="toggle_soft_keyboard">Keyboard</string>
|
||||||
<string name="reset_terminal">Reset</string>
|
<string name="reset_terminal">Reset</string>
|
||||||
<string name="style_terminal">Style</string>
|
<string name="style_terminal">Style</string>
|
||||||
<string name="toggle_fullscreen">Fullscreen</string>
|
|
||||||
<string name="share_transcript_title">Terminal transcript</string>
|
<string name="share_transcript_title">Terminal transcript</string>
|
||||||
<string name="help">Help</string>
|
<string name="help">Help</string>
|
||||||
|
|
||||||
@@ -30,10 +29,6 @@
|
|||||||
<string name="select_url_copied_to_clipboard">URL copied to clipboard</string>
|
<string name="select_url_copied_to_clipboard">URL copied to clipboard</string>
|
||||||
<string name="share_transcript_chooser_title">Send text to:</string>
|
<string name="share_transcript_chooser_title">Send text to:</string>
|
||||||
|
|
||||||
<string name="paste_text">Paste</string>
|
|
||||||
<string name="copy_text">Copy</string>
|
|
||||||
<string name="text_selection_more">More…</string>
|
|
||||||
|
|
||||||
<string name="kill_process">Kill process (%d)</string>
|
<string name="kill_process">Kill process (%d)</string>
|
||||||
<string name="confirm_kill_process">Really kill this session?</string>
|
<string name="confirm_kill_process">Really kill this session?</string>
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,9 @@
|
|||||||
selecting text on pre-6.0 (non-floating toolbar). -->
|
selecting text on pre-6.0 (non-floating toolbar). -->
|
||||||
<item name="android:windowActionModeOverlay">true</item>
|
<item name="android:windowActionModeOverlay">true</item>
|
||||||
|
|
||||||
|
<item name="android:windowTranslucentStatus">true</item>
|
||||||
|
<item name="android:windowTranslucentNavigation">true</item>
|
||||||
|
|
||||||
<!-- https://developer.android.com/training/tv/start/start.html#transition-color -->
|
<!-- https://developer.android.com/training/tv/start/start.html#transition-color -->
|
||||||
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
||||||
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
- If adding text, use large font sizes.
|
- If adding text, use large font sizes.
|
||||||
- Your graphic may be displayed alone without the app icon.
|
- Your graphic may be displayed alone without the app icon.
|
||||||
-->
|
-->
|
||||||
<svg xmlns:svg="http://www.w3.org/2000/svg"
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
version="1.1"
|
version="1.1"
|
||||||
viewBox="0 0 1024 500">
|
viewBox="0 0 1024 500">
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1006 B After Width: | Height: | Size: 962 B |
@@ -7,8 +7,7 @@
|
|||||||
- Text must be included in the image. If your app is available in more
|
- Text must be included in the image. If your app is available in more
|
||||||
than one language, you must provide versions of the banner image for each supported language.
|
than one language, you must provide versions of the banner image for each supported language.
|
||||||
-->
|
-->
|
||||||
<svg xmlns:svg="http://www.w3.org/2000/svg"
|
<svg xmlns="http://www.w3.org/2000/svg"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
version="1.1"
|
version="1.1"
|
||||||
viewBox="0 0 1280 720">
|
viewBox="0 0 1280 720">
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 780 B After Width: | Height: | Size: 736 B |
@@ -1,16 +1,16 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
google()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
classpath 'com.android.tools.build:gradle:3.1.3'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
|
google()
|
||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,5 @@
|
|||||||
#Sun Dec 04 17:26:05 CET 2016
|
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip
|
|
||||||
|
|||||||
6
gradlew
vendored
@@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS=""
|
|||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD="maximum"
|
||||||
|
|
||||||
warn ( ) {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
die ( ) {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
@@ -155,7 +155,7 @@ if $cygwin ; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Escape application args
|
||||||
save ( ) {
|
save () {
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||||
echo " "
|
echo " "
|
||||||
}
|
}
|
||||||
|
|||||||
77
scripts/bintray-publish.gradle
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
// Start https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle
|
||||||
|
group = publishedGroupId // Maven Group ID for the artifact
|
||||||
|
install {
|
||||||
|
repositories.mavenInstaller {
|
||||||
|
pom {
|
||||||
|
project {
|
||||||
|
packaging 'aar'
|
||||||
|
groupId publishedGroupId
|
||||||
|
artifactId artifact
|
||||||
|
|
||||||
|
name libraryName
|
||||||
|
description libraryDescription
|
||||||
|
url siteUrl
|
||||||
|
|
||||||
|
licenses {
|
||||||
|
license {
|
||||||
|
name 'GNU General Public License version 3'
|
||||||
|
url 'https://opensource.org/licenses/gpl-3.0.html'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
developers {
|
||||||
|
developer {
|
||||||
|
id 'fornwall'
|
||||||
|
name 'Fredrik Fornwall'
|
||||||
|
email 'fredrik@fornwall.net'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scm {
|
||||||
|
connection gitUrl
|
||||||
|
developerConnection gitUrl
|
||||||
|
url siteUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// End https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle
|
||||||
|
|
||||||
|
// Start https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle
|
||||||
|
apply plugin: 'com.jfrog.bintray'
|
||||||
|
|
||||||
|
version = libraryVersion
|
||||||
|
|
||||||
|
task sourcesJar(type: Jar) {
|
||||||
|
classifier = 'sources'
|
||||||
|
from android.sourceSets.main.java.srcDirs
|
||||||
|
}
|
||||||
|
|
||||||
|
artifacts {
|
||||||
|
archives sourcesJar
|
||||||
|
}
|
||||||
|
|
||||||
|
bintray {
|
||||||
|
user = System.getenv('BINTRAY_USER')
|
||||||
|
key = System.getenv('BINTRAY_API_KEY')
|
||||||
|
|
||||||
|
configurations = ['archives']
|
||||||
|
pkg {
|
||||||
|
repo = 'maven'
|
||||||
|
name = bintrayName
|
||||||
|
userOrg = 'termux'
|
||||||
|
desc = libraryDescription
|
||||||
|
websiteUrl = siteUrl
|
||||||
|
vcsUrl = gitUrl
|
||||||
|
licenses = ['GPL-3.0']
|
||||||
|
publish = true
|
||||||
|
publicDownloadNumbers = true
|
||||||
|
version {
|
||||||
|
desc = libraryDescription
|
||||||
|
gpg {
|
||||||
|
sign = false //Determines whether to GPG sign the files. The default is false
|
||||||
|
// passphrase = properties.getProperty("bintray.gpg.password")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1 @@
|
|||||||
include ':app'
|
include ':app', ':terminal-emulator', ':terminal-view'
|
||||||
|
|||||||
61
terminal-emulator/build.gradle
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
plugins {
|
||||||
|
id "com.jfrog.bintray" version "1.7.3"
|
||||||
|
id "com.github.dcendents.android-maven" version "2.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
|
ext {
|
||||||
|
bintrayName = 'terminal-emulator'
|
||||||
|
publishedGroupId = 'com.termux'
|
||||||
|
libraryName = 'TerminalEmulator'
|
||||||
|
artifact = 'terminal-emulator'
|
||||||
|
libraryDescription = 'The terminal emulator used in Termux'
|
||||||
|
siteUrl = 'https://github.com/termux/termux'
|
||||||
|
gitUrl = 'https://github.com/termux/termux.git'
|
||||||
|
libraryVersion = '0.52'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 27
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 27
|
||||||
|
|
||||||
|
externalNativeBuild {
|
||||||
|
ndkBuild {
|
||||||
|
cFlags "-std=c11", "-Wall", "-Wextra", "-Werror", "-Os", "-fno-stack-protector", "-Wl,--gc-sections"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ndk {
|
||||||
|
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
externalNativeBuild {
|
||||||
|
ndkBuild {
|
||||||
|
path "src/main/jni/Android.mk"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(Test) {
|
||||||
|
testLogging {
|
||||||
|
events "started", "passed", "skipped", "failed"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: '../scripts/bintray-publish.gradle'
|
||||||
25
terminal-emulator/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# By default, the flags in this file are appended to flags specified
|
||||||
|
# in /Users/fornwall/lib/android-sdk/tools/proguard/proguard-android.txt
|
||||||
|
# You can edit the include path and order by changing the proguardFiles
|
||||||
|
# directive in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Add any project specific keep options here:
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
2
terminal-emulator/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<manifest package="com.termux.terminal">
|
||||||
|
</manifest>
|
||||||
@@ -3,7 +3,7 @@ package com.termux.terminal;
|
|||||||
/**
|
/**
|
||||||
* A circular buffer of {@link TerminalRow}:s which keeps notes about what is visible on a logical screen and the scroll
|
* A circular buffer of {@link TerminalRow}:s which keeps notes about what is visible on a logical screen and the scroll
|
||||||
* history.
|
* history.
|
||||||
* <p/>
|
* <p>
|
||||||
* See {@link #externalToInternalRow(int)} for how to map from logical screen rows to array indices.
|
* See {@link #externalToInternalRow(int)} for how to map from logical screen rows to array indices.
|
||||||
*/
|
*/
|
||||||
public final class TerminalBuffer {
|
public final class TerminalBuffer {
|
||||||
@@ -92,22 +92,20 @@ public final class TerminalBuffer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a row value from the public external coordinate system to our internal private coordinate system.
|
* Convert a row value from the public external coordinate system to our internal private coordinate system.
|
||||||
* <p/>
|
*
|
||||||
* <ul>
|
|
||||||
* <li>External coordinate system: -mActiveTranscriptRows to mScreenRows-1, with the screen being 0..mScreenRows-1.
|
|
||||||
* <li>Internal coordinate system: the mScreenRows lines starting at mScreenFirstRow comprise the screen, while the
|
|
||||||
* mActiveTranscriptRows lines ending at mScreenFirstRow-1 form the transcript (as a circular buffer).
|
|
||||||
* </ul>
|
|
||||||
* <p/>
|
|
||||||
* External <---> Internal:
|
|
||||||
* <p/>
|
|
||||||
* <pre>
|
* <pre>
|
||||||
* [ ... ] [ ... ]
|
* - External coordinate system: -mActiveTranscriptRows to mScreenRows-1, with the screen being 0..mScreenRows-1.
|
||||||
* [ -mActiveTranscriptRows ] [ mScreenFirstRow - mActiveTranscriptRows ]
|
* - Internal coordinate system: the mScreenRows lines starting at mScreenFirstRow comprise the screen, while the
|
||||||
* [ ... ] [ ... ]
|
* mActiveTranscriptRows lines ending at mScreenFirstRow-1 form the transcript (as a circular buffer).
|
||||||
* [ 0 (visible screen starts here) ] <-----> [ mScreenFirstRow ]
|
*
|
||||||
* [ ... ] [ ... ]
|
* External ↔ Internal:
|
||||||
* [ mScreenRows-1 ] [ mScreenFirstRow + mScreenRows-1 ]
|
*
|
||||||
|
* [ ... ] [ ... ]
|
||||||
|
* [ -mActiveTranscriptRows ] [ mScreenFirstRow - mActiveTranscriptRows ]
|
||||||
|
* [ ... ] [ ... ]
|
||||||
|
* [ 0 (visible screen starts here) ] ↔ [ mScreenFirstRow ]
|
||||||
|
* [ ... ] [ ... ]
|
||||||
|
* [ mScreenRows-1 ] [ mScreenFirstRow + mScreenRows-1 ]
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param externalRow a row in the external coordinate system.
|
* @param externalRow a row in the external coordinate system.
|
||||||
@@ -56,8 +56,6 @@ public final class TerminalEmulator {
|
|||||||
private static final int ESC_SELECT_LEFT_PAREN = 3;
|
private static final int ESC_SELECT_LEFT_PAREN = 3;
|
||||||
/** Escape processing: Have seen ESC and a character-set-select ) char */
|
/** Escape processing: Have seen ESC and a character-set-select ) char */
|
||||||
private static final int ESC_SELECT_RIGHT_PAREN = 4;
|
private static final int ESC_SELECT_RIGHT_PAREN = 4;
|
||||||
/** Escape processing: Have seen ESC and a character-set-select + char */
|
|
||||||
// private static final int ESC_SELECT_PLUS = 5;
|
|
||||||
/** Escape processing: "ESC [" or CSI (Control Sequence Introducer). */
|
/** Escape processing: "ESC [" or CSI (Control Sequence Introducer). */
|
||||||
private static final int ESC_CSI = 6;
|
private static final int ESC_CSI = 6;
|
||||||
/** Escape processing: ESC [ ? */
|
/** Escape processing: ESC [ ? */
|
||||||
@@ -225,6 +223,7 @@ public final class TerminalEmulator {
|
|||||||
|
|
||||||
private byte mUtf8ToFollow, mUtf8Index;
|
private byte mUtf8ToFollow, mUtf8Index;
|
||||||
private final byte[] mUtf8InputBuffer = new byte[4];
|
private final byte[] mUtf8InputBuffer = new byte[4];
|
||||||
|
private int mLastEmittedCodePoint = -1;
|
||||||
|
|
||||||
public final TerminalColors mColors = new TerminalColors();
|
public final TerminalColors mColors = new TerminalColors();
|
||||||
|
|
||||||
@@ -302,6 +301,11 @@ public final class TerminalEmulator {
|
|||||||
* @param mouseButton one of the MOUSE_* constants of this class.
|
* @param mouseButton one of the MOUSE_* constants of this class.
|
||||||
*/
|
*/
|
||||||
public void sendMouseEvent(int mouseButton, int column, int row, boolean pressed) {
|
public void sendMouseEvent(int mouseButton, int column, int row, boolean pressed) {
|
||||||
|
if (column < 1) column = 1;
|
||||||
|
if (column > mColumns) column = mColumns;
|
||||||
|
if (row < 1) row = 1;
|
||||||
|
if (row > mRows) row = mRows;
|
||||||
|
|
||||||
if (mouseButton == MOUSE_LEFT_BUTTON_MOVED && !isDecsetInternalBitSet(DECSET_BIT_MOUSE_TRACKING_BUTTON_EVENT)) {
|
if (mouseButton == MOUSE_LEFT_BUTTON_MOVED && !isDecsetInternalBitSet(DECSET_BIT_MOUSE_TRACKING_BUTTON_EVENT)) {
|
||||||
// Do not send tracking.
|
// Do not send tracking.
|
||||||
} else if (isDecsetInternalBitSet(DECSET_BIT_MOUSE_PROTOCOL_SGR)) {
|
} else if (isDecsetInternalBitSet(DECSET_BIT_MOUSE_PROTOCOL_SGR)) {
|
||||||
@@ -309,7 +313,7 @@ public final class TerminalEmulator {
|
|||||||
} else {
|
} else {
|
||||||
mouseButton = pressed ? mouseButton : 3; // 3 for release of all buttons.
|
mouseButton = pressed ? mouseButton : 3; // 3 for release of all buttons.
|
||||||
// Clip to screen, and clip to the limits of 8-bit data.
|
// Clip to screen, and clip to the limits of 8-bit data.
|
||||||
boolean out_of_bounds = column < 1 || row < 1 || column > mColumns || row > mRows || column > 255 - 32 || row > 255 - 32;
|
boolean out_of_bounds = column > 255 - 32 || row > 255 - 32;
|
||||||
if (!out_of_bounds) {
|
if (!out_of_bounds) {
|
||||||
byte[] data = {'\033', '[', 'M', (byte) (32 + mouseButton), (byte) (32 + column), (byte) (32 + row)};
|
byte[] data = {'\033', '[', 'M', (byte) (32 + mouseButton), (byte) (32 + column), (byte) (32 + row)};
|
||||||
mSession.write(data, 0, data.length);
|
mSession.write(data, 0, data.length);
|
||||||
@@ -421,10 +425,11 @@ public final class TerminalEmulator {
|
|||||||
mUtf8Index = mUtf8ToFollow = 0;
|
mUtf8Index = mUtf8ToFollow = 0;
|
||||||
|
|
||||||
if (codePoint >= 0x80 && codePoint <= 0x9F) {
|
if (codePoint >= 0x80 && codePoint <= 0x9F) {
|
||||||
// Sequence decoded to a C1 control character which is the same as escape followed by
|
// Sequence decoded to a C1 control character which we ignore. They are
|
||||||
// ((code & 0x7F) + 0x40).
|
// not used nowadays and increases the risk of messing up the terminal state
|
||||||
processCodePoint(/* escape (hexadecimal=0x1B, octal=033): */27);
|
// on binary input. XTerm does not allow them in utf-8:
|
||||||
processCodePoint((codePoint & 0x7F) + 0x40);
|
// "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 {
|
} else {
|
||||||
switch (Character.getType(codePoint)) {
|
switch (Character.getType(codePoint)) {
|
||||||
case Character.UNASSIGNED:
|
case Character.UNASSIGNED:
|
||||||
@@ -634,6 +639,7 @@ public final class TerminalEmulator {
|
|||||||
int bottom = Math.min(getArg(2, mRows, true) + 1, effectiveBottomMargin - 1) + effectiveTopMargin;
|
int bottom = Math.min(getArg(2, mRows, true) + 1, effectiveBottomMargin - 1) + effectiveTopMargin;
|
||||||
int right = Math.min(getArg(3, mColumns, true) + 1, effectiveRightMargin - 1) + effectiveLeftMargin;
|
int right = Math.min(getArg(3, mColumns, true) + 1, effectiveRightMargin - 1) + effectiveLeftMargin;
|
||||||
if (mArgIndex >= 4) {
|
if (mArgIndex >= 4) {
|
||||||
|
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
|
||||||
for (int i = 4; i <= mArgIndex; i++) {
|
for (int i = 4; i <= mArgIndex; i++) {
|
||||||
int bits = 0;
|
int bits = 0;
|
||||||
boolean setOrClear = true; // True if setting, false if clearing.
|
boolean setOrClear = true; // True if setting, false if clearing.
|
||||||
@@ -967,6 +973,7 @@ public final class TerminalEmulator {
|
|||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
case 'l':
|
case 'l':
|
||||||
|
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
|
||||||
for (int i = 0; i <= mArgIndex; i++)
|
for (int i = 0; i <= mArgIndex; i++)
|
||||||
doDecSetOrReset(b == 'h', mArgs[i]);
|
doDecSetOrReset(b == 'h', mArgs[i]);
|
||||||
break;
|
break;
|
||||||
@@ -983,6 +990,7 @@ public final class TerminalEmulator {
|
|||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
case 's':
|
case 's':
|
||||||
|
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
|
||||||
for (int i = 0; i <= mArgIndex; i++) {
|
for (int i = 0; i <= mArgIndex; i++) {
|
||||||
int externalBit = mArgs[i];
|
int externalBit = mArgs[i];
|
||||||
int internalBit = mapDecSetBitToInternalBit(externalBit);
|
int internalBit = mapDecSetBitToInternalBit(externalBit);
|
||||||
@@ -1189,12 +1197,20 @@ public final class TerminalEmulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void doLinefeed() {
|
private void doLinefeed() {
|
||||||
|
boolean belowScrollingRegion = mCursorRow >= mBottomMargin;
|
||||||
int newCursorRow = mCursorRow + 1;
|
int newCursorRow = mCursorRow + 1;
|
||||||
if (newCursorRow >= mBottomMargin) {
|
if (belowScrollingRegion) {
|
||||||
scrollDownOneLine();
|
// Move down (but not scroll) as long as we are above the last row.
|
||||||
newCursorRow = mBottomMargin - 1;
|
if (mCursorRow != mRows - 1) {
|
||||||
|
setCursorRow(newCursorRow);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (newCursorRow == mBottomMargin) {
|
||||||
|
scrollDownOneLine();
|
||||||
|
newCursorRow = mBottomMargin - 1;
|
||||||
|
}
|
||||||
|
setCursorRow(newCursorRow);
|
||||||
}
|
}
|
||||||
setCursorRow(newCursorRow);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void continueSequence(int state) {
|
private void continueSequence(int state) {
|
||||||
@@ -1309,6 +1325,8 @@ public final class TerminalEmulator {
|
|||||||
state.mSavedCursorRow = mCursorRow;
|
state.mSavedCursorRow = mCursorRow;
|
||||||
state.mSavedCursorCol = mCursorCol;
|
state.mSavedCursorCol = mCursorCol;
|
||||||
state.mSavedEffect = mEffect;
|
state.mSavedEffect = mEffect;
|
||||||
|
state.mSavedForeColor = mForeColor;
|
||||||
|
state.mSavedBackColor = mBackColor;
|
||||||
state.mSavedDecFlags = mCurrentDecSetFlags;
|
state.mSavedDecFlags = mCurrentDecSetFlags;
|
||||||
state.mUseLineDrawingG0 = mUseLineDrawingG0;
|
state.mUseLineDrawingG0 = mUseLineDrawingG0;
|
||||||
state.mUseLineDrawingG1 = mUseLineDrawingG1;
|
state.mUseLineDrawingG1 = mUseLineDrawingG1;
|
||||||
@@ -1320,6 +1338,8 @@ public final class TerminalEmulator {
|
|||||||
SavedScreenState state = (mScreen == mMainBuffer) ? mSavedStateMain : mSavedStateAlt;
|
SavedScreenState state = (mScreen == mMainBuffer) ? mSavedStateMain : mSavedStateAlt;
|
||||||
setCursorRowCol(state.mSavedCursorRow, state.mSavedCursorCol);
|
setCursorRowCol(state.mSavedCursorRow, state.mSavedCursorCol);
|
||||||
mEffect = state.mSavedEffect;
|
mEffect = state.mSavedEffect;
|
||||||
|
mForeColor = state.mSavedForeColor;
|
||||||
|
mBackColor = state.mSavedBackColor;
|
||||||
int mask = (DECSET_BIT_AUTOWRAP | DECSET_BIT_ORIGIN_MODE);
|
int mask = (DECSET_BIT_AUTOWRAP | DECSET_BIT_ORIGIN_MODE);
|
||||||
mCurrentDecSetFlags = (mCurrentDecSetFlags & ~mask) | (state.mSavedDecFlags & mask);
|
mCurrentDecSetFlags = (mCurrentDecSetFlags & ~mask) | (state.mSavedDecFlags & mask);
|
||||||
mUseLineDrawingG0 = state.mUseLineDrawingG0;
|
mUseLineDrawingG0 = state.mUseLineDrawingG0;
|
||||||
@@ -1503,6 +1523,11 @@ public final class TerminalEmulator {
|
|||||||
case '`': // Horizontal position absolute (HPA - http://www.vt100.net/docs/vt510-rm/HPA).
|
case '`': // Horizontal position absolute (HPA - http://www.vt100.net/docs/vt510-rm/HPA).
|
||||||
setCursorColRespectingOriginMode(getArg0(1) - 1);
|
setCursorColRespectingOriginMode(getArg0(1) - 1);
|
||||||
break;
|
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.
|
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)
|
// 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".
|
// is the first response parameter identifying the terminal service class, where we send 64 for "vt420".
|
||||||
@@ -1559,7 +1584,7 @@ public final class TerminalEmulator {
|
|||||||
break;
|
break;
|
||||||
case 'r': // "CSI${top};${bottom}r" - set top and bottom Margins (DECSTBM).
|
case 'r': // "CSI${top};${bottom}r" - set top and bottom Margins (DECSTBM).
|
||||||
{
|
{
|
||||||
// http://www.vt100.net/docs/vt510-rm/DECSTBM
|
// https://vt100.net/docs/vt510-rm/DECSTBM.html
|
||||||
// The top margin defaults to 1, the bottom margin defaults to mRows.
|
// The top margin defaults to 1, the bottom margin defaults to mRows.
|
||||||
// The escape sequence numbers top 1..23, but we number top 0..22.
|
// The escape sequence numbers top 1..23, but we number top 0..22.
|
||||||
// The escape sequence numbers bottom 2..24, and so do we (because we use a zero based numbering
|
// The escape sequence numbers bottom 2..24, and so do we (because we use a zero based numbering
|
||||||
@@ -1568,6 +1593,7 @@ public final class TerminalEmulator {
|
|||||||
// Also require that top + 2 <= bottom.
|
// Also require that top + 2 <= bottom.
|
||||||
mTopMargin = Math.max(0, Math.min(getArg0(1) - 1, mRows - 2));
|
mTopMargin = Math.max(0, Math.min(getArg0(1) - 1, mRows - 2));
|
||||||
mBottomMargin = Math.max(mTopMargin + 2, Math.min(getArg1(mRows), mRows));
|
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.
|
// DECSTBM moves the cursor to column 1, line 1 of the page respecting origin mode.
|
||||||
setCursorPosition(0, 0);
|
setCursorPosition(0, 0);
|
||||||
}
|
}
|
||||||
@@ -1641,6 +1667,7 @@ public final class TerminalEmulator {
|
|||||||
|
|
||||||
/** Select Graphic Rendition (SGR) - see http://en.wikipedia.org/wiki/ANSI_escape_code#graphics. */
|
/** Select Graphic Rendition (SGR) - see http://en.wikipedia.org/wiki/ANSI_escape_code#graphics. */
|
||||||
private void selectGraphicRendition() {
|
private void selectGraphicRendition() {
|
||||||
|
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
|
||||||
for (int i = 0; i <= mArgIndex; i++) {
|
for (int i = 0; i <= mArgIndex; i++) {
|
||||||
int code = mArgs[i];
|
int code = mArgs[i];
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
@@ -2051,6 +2078,7 @@ public final class TerminalEmulator {
|
|||||||
buf.append(", escapeState=");
|
buf.append(", escapeState=");
|
||||||
buf.append(mEscapeState);
|
buf.append(mEscapeState);
|
||||||
boolean firstArg = true;
|
boolean firstArg = true;
|
||||||
|
if (mArgIndex >= mArgs.length) mArgIndex = mArgs.length - 1;
|
||||||
for (int i = 0; i <= mArgIndex; i++) {
|
for (int i = 0; i <= mArgIndex; i++) {
|
||||||
int value = mArgs[i];
|
int value = mArgs[i];
|
||||||
if (value >= 0) {
|
if (value >= 0) {
|
||||||
@@ -2083,6 +2111,7 @@ public final class TerminalEmulator {
|
|||||||
* @param codePoint The code point of the character to display
|
* @param codePoint The code point of the character to display
|
||||||
*/
|
*/
|
||||||
private void emitCodePoint(int codePoint) {
|
private void emitCodePoint(int codePoint) {
|
||||||
|
mLastEmittedCodePoint = codePoint;
|
||||||
if (mUseLineDrawingUsesG0 ? mUseLineDrawingG0 : mUseLineDrawingG1) {
|
if (mUseLineDrawingUsesG0 ? mUseLineDrawingG0 : mUseLineDrawingG1) {
|
||||||
// http://www.vt100.net/docs/vt102-ug/table5-15.html.
|
// http://www.vt100.net/docs/vt102-ug/table5-15.html.
|
||||||
switch (codePoint) {
|
switch (codePoint) {
|
||||||
@@ -2265,8 +2294,8 @@ public final class TerminalEmulator {
|
|||||||
mBottomMargin = mRows;
|
mBottomMargin = mRows;
|
||||||
mRightMargin = mColumns;
|
mRightMargin = mColumns;
|
||||||
mAboutToAutoWrap = false;
|
mAboutToAutoWrap = false;
|
||||||
mForeColor = TextStyle.COLOR_INDEX_FOREGROUND;
|
mForeColor = mSavedStateMain.mSavedForeColor = mSavedStateAlt.mSavedForeColor = TextStyle.COLOR_INDEX_FOREGROUND;
|
||||||
mBackColor = TextStyle.COLOR_INDEX_BACKGROUND;
|
mBackColor = mSavedStateMain.mSavedBackColor = mSavedStateAlt.mSavedBackColor = TextStyle.COLOR_INDEX_BACKGROUND;
|
||||||
setDefaultTabStops();
|
setDefaultTabStops();
|
||||||
|
|
||||||
mUseLineDrawingG0 = mUseLineDrawingG1 = false;
|
mUseLineDrawingG0 = mUseLineDrawingG1 = false;
|
||||||
@@ -2309,6 +2338,9 @@ public final class TerminalEmulator {
|
|||||||
public void paste(String text) {
|
public void paste(String text) {
|
||||||
// First: Always remove escape key and C1 control characters [0x80,0x9F]:
|
// First: Always remove escape key and C1 control characters [0x80,0x9F]:
|
||||||
text = text.replaceAll("(\u001B|[\u0080-\u009F])", "");
|
text = text.replaceAll("(\u001B|[\u0080-\u009F])", "");
|
||||||
|
// Second: Replace all newlines (\n) or CRLF (\r\n) with carriage returns (\r).
|
||||||
|
text = text.replaceAll("\r?\n", "\r");
|
||||||
|
|
||||||
// Then: Implement bracketed paste mode if enabled:
|
// Then: Implement bracketed paste mode if enabled:
|
||||||
boolean bracketed = isDecsetInternalBitSet(DECSET_BIT_BRACKETED_PASTE_MODE);
|
boolean bracketed = isDecsetInternalBitSet(DECSET_BIT_BRACKETED_PASTE_MODE);
|
||||||
if (bracketed) mSession.write("\033[200~");
|
if (bracketed) mSession.write("\033[200~");
|
||||||
@@ -2320,7 +2352,7 @@ public final class TerminalEmulator {
|
|||||||
static final class SavedScreenState {
|
static final class SavedScreenState {
|
||||||
/** Saved state of the cursor position, Used to implement the save/restore cursor position escape sequences. */
|
/** Saved state of the cursor position, Used to implement the save/restore cursor position escape sequences. */
|
||||||
int mSavedCursorRow, mSavedCursorCol;
|
int mSavedCursorRow, mSavedCursorCol;
|
||||||
int mSavedEffect;
|
int mSavedEffect, mSavedForeColor, mSavedBackColor;
|
||||||
int mSavedDecFlags;
|
int mSavedDecFlags;
|
||||||
boolean mUseLineDrawingG0, mUseLineDrawingG1, mUseLineDrawingUsesG0 = true;
|
boolean mUseLineDrawingG0, mUseLineDrawingG1, mUseLineDrawingUsesG0 = true;
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A row in a terminal, composed of a fixed number of cells.
|
* A row in a terminal, composed of a fixed number of cells.
|
||||||
* <p/>
|
* <p>
|
||||||
* The text in the row is stored in a char[] array, {@link #mText}, for quick access during rendering.
|
* The text in the row is stored in a char[] array, {@link #mText}, for quick access during rendering.
|
||||||
*/
|
*/
|
||||||
public final class TerminalRow {
|
public final class TerminalRow {
|
||||||
@@ -21,6 +21,8 @@ public final class TerminalRow {
|
|||||||
boolean mLineWrap;
|
boolean mLineWrap;
|
||||||
/** The style bits of each cell in the row. See {@link TextStyle}. */
|
/** The style bits of each cell in the row. See {@link TextStyle}. */
|
||||||
final long[] mStyle;
|
final long[] mStyle;
|
||||||
|
/** If this row might contain chars with width != 1, used for deactivating fast path */
|
||||||
|
boolean mHasNonOneWidthOrSurrogateChars;
|
||||||
|
|
||||||
/** Construct a blank row (containing only whitespace, ' ') with a specified style. */
|
/** Construct a blank row (containing only whitespace, ' ') with a specified style. */
|
||||||
public TerminalRow(int columns, long style) {
|
public TerminalRow(int columns, long style) {
|
||||||
@@ -32,6 +34,7 @@ public final class TerminalRow {
|
|||||||
|
|
||||||
/** NOTE: The sourceX2 is exclusive. */
|
/** NOTE: The sourceX2 is exclusive. */
|
||||||
public void copyInterval(TerminalRow line, int sourceX1, int sourceX2, int destinationX) {
|
public void copyInterval(TerminalRow line, int sourceX1, int sourceX2, int destinationX) {
|
||||||
|
mHasNonOneWidthOrSurrogateChars |= line.mHasNonOneWidthOrSurrogateChars;
|
||||||
final int x1 = line.findStartOfColumn(sourceX1);
|
final int x1 = line.findStartOfColumn(sourceX1);
|
||||||
final int x2 = line.findStartOfColumn(sourceX2);
|
final int x2 = line.findStartOfColumn(sourceX2);
|
||||||
boolean startingFromSecondHalfOfWideChar = (sourceX1 > 0 && line.wideDisplayCharacterStartingAt(sourceX1 - 1));
|
boolean startingFromSecondHalfOfWideChar = (sourceX1 > 0 && line.wideDisplayCharacterStartingAt(sourceX1 - 1));
|
||||||
@@ -116,6 +119,7 @@ public final class TerminalRow {
|
|||||||
Arrays.fill(mText, ' ');
|
Arrays.fill(mText, ' ');
|
||||||
Arrays.fill(mStyle, style);
|
Arrays.fill(mStyle, style);
|
||||||
mSpaceUsed = (short) mColumns;
|
mSpaceUsed = (short) mColumns;
|
||||||
|
mHasNonOneWidthOrSurrogateChars = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
|
// https://github.com/steven676/Android-Terminal-Emulator/commit/9a47042620bec87617f0b4f5d50568535668fe26
|
||||||
@@ -123,6 +127,17 @@ public final class TerminalRow {
|
|||||||
mStyle[columnToSet] = style;
|
mStyle[columnToSet] = style;
|
||||||
|
|
||||||
final int newCodePointDisplayWidth = WcWidth.width(codePoint);
|
final int newCodePointDisplayWidth = WcWidth.width(codePoint);
|
||||||
|
|
||||||
|
// Fast path when we don't have any chars with width != 1
|
||||||
|
if (!mHasNonOneWidthOrSurrogateChars) {
|
||||||
|
if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT || newCodePointDisplayWidth != 1) {
|
||||||
|
mHasNonOneWidthOrSurrogateChars = true;
|
||||||
|
} else {
|
||||||
|
mText[columnToSet] = (char) codePoint;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final boolean newIsCombining = newCodePointDisplayWidth <= 0;
|
final boolean newIsCombining = newCodePointDisplayWidth <= 0;
|
||||||
|
|
||||||
boolean wasExtraColForWideChar = (columnToSet > 0) && wideDisplayCharacterStartingAt(columnToSet - 1);
|
boolean wasExtraColForWideChar = (columnToSet > 0) && wideDisplayCharacterStartingAt(columnToSet - 1);
|
||||||
@@ -19,13 +19,13 @@ import java.util.UUID;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A terminal session, consisting of a process coupled to a terminal interface.
|
* A terminal session, consisting of a process coupled to a terminal interface.
|
||||||
* <p/>
|
* <p>
|
||||||
* The subprocess will be executed by the constructor, and when the size is made known by a call to
|
* The subprocess will be executed by the constructor, and when the size is made known by a call to
|
||||||
* {@link #updateSize(int, int)} terminal emulation will begin and threads will be spawned to handle the subprocess I/O.
|
* {@link #updateSize(int, int)} terminal emulation will begin and threads will be spawned to handle the subprocess I/O.
|
||||||
* All terminal emulation and callback methods will be performed on the main thread.
|
* All terminal emulation and callback methods will be performed on the main thread.
|
||||||
* <p/>
|
* <p>
|
||||||
* The child process may be exited forcefully by using the {@link #finishIfRunning()} method.
|
* The child process may be exited forcefully by using the {@link #finishIfRunning()} method.
|
||||||
* <p/>
|
* <p>
|
||||||
* NOTE: The terminal session may outlive the EmulatorView, so be careful with callbacks!
|
* NOTE: The terminal session may outlive the EmulatorView, so be careful with callbacks!
|
||||||
*/
|
*/
|
||||||
public final class TerminalSession extends TerminalOutput {
|
public final class TerminalSession extends TerminalOutput {
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.termux.terminal;
|
package com.termux.terminal;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* <p>
|
||||||
* Encodes effects, foreground and background colors into a 64 bit long, which are stored for each cell in a terminal
|
* Encodes effects, foreground and background colors into a 64 bit long, which are stored for each cell in a terminal
|
||||||
* row in {@link TerminalRow#mStyle}.
|
* row in {@link TerminalRow#mStyle}.
|
||||||
* <p/>
|
* </p>
|
||||||
|
* <p>
|
||||||
* The bit layout is:
|
* The bit layout is:
|
||||||
|
* </p>
|
||||||
* - 16 flags (11 currently used).
|
* - 16 flags (11 currently used).
|
||||||
* - 24 for foreground color (only 9 first bits if a color index).
|
* - 24 for foreground color (only 9 first bits if a color index).
|
||||||
* - 24 for background color (only 9 first bits if a color index).
|
* - 24 for background color (only 9 first bits if a color index).
|
||||||
@@ -20,9 +23,10 @@ public final class TextStyle {
|
|||||||
public final static int CHARACTER_ATTRIBUTE_STRIKETHROUGH = 1 << 6;
|
public final static int CHARACTER_ATTRIBUTE_STRIKETHROUGH = 1 << 6;
|
||||||
/**
|
/**
|
||||||
* The selective erase control functions (DECSED and DECSEL) can only erase characters defined as erasable.
|
* The selective erase control functions (DECSED and DECSEL) can only erase characters defined as erasable.
|
||||||
* <p/>
|
* <p>
|
||||||
* This bit is set if DECSCA (Select Character Protection Attribute) has been used to define the characters that
|
* This bit is set if DECSCA (Select Character Protection Attribute) has been used to define the characters that
|
||||||
* come after it as erasable from the screen.
|
* come after it as erasable from the screen.
|
||||||
|
* </p>
|
||||||
*/
|
*/
|
||||||
public final static int CHARACTER_ATTRIBUTE_PROTECTED = 1 << 7;
|
public final static int CHARACTER_ATTRIBUTE_PROTECTED = 1 << 7;
|
||||||
/** Dim colors. Also known as faint or half intensity. */
|
/** Dim colors. Also known as faint or half intensity. */
|
||||||
@@ -29,4 +29,21 @@ public class ControlSequenceIntroducerTest extends TerminalTestCase {
|
|||||||
withTerminalSized(13, 2).enterString("abcdefghijkl\b\b\b\b\b\033[20X").assertLinesAre("abcdefg ", " ");
|
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", " ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -227,4 +227,44 @@ public class CursorAndScreenTest extends TerminalTestCase {
|
|||||||
withTerminalSized(3, 3).enterString("\b\b\b\bhi").assertLinesAre("hi ", " ", " ");
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -98,4 +98,13 @@ public class ScrollRegionTest extends TerminalTestCase {
|
|||||||
withTerminalSized(2, 5).enterString("1\r\n2\r\n3\r\n4\r\n5").assertLinesAre("1 ", "2 ", "3 ", "4 ", "5 ");
|
withTerminalSized(2, 5).enterString("1\r\n2\r\n3\r\n4\r\n5").assertLinesAre("1 ", "2 ", "3 ", "4 ", "5 ");
|
||||||
enterString("\033[3r").enterString("\033[2T").assertLinesAre("1 ", "2 ", " ", " ", "3 ");
|
enterString("\033[3r").enterString("\033[2T").assertLinesAre("1 ", "2 ", " ", " ", "3 ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testScrollDownBelowScrollRegion() {
|
||||||
|
withTerminalSized(2, 5).enterString("1\r\n2\r\n3\r\n4\r\n5").assertLinesAre("1 ", "2 ", "3 ", "4 ", "5 ");
|
||||||
|
enterString("\033[1;3r"); // DECSTBM margins.
|
||||||
|
enterString("\033[4;1H"); // Place cursor just below bottom margin.
|
||||||
|
enterString("QQ\r\nRR\r\n\r\n\r\nYY");
|
||||||
|
assertLinesAre("1 ", "2 ", "3 ", "QQ", "YY");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,7 @@ public class TerminalRowTest extends TestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
row = new TerminalRow(COLUMNS, TextStyle.NORMAL);
|
row = new TerminalRow(COLUMNS, TextStyle.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,6 +55,14 @@ public class TerminalTest extends TerminalTestCase {
|
|||||||
assertEquals("\033[<0;3;4M", mOutput.getOutputAndClear());
|
assertEquals("\033[<0;3;4M", mOutput.getOutputAndClear());
|
||||||
mTerminal.sendMouseEvent(TerminalEmulator.MOUSE_LEFT_BUTTON, 3, 4, false);
|
mTerminal.sendMouseEvent(TerminalEmulator.MOUSE_LEFT_BUTTON, 3, 4, false);
|
||||||
assertEquals("\033[<0;3;4m", mOutput.getOutputAndClear());
|
assertEquals("\033[<0;3;4m", mOutput.getOutputAndClear());
|
||||||
|
|
||||||
|
// When the client says that a click is outside (which could happen when pixels are outside
|
||||||
|
// the terminal area, see https://github.com/termux/termux-app/issues/501) the terminal
|
||||||
|
// sends a click at the edge.
|
||||||
|
mTerminal.sendMouseEvent(TerminalEmulator.MOUSE_LEFT_BUTTON, 0, 0, true);
|
||||||
|
assertEquals("\033[<0;1;1M", mOutput.getOutputAndClear());
|
||||||
|
mTerminal.sendMouseEvent(TerminalEmulator.MOUSE_LEFT_BUTTON, 11, 11, false);
|
||||||
|
assertEquals("\033[<0;10;10m", mOutput.getOutputAndClear());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNormalization() throws UnsupportedEncodingException {
|
public void testNormalization() throws UnsupportedEncodingException {
|
||||||
@@ -103,6 +103,7 @@ public abstract class TerminalTestCase extends TestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
mOutput = new MockTerminalOutput();
|
mOutput = new MockTerminalOutput();
|
||||||
}
|
}
|
||||||
|
|
||||||
45
terminal-view/build.gradle
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
plugins {
|
||||||
|
id "com.jfrog.bintray" version "1.7.3"
|
||||||
|
id "com.github.dcendents.android-maven" version "2.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'com.android.library'
|
||||||
|
|
||||||
|
ext {
|
||||||
|
bintrayName = 'terminal-view'
|
||||||
|
publishedGroupId = 'com.termux'
|
||||||
|
libraryName = 'TerminalView'
|
||||||
|
artifact = 'terminal-view'
|
||||||
|
libraryDescription = 'The terminal view used in Termux'
|
||||||
|
siteUrl = 'https://github.com/termux/termux'
|
||||||
|
gitUrl = 'https://github.com/termux/termux.git'
|
||||||
|
libraryVersion = '0.50'
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 27
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.android.support:support-annotations:27.1.1'
|
||||||
|
api project(":terminal-emulator")
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 27
|
||||||
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: '../scripts/bintray-publish.gradle'
|
||||||
25
terminal-view/proguard-rules.pro
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# By default, the flags in this file are appended to flags specified
|
||||||
|
# in /Users/fornwall/lib/android-sdk/tools/proguard/proguard-android.txt
|
||||||
|
# You can edit the include path and order by changing the proguardFiles
|
||||||
|
# directive in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Add any project specific keep options here:
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
2
terminal-view/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<manifest package="com.termux.view">
|
||||||
|
</manifest>
|
||||||
@@ -6,7 +6,7 @@ import android.view.MotionEvent;
|
|||||||
import android.view.ScaleGestureDetector;
|
import android.view.ScaleGestureDetector;
|
||||||
|
|
||||||
/** A combination of {@link GestureDetector} and {@link ScaleGestureDetector}. */
|
/** A combination of {@link GestureDetector} and {@link ScaleGestureDetector}. */
|
||||||
public final class GestureAndScaleRecognizer {
|
final class GestureAndScaleRecognizer {
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
boolean onSingleTapUp(MotionEvent e);
|
boolean onSingleTapUp(MotionEvent e);
|
||||||
@@ -85,6 +85,7 @@ public final class GestureAndScaleRecognizer {
|
|||||||
return mListener.onScale(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
|
return mListener.onScale(detector.getFocusX(), detector.getFocusY(), detector.getScaleFactor());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
mScaleDetector.setQuickScaleEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onTouchEvent(MotionEvent event) {
|
public void onTouchEvent(MotionEvent event) {
|
||||||
@@ -16,7 +16,7 @@ import com.termux.terminal.WcWidth;
|
|||||||
* <p/>
|
* <p/>
|
||||||
* Saves font metrics, so needs to be recreated each time the typeface or font size changes.
|
* Saves font metrics, so needs to be recreated each time the typeface or font size changes.
|
||||||
*/
|
*/
|
||||||
final class TerminalRenderer {
|
public final class TerminalRenderer {
|
||||||
|
|
||||||
final int mTextSize;
|
final int mTextSize;
|
||||||
final Typeface mTypeface;
|
final Typeface mTypeface;
|
||||||
@@ -29,7 +29,6 @@ import android.view.inputmethod.EditorInfo;
|
|||||||
import android.view.inputmethod.InputConnection;
|
import android.view.inputmethod.InputConnection;
|
||||||
import android.widget.Scroller;
|
import android.widget.Scroller;
|
||||||
|
|
||||||
import com.termux.R;
|
|
||||||
import com.termux.terminal.EmulatorDebug;
|
import com.termux.terminal.EmulatorDebug;
|
||||||
import com.termux.terminal.KeyHandler;
|
import com.termux.terminal.KeyHandler;
|
||||||
import com.termux.terminal.TerminalBuffer;
|
import com.termux.terminal.TerminalBuffer;
|
||||||
@@ -49,7 +48,7 @@ public final class TerminalView extends View {
|
|||||||
|
|
||||||
TerminalRenderer mRenderer;
|
TerminalRenderer mRenderer;
|
||||||
|
|
||||||
TerminalKeyListener mOnKeyListener;
|
TerminalViewClient mClient;
|
||||||
|
|
||||||
/** The top row of text to display. Ranges from -activeTranscriptRows to 0. */
|
/** The top row of text to display. Ranges from -activeTranscriptRows to 0. */
|
||||||
int mTopRow;
|
int mTopRow;
|
||||||
@@ -106,7 +105,7 @@ public final class TerminalView extends View {
|
|||||||
requestFocus();
|
requestFocus();
|
||||||
if (!mEmulator.isMouseTrackingActive()) {
|
if (!mEmulator.isMouseTrackingActive()) {
|
||||||
if (!e.isFromSource(InputDevice.SOURCE_MOUSE)) {
|
if (!e.isFromSource(InputDevice.SOURCE_MOUSE)) {
|
||||||
mOnKeyListener.onSingleTapUp(e);
|
mClient.onSingleTapUp(e);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,7 +135,7 @@ public final class TerminalView extends View {
|
|||||||
public boolean onScale(float focusX, float focusY, float scale) {
|
public boolean onScale(float focusX, float focusY, float scale) {
|
||||||
if (mEmulator == null || mIsSelectingText) return true;
|
if (mEmulator == null || mIsSelectingText) return true;
|
||||||
mScaleFactor *= scale;
|
mScaleFactor *= scale;
|
||||||
mScaleFactor = mOnKeyListener.onScale(mScaleFactor);
|
mScaleFactor = mClient.onScale(mScaleFactor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +188,9 @@ public final class TerminalView extends View {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public void onLongPress(MotionEvent e) {
|
||||||
if (!mGestureRecognizer.isInProgress() && !mIsSelectingText) {
|
if (mGestureRecognizer.isInProgress()) return;
|
||||||
|
if (mClient.onLongPress(e)) return;
|
||||||
|
if (!mIsSelectingText) {
|
||||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||||
toggleSelectingText(e);
|
toggleSelectingText(e);
|
||||||
}
|
}
|
||||||
@@ -202,8 +203,8 @@ public final class TerminalView extends View {
|
|||||||
* @param onKeyListener Listener for all kinds of key events, both hardware and IME (which makes it different from that
|
* @param onKeyListener Listener for all kinds of key events, both hardware and IME (which makes it different from that
|
||||||
* available with {@link View#setOnKeyListener(OnKeyListener)}.
|
* available with {@link View#setOnKeyListener(OnKeyListener)}.
|
||||||
*/
|
*/
|
||||||
public void setOnKeyListener(TerminalKeyListener onKeyListener) {
|
public void setOnKeyListener(TerminalViewClient onKeyListener) {
|
||||||
this.mOnKeyListener = onKeyListener;
|
this.mClient = onKeyListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -555,7 +556,7 @@ public final class TerminalView extends View {
|
|||||||
if (mIsSelectingText) {
|
if (mIsSelectingText) {
|
||||||
toggleSelectingText(null);
|
toggleSelectingText(null);
|
||||||
return true;
|
return true;
|
||||||
} else if (mOnKeyListener.shouldBackButtonBeMappedToEscape()) {
|
} else if (mClient.shouldBackButtonBeMappedToEscape()) {
|
||||||
// Intercept back button to treat it as escape:
|
// Intercept back button to treat it as escape:
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case KeyEvent.ACTION_DOWN:
|
case KeyEvent.ACTION_DOWN:
|
||||||
@@ -574,10 +575,10 @@ public final class TerminalView extends View {
|
|||||||
Log.i(EmulatorDebug.LOG_TAG, "onKeyDown(keyCode=" + keyCode + ", isSystem()=" + event.isSystem() + ", event=" + event + ")");
|
Log.i(EmulatorDebug.LOG_TAG, "onKeyDown(keyCode=" + keyCode + ", isSystem()=" + event.isSystem() + ", event=" + event + ")");
|
||||||
if (mEmulator == null) return true;
|
if (mEmulator == null) return true;
|
||||||
|
|
||||||
if (mOnKeyListener.onKeyDown(keyCode, event, mTermSession)) {
|
if (mClient.onKeyDown(keyCode, event, mTermSession)) {
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
} else if (event.isSystem() && (!mOnKeyListener.shouldBackButtonBeMappedToEscape() || keyCode != KeyEvent.KEYCODE_BACK)) {
|
} else if (event.isSystem() && (!mClient.shouldBackButtonBeMappedToEscape() || keyCode != KeyEvent.KEYCODE_BACK)) {
|
||||||
return super.onKeyDown(keyCode, event);
|
return super.onKeyDown(keyCode, event);
|
||||||
} else if (event.getAction() == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
} else if (event.getAction() == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
|
||||||
mTermSession.write(event.getCharacters());
|
mTermSession.write(event.getCharacters());
|
||||||
@@ -641,10 +642,12 @@ public final class TerminalView extends View {
|
|||||||
+ leftAltDownFromEvent + ")");
|
+ leftAltDownFromEvent + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
final boolean controlDown = controlDownFromEvent || mOnKeyListener.readControlKey();
|
if (mTermSession == null) return;
|
||||||
final boolean altDown = leftAltDownFromEvent || mOnKeyListener.readAltKey();
|
|
||||||
|
|
||||||
if (mOnKeyListener.onCodePoint(codePoint, controlDown, mTermSession)) return;
|
final boolean controlDown = controlDownFromEvent || mClient.readControlKey();
|
||||||
|
final boolean altDown = leftAltDownFromEvent || mClient.readAltKey();
|
||||||
|
|
||||||
|
if (mClient.onCodePoint(codePoint, controlDown, mTermSession)) return;
|
||||||
|
|
||||||
if (controlDown) {
|
if (controlDown) {
|
||||||
if (codePoint >= 'a' && codePoint <= 'z') {
|
if (codePoint >= 'a' && codePoint <= 'z') {
|
||||||
@@ -713,7 +716,7 @@ public final class TerminalView extends View {
|
|||||||
Log.i(EmulatorDebug.LOG_TAG, "onKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
|
Log.i(EmulatorDebug.LOG_TAG, "onKeyUp(keyCode=" + keyCode + ", event=" + event + ")");
|
||||||
if (mEmulator == null) return true;
|
if (mEmulator == null) return true;
|
||||||
|
|
||||||
if (mOnKeyListener.onKeyUp(keyCode, event)) {
|
if (mClient.onKeyUp(keyCode, event)) {
|
||||||
invalidate();
|
invalidate();
|
||||||
return true;
|
return true;
|
||||||
} else if (event.isSystem()) {
|
} else if (event.isSystem()) {
|
||||||
@@ -781,7 +784,7 @@ public final class TerminalView extends View {
|
|||||||
@TargetApi(23)
|
@TargetApi(23)
|
||||||
public void toggleSelectingText(MotionEvent ev) {
|
public void toggleSelectingText(MotionEvent ev) {
|
||||||
mIsSelectingText = !mIsSelectingText;
|
mIsSelectingText = !mIsSelectingText;
|
||||||
mOnKeyListener.copyModeChanged(mIsSelectingText);
|
mClient.copyModeChanged(mIsSelectingText);
|
||||||
|
|
||||||
if (mIsSelectingText) {
|
if (mIsSelectingText) {
|
||||||
if (mLeftSelectionHandle == null) {
|
if (mLeftSelectionHandle == null) {
|
||||||
@@ -833,6 +836,10 @@ public final class TerminalView extends View {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||||
|
if (!mIsSelectingText) {
|
||||||
|
// Fix issue where the dialog is pressed while being dismissed.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case 1:
|
case 1:
|
||||||
String selectedText = mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2).trim();
|
String selectedText = mEmulator.getSelectedText(mSelX1, mSelY1, mSelX2, mSelY2).trim();
|
||||||
@@ -8,16 +8,19 @@ import com.termux.terminal.TerminalSession;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Input and scale listener which may be set on a {@link TerminalView} through
|
* Input and scale listener which may be set on a {@link TerminalView} through
|
||||||
* {@link TerminalView#setOnKeyListener(TerminalKeyListener)}.
|
* {@link TerminalView#setOnKeyListener(TerminalViewClient)}.
|
||||||
* <p/>
|
* <p/>
|
||||||
* TODO: Rename to TerminalViewClient.
|
|
||||||
*/
|
*/
|
||||||
public interface TerminalKeyListener {
|
public interface TerminalViewClient {
|
||||||
|
|
||||||
/** Callback function on scale events according to {@link ScaleGestureDetector#getScaleFactor()}. */
|
/**
|
||||||
|
* Callback function on scale events according to {@link ScaleGestureDetector#getScaleFactor()}.
|
||||||
|
*/
|
||||||
float onScale(float scale);
|
float onScale(float scale);
|
||||||
|
|
||||||
/** On a single tap on the terminal if terminal mouse reporting not enabled. */
|
/**
|
||||||
|
* On a single tap on the terminal if terminal mouse reporting not enabled.
|
||||||
|
*/
|
||||||
void onSingleTapUp(MotionEvent e);
|
void onSingleTapUp(MotionEvent e);
|
||||||
|
|
||||||
boolean shouldBackButtonBeMappedToEscape();
|
boolean shouldBackButtonBeMappedToEscape();
|
||||||
@@ -34,4 +37,6 @@ public interface TerminalKeyListener {
|
|||||||
|
|
||||||
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
|
boolean onCodePoint(int codePoint, boolean ctrlDown, TerminalSession session);
|
||||||
|
|
||||||
|
boolean onLongPress(MotionEvent event);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
5
terminal-view/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="paste_text">Paste</string>
|
||||||
|
<string name="copy_text">Copy</string>
|
||||||
|
<string name="text_selection_more">More…</string>
|
||||||
|
</resources>
|
||||||