Improve: Program interface

This commit is contained in:
zt515 2017-08-01 01:00:59 +08:00
parent ddd25bc08a
commit 3f38df8911
20 changed files with 74 additions and 24 deletions

View File

@ -8,8 +8,8 @@ android {
applicationId "io.neoterm"
minSdkVersion 21
targetSdkVersion 25
versionCode 19
versionName "1.2.0-rc8"
versionCode 20
versionName "1.2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resConfigs "zh-rCN", "zh-rTW"
externalNativeBuild {

View File

@ -1,7 +1,6 @@
package io.neoterm.frontend
import android.content.Context
import android.widget.Toast
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.frontend.client.TermSessionCallback
@ -110,16 +109,11 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
fun create(context: Context): ShellTermSession {
val cwd = this.cwd ?: NeoTermPath.HOME_PATH
var shell = this.executablePath ?:
val shell = this.executablePath ?:
if (systemShell)
"/system/bin/sh"
else
NeoTermPath.USR_PATH + "/bin/" + NeoPreference.loadString(R.string.key_general_shell, "sh")
if (!File(shell).exists()) {
Toast.makeText(context, context.getString(R.string.shell_not_found, shell), Toast.LENGTH_LONG).show()
shell = NeoTermPath.USR_PATH + "/bin/sh"
}
NeoPreference.getLoginShell()
val args = this.args ?: mutableListOf(shell)
val env = transformEnvironment(this.env) ?: buildEnvironment(cwd, systemShell)
@ -148,9 +142,12 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
val androidDataEnv = "ANDROID_DATA=" + System.getenv("ANDROID_DATA")
val externalStorageEnv = "EXTERNAL_STORAGE=" + System.getenv("EXTERNAL_STORAGE")
// PY Trace: Some programs support NeoTerm in a special way.
val neotermIdEnv = "__NEOTERM=1"
if (systemShell) {
val pathEnv = "PATH=" + System.getenv("PATH")
return arrayOf(termEnv, homeEnv, androidRootEnv, androidDataEnv, externalStorageEnv, pathEnv)
return arrayOf(termEnv, homeEnv, androidRootEnv, androidDataEnv, externalStorageEnv, pathEnv, neotermIdEnv)
} else {
val ps1Env = "PS1=$ "
@ -160,7 +157,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
val pwdEnv = "PWD=" + cwd
val tmpdirEnv = "TMPDIR=${NeoTermPath.USR_PATH}/tmp"
return arrayOf(termEnv, homeEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv)
return arrayOf(termEnv, homeEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv, neotermIdEnv)
}
}

View File

@ -3,10 +3,11 @@ package io.neoterm.preference
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import android.system.ErrnoException
import android.system.Os
import io.neoterm.App
import io.neoterm.R
import io.neoterm.backend.TerminalSession
import io.neoterm.customize.setup.BaseFileInstaller
import io.neoterm.services.NeoTermService
import io.neoterm.utils.FileUtils
import java.io.File
@ -102,10 +103,49 @@ object NeoPreference {
return null
}
fun isBaseFileInstalled() : Boolean {
return !BaseFileInstaller.needSetup()
fun setLoginShell(loginProgramName: String?): Boolean {
if (loginProgramName == null) {
return false
}
val loginProgramPath = findLoginProgram(loginProgramName) ?: return false
store(R.string.key_general_shell, loginProgramName)
symlinkLoginShell(loginProgramPath)
return true
}
fun getLoginShell(): String {
val loginProgramName = loadString(R.string.key_general_shell, "sh")
// Some programs like ssh needs it
val shell = File(NeoTermPath.NEOTERM_SHELL_PATH)
if (!shell.exists()) {
symlinkLoginShell(loginProgramName)
}
return "${NeoTermPath.USR_PATH}/bin/$loginProgramName"
}
private fun symlinkLoginShell(loginProgramPath: String) {
File(NeoTermPath.CUSTOM_PATH).mkdirs()
try {
if (File(NeoTermPath.NEOTERM_SHELL_PATH).exists()) {
Os.remove(NeoTermPath.NEOTERM_SHELL_PATH)
}
Os.symlink(loginProgramPath, NeoTermPath.NEOTERM_SHELL_PATH)
Os.chmod(NeoTermPath.NEOTERM_SHELL_PATH, 448 /*Decimal of 0700 */)
} catch (e: ErrnoException) {
e.printStackTrace()
}
}
private fun findLoginProgram(loginProgramName: String): String? {
val file = File("${NeoTermPath.USR_PATH}/bin", loginProgramName)
return if (file.canExecute()) file.absolutePath else null
}
// fun storeWindowSize(context: Context, width: Int, height: Int) {
// store(KEY_FLOATING_WIDTH, width)
// store(KEY_FLOATING_HEIGHT, height)

View File

@ -14,6 +14,7 @@ object NeoTermPath {
const val APT_BIN_PATH = "$USR_PATH/bin/apt"
const val CUSTOM_PATH = "$HOME_PATH/.neoterm"
const val NEOTERM_SHELL_PATH = "$CUSTOM_PATH/shell"
const val EKS_PATH = "$CUSTOM_PATH/eks"
const val EKS_DEFAULT_FILE = "$EKS_PATH/default.eks"
const val FONT_PATH = "$CUSTOM_PATH/font"

View File

@ -41,7 +41,7 @@ class UISettingsActivity : AppCompatPreferenceActivity() {
override fun onSessionFinished(dialog: TerminalDialog, finishedSession: TerminalSession?) {
if (finishedSession?.exitStatus == 0) {
dialog.dismiss()
NeoPreference.store(R.string.key_general_shell, "zsh")
NeoPreference.setLoginShell("zsh")
} else {
dialog.setTitle(getString(R.string.error))
}

View File

@ -69,7 +69,7 @@ class SetupActivity : AppCompatActivity() {
if (finishedSession?.exitStatus == 0) {
dialog.dismiss()
if (withShell != null) {
NeoPreference.store(R.string.key_general_shell, withShell!!)
NeoPreference.setLoginShell(withShell!!)
}
} else {
dialog.setTitle(getString(R.string.error))

View File

@ -69,13 +69,12 @@ class TermTabDecorator(val context: NeoTermActivity) : TabSwitcherDecorator() {
view.attachSession(termData.termSession)
// Still in progress with lots of bugs to deal with.
// Only available for developers.
// if (BuildConfig.DEBUG) {
// if (termData.onAutoCompleteListener == null) {
// termData.onAutoCompleteListener = createAutoCompleteListener(view)
// }
// view.onAutoCompleteListener = termData.onAutoCompleteListener
// }
if (NeoPreference.loadBoolean(R.string.key_general_auto_completion, false)) {
if (termData.onAutoCompleteListener == null) {
termData.onAutoCompleteListener = createAutoCompleteListener(view)
}
view.onAutoCompleteListener = termData.onAutoCompleteListener
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -99,4 +99,6 @@
<string name="command_shortcut_command">命令</string>
<string name="no_command_extra">没有找到需要执行的命令,是否忘记了传递参数?</string>
<string name="command_display_title_cannot_be_null">展示标题不可为空</string>
<string name="pref_general_auto_completion">自动补全(实验性)</string>
<string name="pref_general_auto_completion_desc">输入命令或者路径时提供补全。该功能还在开发中有许多bug需要解决</string>
</resources>

View File

@ -99,4 +99,6 @@
<string name="command_display_title_cannot_be_null">展示標題不可為空</string>
<string name="command_shortcut_display_title">"展示標題 "</string>
<string name="command_shortcut_command">命令</string>
<string name="pref_general_auto_completion">自動補全(實驗性)</string>
<string name="pref_general_auto_completion_desc">"輸入命令或者路徑時提供補全。該功能還在開發中有許多bug需要解决 "</string>
</resources>

View File

@ -6,6 +6,7 @@
<string name="key_general_shell" translatable="false">neoterm_general_shell</string>
<string name="key_general_program_selection" translatable="false">neoterm_general_program_selection</string>
<string name="key_general_initial_command" translatable="false">neoterm_general_initial_command</string>
<string name="key_general_auto_completion" translatable="false">neoterm_general_auto_completion</string>
<string name="key_ui_fullscreen" translatable="false">neoterm_ui_fullscreen</string>
<string name="key_ui_hide_toolbar" translatable="false">neoterm_ui_hide_toolbar</string>

View File

@ -67,6 +67,8 @@
<string name="pref_general_program_selection_desc">When both Neo Term and your Android OS have a program, which one should we choose?</string>
<string name="pref_general_initial_command">Initial Command</string>
<string name="pref_general_initial_command_desc">Execute commands when a session is being created</string>
<string name="pref_general_auto_completion">Auto Completion(Experimental)</string>
<string name="pref_general_auto_completion_desc">Enable complete things when typing commands or path. This is still work in progress with lots of bugs to deal with</string>
<string name="pref_ui_fullscreen">Full Screen</string>
<string name="pref_ui_hide_toolbar">Hide Toolbar</string>
<string name="pref_ui_hide_toolbar_desc">Hide toolbar when keyboard is showing</string>

View File

@ -31,6 +31,12 @@
android:summary="@string/pref_general_backspace_map_to_esc_desc"
android:title="@string/pref_general_backspace_map_to_esc" />
<CheckBoxPreference
android:defaultValue="false"
android:key="@string/key_general_auto_completion"
android:summary="@string/pref_general_auto_completion_desc"
android:title="@string/pref_general_auto_completion" />
<ListPreference
android:defaultValue="NeoTermOnly"
android:entries="@array/pref_general_program_selection_entries"

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

BIN
artwork/icon-512.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

BIN
artwork/neoterm.psd Normal file

Binary file not shown.