Feature: Customize EKS
This commit is contained in:
parent
93d4a29d47
commit
2ee0d17fdf
@ -26,7 +26,7 @@ android {
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
minifyEnabled true
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
|
5
app/proguard-rules.pro
vendored
5
app/proguard-rules.pro
vendored
@ -23,3 +23,8 @@
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
|
||||
-keep class io.neoterm.backend.JNI {
|
||||
*;
|
||||
}
|
||||
|
||||
|
12
app/src/main/java/io/neoterm/customize/NeoTermPath.kt
Normal file
12
app/src/main/java/io/neoterm/customize/NeoTermPath.kt
Normal file
@ -0,0 +1,12 @@
|
||||
package io.neoterm.customize
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
object NeoTermPath {
|
||||
const val ROOT_PATH = "/data/data/io.neoterm/files"
|
||||
const val USR_PATH = "$ROOT_PATH/usr"
|
||||
const val HOME_PATH = "$ROOT_PATH/home"
|
||||
|
||||
const val EKS_PATH = "$USR_PATH/share/eks"
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package io.neoterm.customize.shortcut
|
||||
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class ShortcutConfig {
|
||||
var version: Int = -1
|
||||
val programNames: MutableList<String> = mutableListOf()
|
||||
val shortcutKeys: MutableList<ExtraKeysView.ExtraButton> = mutableListOf()
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package io.neoterm.customize.shortcut
|
||||
|
||||
import io.neoterm.view.ExtraKeysView
|
||||
import java.io.*
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
class ShortcutConfigParser {
|
||||
companion object {
|
||||
const val PARSER_VERSION = 1
|
||||
}
|
||||
|
||||
private lateinit var source: BufferedReader
|
||||
|
||||
fun setInput(file: File) {
|
||||
source = BufferedReader(FileReader(file))
|
||||
}
|
||||
|
||||
fun setInput(bufferedReader: BufferedReader) {
|
||||
source = bufferedReader
|
||||
}
|
||||
|
||||
fun setInput(inputStream: BufferedInputStream) {
|
||||
source = BufferedReader(InputStreamReader(inputStream))
|
||||
}
|
||||
|
||||
fun parse(): ShortcutConfig {
|
||||
val config = ShortcutConfig()
|
||||
var line: String? = source.readLine()
|
||||
|
||||
while (line != null) {
|
||||
line = line.trim().trimEnd()
|
||||
if (line.isEmpty() || line.startsWith("#")) {
|
||||
line = source.readLine()
|
||||
continue
|
||||
}
|
||||
|
||||
if (line.startsWith("version")) {
|
||||
parseHeader(line, config)
|
||||
} else if (line.startsWith("program")) {
|
||||
parseProgram(line, config)
|
||||
} else if (line.startsWith("define")) {
|
||||
parseKeyDefine(line, config)
|
||||
}
|
||||
line = source.readLine()
|
||||
}
|
||||
|
||||
if (config.version < 0) {
|
||||
throw RuntimeException("Not a valid shortcut config file")
|
||||
}
|
||||
if (config.programNames.size == 0) {
|
||||
throw RuntimeException("At least one program name should be given")
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
private fun parseKeyDefine(line: String, config: ShortcutConfig) {
|
||||
val keyDefine = line.substring("define".length).trim().trimEnd()
|
||||
val keyValues = keyDefine.split(" ")
|
||||
if (keyValues.size < 2) {
|
||||
throw RuntimeException("Bad define")
|
||||
}
|
||||
|
||||
val buttonText = keyValues[0]
|
||||
val withEnter = keyValues[1] == "true"
|
||||
|
||||
config.shortcutKeys.add(ExtraKeysView.TextButton(buttonText, withEnter))
|
||||
}
|
||||
|
||||
private fun parseProgram(line: String, config: ShortcutConfig) {
|
||||
val programNames = line.substring("program".length).trim().trimEnd()
|
||||
if (programNames.isEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
for (name in programNames.split(" ")) {
|
||||
config.programNames.add(name)
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseHeader(line: String, config: ShortcutConfig) {
|
||||
val version: Int
|
||||
val versionString = line.substring("version".length).trim().trimEnd()
|
||||
try {
|
||||
version = Integer.parseInt(versionString)
|
||||
} catch (e: NumberFormatException) {
|
||||
throw RuntimeException("Bad version '$versionString'")
|
||||
}
|
||||
|
||||
if (version > ShortcutConfigParser.PARSER_VERSION) {
|
||||
throw RuntimeException("Required version: $version, please upgrade your app")
|
||||
}
|
||||
|
||||
config.version = version
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.preference.PreferenceManager
|
||||
import io.neoterm.backend.TerminalSession
|
||||
import io.neoterm.customize.NeoTermPath
|
||||
import io.neoterm.services.NeoTermService
|
||||
import java.io.File
|
||||
|
||||
@ -13,10 +14,6 @@ import java.io.File
|
||||
*/
|
||||
|
||||
object NeoTermPreference {
|
||||
const val ROOT_PATH = "/data/data/io.neoterm/files"
|
||||
const val USR_PATH = ROOT_PATH + "/usr"
|
||||
const val HOME_PATH = ROOT_PATH + "/home"
|
||||
|
||||
const val KEY_FONT_SIZE = "neoterm_general_font_size"
|
||||
const val KEY_CURRENT_SESSION = "neoterm_service_current_session"
|
||||
|
||||
@ -89,12 +86,12 @@ object NeoTermPreference {
|
||||
|
||||
fun buildEnvironment(cwd: String?, systemShell: Boolean): Array<String> {
|
||||
var cwd = cwd
|
||||
File(HOME_PATH).mkdirs()
|
||||
File(NeoTermPath.HOME_PATH).mkdirs()
|
||||
|
||||
if (cwd == null) cwd = HOME_PATH
|
||||
if (cwd == null) cwd = NeoTermPath.HOME_PATH
|
||||
|
||||
val termEnv = "TERM=xterm-256color"
|
||||
val homeEnv = "HOME=" + HOME_PATH
|
||||
val homeEnv = "HOME=" + NeoTermPath.HOME_PATH
|
||||
val androidRootEnv = "ANDROID_ROOT=" + System.getenv("ANDROID_ROOT")
|
||||
val androidDataEnv = "ANDROID_DATA=" + System.getenv("ANDROID_DATA")
|
||||
val externalStorageEnv = "EXTERNAL_STORAGE=" + System.getenv("EXTERNAL_STORAGE")
|
||||
@ -105,11 +102,11 @@ object NeoTermPreference {
|
||||
|
||||
} else {
|
||||
val ps1Env = "PS1=$ "
|
||||
val ldEnv = "LD_LIBRARY_PATH=$USR_PATH/lib"
|
||||
val ldEnv = "LD_LIBRARY_PATH=${NeoTermPath.USR_PATH}/lib"
|
||||
val langEnv = "LANG=en_US.UTF-8"
|
||||
val pathEnv = "PATH=$USR_PATH/bin:$USR_PATH/bin/applets"
|
||||
val pathEnv = "PATH=${NeoTermPath.USR_PATH}/bin:${NeoTermPath.USR_PATH}/bin/applets"
|
||||
val pwdEnv = "PWD=" + cwd
|
||||
val tmpdirEnv = "TMPDIR=$USR_PATH/tmp"
|
||||
val tmpdirEnv = "TMPDIR=${NeoTermPath.USR_PATH}/tmp"
|
||||
|
||||
return arrayOf(termEnv, homeEnv, ps1Env, ldEnv, langEnv, pathEnv, pwdEnv, androidRootEnv, androidDataEnv, externalStorageEnv, tmpdirEnv)
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
package io.neoterm.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.FloatingActionButton
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.widget.Toolbar
|
||||
|
||||
import io.neoterm.R
|
||||
|
||||
class AboutActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_about)
|
||||
val toolbar = findViewById(R.id.about_toolbar) as Toolbar
|
||||
setSupportActionBar(toolbar)
|
||||
|
||||
val fab = findViewById(R.id.about_fab) as FloatingActionButton
|
||||
fab.setOnClickListener({ view ->
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show()
|
||||
})
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package io.neoterm.ui.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatPreferenceActivity
|
||||
import android.view.MenuItem
|
||||
import io.neoterm.R
|
||||
@ -15,6 +16,14 @@ class SettingActivity : AppCompatPreferenceActivity() {
|
||||
supportActionBar.title = getString(R.string.settings)
|
||||
supportActionBar.setDisplayHomeAsUpEnabled(true)
|
||||
addPreferencesFromResource(R.xml.settings_main)
|
||||
findPreference(getString(R.string.about)).setOnPreferenceClickListener {
|
||||
AlertDialog.Builder(this@SettingActivity)
|
||||
.setTitle(R.string.about)
|
||||
.setMessage("Hello World!")
|
||||
.setPositiveButton(android.R.string.yes, null)
|
||||
.show()
|
||||
return@setOnPreferenceClickListener true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBuildHeaders(target: MutableList<Header>?) {
|
||||
|
@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="io.neoterm.ui.AboutActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/app_bar_height"
|
||||
android:fitsSystemWindows="true"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.design.widget.CollapsingToolbarLayout
|
||||
android:id="@+id/toolbar_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
app:contentScrim="?attr/colorPrimary"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed"
|
||||
app:toolbarId="@+id/about_toolbar">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/about_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</android.support.design.widget.CollapsingToolbarLayout>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_about" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/about_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:layout_anchor="@id/app_bar"
|
||||
app:layout_anchorGravity="bottom|end"
|
||||
app:srcCompat="@drawable/ic_terminal_running_white" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context="io.neoterm.ui.AboutActivity"
|
||||
tools:showIn="@layout/activity_about">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:text="@string/large_text" />
|
||||
|
||||
</android.support.v4.widget.NestedScrollView>
|
30
app/src/main/res/values-zh/strings.xml
Normal file
30
app/src/main/res/values-zh/strings.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">Neo Term</string>
|
||||
<string name="about">关于</string>
|
||||
<string name="copy_text">复制</string>
|
||||
<string name="general_settings">通用设置</string>
|
||||
<string name="new_session">新建终端</string>
|
||||
<string name="package_settings">软件包设置</string>
|
||||
<string name="paste_text">粘贴</string>
|
||||
<string name="pref_general_backspace_map_to_esc">返回键发送ESC</string>
|
||||
<string name="pref_general_backspace_map_to_esc_desc">当返回键按下时,发送ESC而不是退出终端</string>
|
||||
<string name="pref_general_bell">响铃</string>
|
||||
<string name="pref_general_bell_desc">收到 \'\\a\' 时响铃</string>
|
||||
<string name="pref_general_shell_desc">登录时使用指定的 Shell</string>
|
||||
<string name="pref_general_vibrate">振动</string>
|
||||
<string name="pref_general_vibrate_desc">收到 \'\\a\' 时振动</string>
|
||||
<string name="pref_package_source">软件源</string>
|
||||
<string name="pref_ui_close_tab_anim_next_tab">向下切换窗口</string>
|
||||
<string name="pref_ui_close_tab_anim_next_tab_desc">关闭当前窗口时切换到下一个窗口而不是上一个</string>
|
||||
<string name="pref_ui_color_scheme">配色方案</string>
|
||||
<string name="pref_ui_font">字体</string>
|
||||
<string name="pref_ui_fullscreen">全屏</string>
|
||||
<string name="pref_ui_suggestions">显示建议 (需要 zsh)</string>
|
||||
<string name="pref_ui_suggestions_desc">使用一些软件时,屏幕下方显示快捷键</string>
|
||||
<string name="settings">设置</string>
|
||||
<string name="text_selection_more">更多</string>
|
||||
<string name="toggle_ime">切换输入法</string>
|
||||
<string name="toggle_tab_switcher_menu_item">切换窗口</string>
|
||||
<string name="ui_settings">界面设置</string>
|
||||
</resources>
|
@ -2,8 +2,8 @@
|
||||
<resources>
|
||||
<string name="key_general_bell" translatable="false">neoterm_general_bell</string>
|
||||
<string name="key_general_vibrate" translatable="false">neoterm_general_vibrate</string>
|
||||
<string name="key_generaL_backspace_map_to_esc">neoterm_general_backspace_map_to_esc</string>
|
||||
<string name="key_general_shell">neoterm_general_shell</string>
|
||||
<string name="key_generaL_backspace_map_to_esc" translatable="false">neoterm_general_backspace_map_to_esc</string>
|
||||
<string name="key_general_shell" translatable="false">neoterm_general_shell</string>
|
||||
|
||||
<string name="key_ui_fullscreen" translatable="false">neoterm_ui_fullscreen</string>
|
||||
<string name="key_ui_font" translatable="false">neoterm_ui_font</string>
|
||||
|
@ -13,21 +13,19 @@
|
||||
<string name="ui_settings">UI Settings</string>
|
||||
<string name="package_settings">Package Settings</string>
|
||||
|
||||
<string name="large_text">Hello NeoTerm.</string>
|
||||
|
||||
<string name="pref_general_bell">Bell</string>
|
||||
<string name="pref_general_bell_desc">Bell when receiving \'\\a\'</string>
|
||||
<string name="pref_general_vibrate">Vibrate</string>
|
||||
<string name="pref_general_vibrate_desc">Vibrate when receiving \'\\a\'</string>
|
||||
<string name="pref_general_backspace_map_to_esc">BackSpace Mapped to Esc</string>
|
||||
<string name="pref_general_backspace_map_to_esc_desc">Send esc when backspace is pressed</string>
|
||||
<string name="pref_general_shell">Shell</string>
|
||||
<string name="pref_general_shell" translatable="false">Shell</string>
|
||||
<string name="pref_general_shell_desc">Which shell should we use when login</string>
|
||||
<string name="pref_ui_fullscreen">Full Screen</string>
|
||||
<string name="pref_ui_font">Font</string>
|
||||
<string name="pref_ui_color_scheme">Color Scheme</string>
|
||||
<string name="pref_ui_close_tab_anim_next_tab">Next tab animation</string>
|
||||
<string name="pref_ui_close_tab_anim_next_tab_desc">Switch to next tab instead of previous tab when closing tab</string>
|
||||
<string name="pref_ui_close_tab_anim_next_tab_desc">Switch to the next tab instead of the previous tab when closing tab</string>
|
||||
<string name="pref_ui_suggestions">Show Suggestions (zsh required)</string>
|
||||
<string name="pref_ui_suggestions_desc">When using some programs, show shortcut keys</string>
|
||||
<string name="pref_package_source">Source</string>
|
||||
|
@ -27,10 +27,7 @@
|
||||
|
||||
<Preference
|
||||
android:icon="@drawable/ic_info_white_36dp"
|
||||
android:title="@string/about">
|
||||
<intent
|
||||
android:targetClass="io.neoterm.ui.AboutActivity"
|
||||
android:targetPackage="io.neoterm" />
|
||||
</Preference>
|
||||
android:key="@string/about"
|
||||
android:title="@string/about" />
|
||||
|
||||
</PreferenceScreen>
|
@ -1,8 +1,10 @@
|
||||
package io.neoterm
|
||||
|
||||
import io.neoterm.customize.shortcut.ShortcutConfigParser
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
@ -12,7 +14,9 @@ import org.junit.Assert.*
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, (2 + 2).toLong())
|
||||
fun test_config_parser() {
|
||||
val parser = ShortcutConfigParser()
|
||||
parser.setInput(File("docs/shortcut-key-config.example"))
|
||||
val config = parser.parse()
|
||||
}
|
||||
}
|
6
docs/shortcut-key-config.example
Normal file
6
docs/shortcut-key-config.example
Normal file
@ -0,0 +1,6 @@
|
||||
version 1
|
||||
program vi vim neovim
|
||||
define :q true
|
||||
define / false
|
||||
define dd true
|
||||
define :w true
|
Loading…
Reference in New Issue
Block a user