feature: start working on auto-completion
This commit is contained in:
parent
01333a9343
commit
5a3e87fb2d
@ -26,7 +26,7 @@ open class FileCompletionProvider : ICandidateProvider {
|
||||
}
|
||||
|
||||
override fun canComplete(text: String): Boolean {
|
||||
return text.startsWith(File.separatorChar)
|
||||
return text.startsWith(File.separatorChar) || text.startsWith("\\./")
|
||||
}
|
||||
|
||||
private fun listDirectory(path: File, filter: ((File) -> Boolean)?): Array<File> {
|
||||
|
@ -10,7 +10,7 @@ object CompletionManager {
|
||||
private val candidateProviders = mutableMapOf<String, ICandidateProvider>()
|
||||
|
||||
fun registerProvider(provider: ICandidateProvider) {
|
||||
this.candidateProviders.put(provider.providerName, provider)
|
||||
this.candidateProviders[provider.providerName] = provider
|
||||
}
|
||||
|
||||
fun unregisterProvider(providerName: String) {
|
||||
|
@ -199,7 +199,7 @@ open class ShellTermSession private constructor(shellPath: String, cwd: String,
|
||||
val langEnv = "LANG=en_US.UTF-8"
|
||||
val pathEnv = "PATH=" + buildPathEnv()
|
||||
val ldEnv = "LD_LIBRARY_PATH=" + buildLdLibraryEnv()
|
||||
val pwdEnv = "PWD=" + selectedCwd
|
||||
val pwdEnv = "PWD=$selectedCwd"
|
||||
val tmpdirEnv = "TMPDIR=${NeoTermPath.USR_PATH}/tmp"
|
||||
|
||||
|
||||
|
@ -9,6 +9,7 @@ import io.neoterm.frontend.completion.listener.OnCandidateSelectedListener
|
||||
import io.neoterm.frontend.completion.model.CompletionCandidate
|
||||
import io.neoterm.frontend.completion.model.CompletionResult
|
||||
import io.neoterm.frontend.completion.view.CandidatePopupWindow
|
||||
import io.neoterm.frontend.logging.NLog
|
||||
import io.neoterm.frontend.terminal.TerminalView
|
||||
import java.util.*
|
||||
|
||||
@ -72,7 +73,7 @@ class TermCompleteListener(var terminalView: TerminalView?) : OnAutoCompleteList
|
||||
|
||||
val deleteLength = newText.indexOf(textNeedCompletion) + textNeedCompletion.length
|
||||
if (deleteLength > 0) {
|
||||
for (i in 0..deleteLength - 1) {
|
||||
for (i in 0 until deleteLength) {
|
||||
session.write("\b")
|
||||
popChar()
|
||||
}
|
||||
@ -85,7 +86,6 @@ class TermCompleteListener(var terminalView: TerminalView?) : OnAutoCompleteList
|
||||
|
||||
pushString(newText)
|
||||
session.write(newText)
|
||||
|
||||
// Trigger next completion
|
||||
lastCompletedIndex = inputStack.size
|
||||
triggerCompletion()
|
||||
|
@ -1009,7 +1009,8 @@ public final class TerminalView extends View {
|
||||
ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
menu.add(Menu.NONE, 1, Menu.NONE, R.string.copy_text).setShowAsAction(show);
|
||||
menu.add(Menu.NONE, 2, Menu.NONE, R.string.paste_text).setEnabled(clipboard.hasPrimaryClip()).setShowAsAction(show);
|
||||
// menu.add(Menu.NONE, 3, Menu.NONE, R.string.text_selection_more);
|
||||
menu.add(Menu.NONE, 3, Menu.NONE, R.string.text_selection_more);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,20 +0,0 @@
|
||||
package io.neoterm.setup.connections
|
||||
|
||||
import io.neoterm.App
|
||||
import io.neoterm.setup.SetupHelper
|
||||
import io.neoterm.utils.AssetsUtils
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
|
||||
/**
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
class AssetsFileConnection : OfflineConnection() {
|
||||
@Throws(IOException::class)
|
||||
override fun openInputStream(): InputStream {
|
||||
val arch = SetupHelper.determineArchName()
|
||||
val fileName = "offline_setup/$arch.zip"
|
||||
return AssetsUtils.openAssetsFile(App.get(), fileName)
|
||||
}
|
||||
}
|
@ -7,4 +7,4 @@ import android.net.Uri
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
class BackupFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri)
|
||||
class BackupFileConnection(context: Context, uri: Uri) : LocalFileConnection(context, uri)
|
||||
|
@ -7,4 +7,4 @@ import android.net.Uri
|
||||
* @author kiva
|
||||
*/
|
||||
|
||||
class LocalFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri)
|
||||
open class LocalFileConnection(context: Context, uri: Uri) : OfflineUriConnection(context, uri)
|
||||
|
@ -24,11 +24,11 @@ abstract class OfflineConnection : SourceConnection {
|
||||
|
||||
override fun getSize(): Int {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
return inputStream!!.available()
|
||||
return try {
|
||||
inputStream!!.available()
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
return 0
|
||||
0
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import io.neoterm.frontend.config.NeoTermPath
|
||||
import io.neoterm.setup.ResultListener
|
||||
import io.neoterm.setup.SetupHelper
|
||||
import io.neoterm.setup.SourceConnection
|
||||
import io.neoterm.setup.connections.AssetsFileConnection
|
||||
import io.neoterm.setup.connections.BackupFileConnection
|
||||
import io.neoterm.setup.connections.LocalFileConnection
|
||||
import io.neoterm.setup.connections.NetworkConnection
|
||||
@ -41,7 +40,6 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener
|
||||
private val hintMapping = arrayOf(
|
||||
R.id.setup_method_online, R.string.setup_hint_online,
|
||||
R.id.setup_method_local, R.string.setup_hint_local,
|
||||
R.id.setup_method_assets, R.string.setup_hint_assets,
|
||||
R.id.setup_method_backup, R.string.setup_hint_backup
|
||||
)
|
||||
|
||||
@ -69,7 +67,6 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener
|
||||
|
||||
findViewById<RadioButton>(R.id.setup_method_online).setOnCheckedChangeListener(onCheckedChangeListener)
|
||||
findViewById<RadioButton>(R.id.setup_method_local).setOnCheckedChangeListener(onCheckedChangeListener)
|
||||
findViewById<RadioButton>(R.id.setup_method_assets).setOnCheckedChangeListener(onCheckedChangeListener)
|
||||
findViewById<RadioButton>(R.id.setup_method_backup).setOnCheckedChangeListener(onCheckedChangeListener)
|
||||
|
||||
findViewById<Button>(R.id.setup_next).setOnClickListener(this)
|
||||
@ -137,6 +134,7 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener
|
||||
R.id.setup_method_backup,
|
||||
R.id.setup_method_local -> {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT)
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||
intent.type = "*/*";
|
||||
try {
|
||||
startActivityForResult(intent, REQUEST_SELECT_PARAMETER)
|
||||
@ -151,7 +149,6 @@ class SetupActivity : AppCompatActivity(), View.OnClickListener, ResultListener
|
||||
return when (id) {
|
||||
R.id.setup_method_local -> LocalFileConnection(this, parameterUri!!)
|
||||
R.id.setup_method_online -> NetworkConnection(parameter)
|
||||
R.id.setup_method_assets -> AssetsFileConnection()
|
||||
R.id.setup_method_backup -> BackupFileConnection(this, parameterUri!!)
|
||||
else -> throw IllegalArgumentException("Unexpected setup method!")
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import de.psdev.licensesdialog.model.Notice
|
||||
import de.psdev.licensesdialog.model.Notices
|
||||
import io.neoterm.App
|
||||
import io.neoterm.R
|
||||
import io.neoterm.ui.setup.SetupActivity
|
||||
|
||||
|
||||
/**
|
||||
@ -86,10 +87,20 @@ class AboutActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.about_reset_app_view).setOnClickListener {
|
||||
App.get().errorDialog(this, "WIP", null);
|
||||
AlertDialog.Builder(this)
|
||||
.setMessage(R.string.reset_app_warning)
|
||||
.setPositiveButton(R.string.yes, { _, _ ->
|
||||
resetApp()
|
||||
})
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetApp() {
|
||||
startActivity(Intent(this, SetupActivity::class.java))
|
||||
}
|
||||
|
||||
private fun openUrl(url: String) {
|
||||
val intent = Intent(Intent.ACTION_VIEW)
|
||||
intent.data = Uri.parse(url)
|
||||
|
@ -15,8 +15,11 @@ import io.neoterm.Globals
|
||||
import io.neoterm.NeoGLView
|
||||
import io.neoterm.R
|
||||
import io.neoterm.component.colorscheme.ColorSchemeComponent
|
||||
import io.neoterm.frontend.completion.listener.OnAutoCompleteListener
|
||||
import io.neoterm.frontend.component.ComponentManager
|
||||
import io.neoterm.frontend.config.DefaultValues
|
||||
import io.neoterm.frontend.config.NeoPreference
|
||||
import io.neoterm.frontend.session.shell.client.TermCompleteListener
|
||||
import io.neoterm.frontend.terminal.TerminalView
|
||||
import io.neoterm.frontend.terminal.extrakey.ExtraKeysView
|
||||
import io.neoterm.ui.term.NeoTermActivity
|
||||
@ -152,11 +155,22 @@ class NeoTabDecorator(val context: NeoTermActivity) : TabSwitcherDecorator() {
|
||||
termView.setTerminalViewClient(termData.viewClient)
|
||||
termView.attachSession(termData.termSession)
|
||||
|
||||
if (NeoPreference.loadBoolean(R.string.key_general_auto_completion, false)) {
|
||||
if (termData.onAutoCompleteListener == null) {
|
||||
termData.onAutoCompleteListener = createAutoCompleteListener(termView)
|
||||
}
|
||||
termView.onAutoCompleteListener = termData.onAutoCompleteListener
|
||||
}
|
||||
|
||||
if (termData.termSession != null) {
|
||||
termData.viewClient?.updateExtraKeys(termData.termSession?.title, true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createAutoCompleteListener(view: TerminalView): OnAutoCompleteListener? {
|
||||
return TermCompleteListener(view)
|
||||
}
|
||||
|
||||
override fun getViewTypeCount(): Int {
|
||||
return VIEW_TYPE_COUNT
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ object NetworkUtils {
|
||||
return getNetworkType(context) != null
|
||||
}
|
||||
|
||||
fun getNetworkType(context: Context): String? {
|
||||
private fun getNetworkType(context: Context): String? {
|
||||
var networkType: String? = null
|
||||
|
||||
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager ?: return null
|
||||
|
@ -326,7 +326,7 @@
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
android:text="@string/app_name"
|
||||
android:text="@string/dangerous_zone"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -56,12 +56,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setup_local" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/setup_method_assets"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/setup_assets" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/setup_method_backup"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -9,6 +9,7 @@
|
||||
<string name="new_system_session">新建系统会话</string>
|
||||
<string name="package_settings">软件包</string>
|
||||
<string name="paste_text">粘贴</string>
|
||||
<string name="super_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>
|
||||
@ -75,13 +76,11 @@
|
||||
<string name="setup_setup_method">选择你的安装方式</string>
|
||||
<string name="setup_online">从软件源安装</string>
|
||||
<string name="setup_local">从本地 Zip 文件安装</string>
|
||||
<string name="setup_assets">从软件自带 Zip 文件安装</string>
|
||||
<string name="setup_backup">从 NeoTerm 备份中恢复</string>
|
||||
<string name="setup_source_parameter">配置参数</string>
|
||||
<string name="setup_input_source_parameter">输入配置参数</string>
|
||||
<string name="setup_hint_online">含有启动文件的软件源地址</string>
|
||||
<string name="setup_hint_local">启动文件(*.zip)路径</string>
|
||||
<string name="setup_hint_assets">不可用</string>
|
||||
<string name="setup_hint_backup">备份文件(*.neobackup) 路径</string>
|
||||
<string name="setup_error_file_not_found">文件不存在</string>
|
||||
<string name="setup_error_invalid_url">非法的 URL</string>
|
||||
@ -163,6 +162,7 @@
|
||||
<string name="error_new_source_repo">仓库 不能为空</string>
|
||||
<string name="sorry_for_development">本功能仍在开发中,所以只能在 DEBUG 构建版本下使用。\n若想尝鲜,请尝试联系开发者来成为测试者。</string>
|
||||
<string name="dangerous_zone">危险区域</string>
|
||||
<string name="reset_app_warning">执行此操作后,下次启动时将要重新配置 NeoTerm,继续?</string>
|
||||
|
||||
<string-array name="color_item_names">
|
||||
<item>背景色</item>
|
||||
|
@ -2,6 +2,7 @@
|
||||
<string name="app_name">NeoTerm</string>
|
||||
<string name="copy_text">Copy</string>
|
||||
<string name="paste_text">Paste</string>
|
||||
<string name="super_paste_text">Super Paste</string>
|
||||
<string name="text_selection_more">More</string>
|
||||
|
||||
<string name="toggle_tab_switcher_menu_item">Toggle Tabs</string>
|
||||
@ -18,14 +19,12 @@
|
||||
<string name="setup_setup_method">Select your installation method</string>
|
||||
<string name="setup_online">Online Setup</string>
|
||||
<string name="setup_local">Local Zip File Setup</string>
|
||||
<string name="setup_assets">Assets Zip File Setup</string>
|
||||
<string name="setup_backup">Restore from NeoTerm Backup</string>
|
||||
<string name="setup_source_parameter">Source Parameter</string>
|
||||
<string name="setup_input_source_parameter">Input source parameter…</string>
|
||||
<string name="setup_dots" translatable="false">…</string>
|
||||
<string name="setup_hint_online">URL of mirror that contains setup zip files</string>
|
||||
<string name="setup_hint_local">File path to showConfirmDialog zip files</string>
|
||||
<string name="setup_hint_assets">Not available</string>
|
||||
<string name="setup_hint_backup">File path to backup file(*.neobackup)</string>
|
||||
<string name="setup_error_file_not_found">File not found</string>
|
||||
<string name="setup_error_invalid_url">Invalid URL</string>
|
||||
@ -167,6 +166,7 @@
|
||||
<string name="error_new_source_repo">Repo cannot be empty</string>
|
||||
<string name="sorry_for_development">This feature is still under development so it is only available on DEBUG builds.\n</string>
|
||||
<string name="dangerous_zone">Dangerous Zone</string>
|
||||
<string name="reset_app_warning">You will have to re-setup later, confirm?</string>
|
||||
|
||||
<string name="default_source_url">http://193.112.47.241</string>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user